Skip to content

Commit bf84bf3

Browse files
init projects
* Lib project * Test project * Unity exporter project and others
1 parent 5aca523 commit bf84bf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5057
-0
lines changed

ImportedLinq.Test/BufferTest.cs

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using ImportedLinq;
5+
using ImportedLinqTest.Helpers;
6+
using Xunit;
7+
8+
namespace ImportedLinqTest
9+
{
10+
public class BufferTest
11+
{
12+
[Fact]
13+
public void ThrowArgumentNullException()
14+
{
15+
Assert.Throws<ArgumentNullException>(() => default(IEnumerable<int>).Buffer(5));
16+
Assert.Throws<ArgumentNullException>(() => default(IEnumerable<int>).Buffer(5, 5));
17+
Assert.Throws<ArgumentNullException>(() => default(IEnumerable<int>).Buffer(5, 4));
18+
Assert.Throws<ArgumentNullException>(() => default(IEnumerable<int>).Buffer(5, 6));
19+
}
20+
21+
[Fact]
22+
public void ThrowArgumentOutOfRangeException()
23+
{
24+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(0));
25+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(-1));
26+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(0, 4));
27+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(-1, 4));
28+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(4, 0));
29+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(4, -1));
30+
Assert.Throws<ArgumentOutOfRangeException>(() => new[] {3, 1, 4, 1, 5, 9, 2}.Buffer(0, 0));
31+
}
32+
33+
[Fact]
34+
public void BufferImpl0()
35+
{
36+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 10).Buffer(3);
37+
IEnumerable<IReadOnlyList<int>> expected = new[]
38+
{
39+
new[] {0, 1, 2},
40+
new[] {3, 4, 5},
41+
new[] {6, 7, 8},
42+
new[] {9}
43+
};
44+
45+
Assert.Equal(expected, actual);
46+
}
47+
48+
[Fact]
49+
public void BufferImpl1()
50+
{
51+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 9).Buffer(3);
52+
IEnumerable<IReadOnlyList<int>> expected = new[]
53+
{
54+
new[] {0, 1, 2},
55+
new[] {3, 4, 5},
56+
new[] {6, 7, 8},
57+
};
58+
59+
Assert.Equal(expected, actual);
60+
}
61+
62+
[Fact]
63+
public void BufferImpl2()
64+
{
65+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 10).Buffer(3, 3);
66+
IEnumerable<IReadOnlyList<int>> expected = new[]
67+
{
68+
new[] {0, 1, 2},
69+
new[] {3, 4, 5},
70+
new[] {6, 7, 8},
71+
new[] {9}
72+
};
73+
74+
Assert.Equal(expected, actual);
75+
}
76+
77+
[Fact]
78+
public void BufferImpl3()
79+
{
80+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 9).Buffer(3, 3);
81+
IEnumerable<IReadOnlyList<int>> expected = new[]
82+
{
83+
new[] {0, 1, 2},
84+
new[] {3, 4, 5},
85+
new[] {6, 7, 8},
86+
};
87+
88+
Assert.Equal(expected, actual);
89+
}
90+
91+
[Fact]
92+
public void BufferOverlap()
93+
{
94+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 9).Buffer(3, 2);
95+
IEnumerable<IReadOnlyList<int>> expected = new[]
96+
{
97+
new[] {0, 1, 2},
98+
new[] {2, 3, 4},
99+
new[] {4, 5, 6},
100+
new[] {6, 7, 8},
101+
new[] {8},
102+
};
103+
104+
Assert.Equal(expected, actual);
105+
}
106+
107+
[Fact]
108+
public void BufferSkip()
109+
{
110+
IEnumerable<IReadOnlyList<int>> actual = Enumerable.Range(0, 9).Buffer(3, 4);
111+
IEnumerable<IReadOnlyList<int>> expected = new[]
112+
{
113+
new[] {0, 1, 2},
114+
new[] {4, 5, 6},
115+
new[] {8},
116+
};
117+
118+
Assert.Equal(expected, actual);
119+
}
120+
121+
122+
[Fact]
123+
public void NotThrowExceptionImpl()
124+
{
125+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2).Take(2);
126+
127+
foreach (IReadOnlyList<int> e in actual)
128+
{
129+
}
130+
}
131+
132+
[Fact]
133+
public void NotThrowExceptionSkip()
134+
{
135+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2, 1)
136+
.Take(4);
137+
138+
foreach (IReadOnlyList<int> e in actual)
139+
{
140+
}
141+
}
142+
143+
[Fact]
144+
public void NotThrowExceptionOverlap()
145+
{
146+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2, 3)
147+
.Take(1);
148+
149+
foreach (IReadOnlyList<int> e in actual)
150+
{
151+
}
152+
}
153+
154+
[Fact]
155+
public void ThrowExceptionImpl()
156+
{
157+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2);
158+
159+
Assert.Throws<Exception>(() =>
160+
{
161+
foreach (IReadOnlyList<int> e in actual)
162+
{
163+
}
164+
});
165+
}
166+
167+
[Fact]
168+
public void ThrowExceptionSkip()
169+
{
170+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2, 1);
171+
172+
Assert.Throws<Exception>(() =>
173+
{
174+
foreach (IReadOnlyList<int> e in actual)
175+
{
176+
}
177+
});
178+
}
179+
180+
[Fact]
181+
public void ThrowExceptionOverlap()
182+
{
183+
IEnumerable<IReadOnlyList<int>> actual = new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).Buffer(2, 3);
184+
185+
Assert.Throws<Exception>(() =>
186+
{
187+
foreach (IReadOnlyList<int> e in actual)
188+
{
189+
}
190+
});
191+
}
192+
}
193+
}

ImportedLinq.Test/CountByTest.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using ImportedLinq;
5+
using ImportedLinqTest.Helpers;
6+
using Xunit;
7+
8+
namespace ImportedLinqTest
9+
{
10+
public class CountByTest
11+
{
12+
[Fact]
13+
public void CountBy0()
14+
{
15+
IReadOnlyDictionary<int, int> actual = new[] {3, 1, 4, 1, 5, 9, 2}.CountBy(n => n);
16+
17+
IReadOnlyDictionary<int, int> expected = new Dictionary<int, int>
18+
{
19+
{1, 2},
20+
{2, 1},
21+
{3, 1},
22+
{4, 1},
23+
{5, 1},
24+
{9, 1},
25+
};
26+
27+
Assert.Equal(expected, actual);
28+
}
29+
30+
[Fact]
31+
public void CountBy1()
32+
{
33+
IReadOnlyDictionary<char, int> actual = "HelloWorld".CountBy(c => c);
34+
35+
IReadOnlyDictionary<char, int> expected = new Dictionary<char, int>
36+
{
37+
{'H', 1},
38+
{'e', 1},
39+
{'l', 3},
40+
{'o', 2},
41+
{'W', 1},
42+
{'r', 1},
43+
{'d', 1},
44+
};
45+
46+
Assert.Equal(expected, actual);
47+
}
48+
49+
[Fact]
50+
public void CountBy2()
51+
{
52+
IReadOnlyDictionary<int, int> actual = Enumerable.Range(0, 1000).CountBy(c => c % 2);
53+
54+
IReadOnlyDictionary<int, int> expected = new Dictionary<int, int>
55+
{
56+
{0, 500},
57+
{1, 500},
58+
};
59+
60+
Assert.Equal(expected, actual);
61+
}
62+
63+
[Fact]
64+
public void CountByWithComparer()
65+
{
66+
IReadOnlyDictionary<string, int> actual =
67+
new[] {"A", "a", "A", "b", "B", "c"}.CountBy(c => c, StringComparer.OrdinalIgnoreCase);
68+
69+
IReadOnlyDictionary<string, int> expected = new Dictionary<string, int>
70+
{
71+
{"A", 3},
72+
{"b", 2},
73+
{"c", 1},
74+
};
75+
76+
Assert.Equal(expected, actual);
77+
}
78+
79+
[Fact]
80+
public void CountByWithNullKey()
81+
{
82+
IReadOnlyDictionary<string, int> actual = new[]
83+
{
84+
"a", null, "a", "a", "a", null, "b", "b", null, "c"
85+
}
86+
.CountBy(s => s);
87+
88+
List<KeyValuePair<string, int>> expected = new List<KeyValuePair<string, int>>
89+
{
90+
new KeyValuePair<string, int>("a", 4),
91+
new KeyValuePair<string, int>("b", 2),
92+
new KeyValuePair<string, int>("c", 1),
93+
new KeyValuePair<string, int>(null, 3),
94+
};
95+
96+
List<string> keys = new List<string>
97+
{
98+
"a",
99+
"b",
100+
"c",
101+
null,
102+
};
103+
104+
List<int> values = new List<int>
105+
{
106+
4,
107+
2,
108+
1,
109+
3,
110+
};
111+
112+
Assert.Equal(expected, actual);
113+
Assert.Equal(keys, actual.Keys);
114+
Assert.Equal(values, actual.Values);
115+
Assert.Equal(4, actual.Count);
116+
Assert.True(actual.ContainsKey(null));
117+
Assert.True(actual.ContainsKey("a"));
118+
Assert.True(actual.ContainsKey("b"));
119+
Assert.True(actual.ContainsKey("c"));
120+
Assert.Equal(expected, actual);
121+
}
122+
123+
[Fact]
124+
public void ThrowArgumentNullException()
125+
{
126+
Assert.Throws<ArgumentNullException>(() => default(IEnumerable<int>).CountBy(n => n));
127+
Assert.Throws<ArgumentNullException>(() => new[] {1}.CountBy(default(Func<int, int>)));
128+
}
129+
130+
[Fact]
131+
public void ThrowException()
132+
{
133+
Assert.Throws<Exception>(() => { new ThrowExceptionEnumerable<int>(0, 1, 2, 3, 4).CountBy(it => it); });
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)