|
1 | 1 |
|
| 2 | +using System; |
2 | 3 | using System.Collections; |
3 | 4 | using System.Linq; |
4 | 5 | using Xunit; |
| 6 | +using static Kibnet.IntSet; |
5 | 7 |
|
6 | 8 | namespace IntSet.Tests |
7 | 9 | { |
8 | | - public class IntSetTests |
| 10 | + public partial class IntSetTests |
9 | 11 | { |
10 | 12 | [Fact] |
11 | 13 | public void GetEnumerableTest() |
@@ -124,16 +126,36 @@ public void OrderedEnumerateTest() |
124 | 126 | } |
125 | 127 | } |
126 | 128 |
|
127 | | - [Fact] |
128 | | - public void OrderedIEnumerateTest() |
| 129 | + |
| 130 | + [Theory] |
| 131 | + [InlineData(int.MinValue, int.MinValue + 100000)] |
| 132 | + [InlineData(int.MaxValue - 100000, int.MaxValue)] |
| 133 | + [InlineData(-50000, 50000)] |
| 134 | + [InlineData((1<<3)-50000, (1 << 3)+50000)] |
| 135 | + [InlineData((1<<6)-50000, (1 << 6)+50000)] |
| 136 | + [InlineData((1<<9)-50000, (1 << 9)+50000)] |
| 137 | + [InlineData((1<<12)-50000, (1 << 12)+50000)] |
| 138 | + [InlineData((1<<15)-50000, (1 << 15)+50000)] |
| 139 | + [InlineData((1<<18)-50000, (1 << 18)+50000)] |
| 140 | + [InlineData((1<<21)-50000, (1 << 21)+50000)] |
| 141 | + [InlineData((1<<24)-50000, (1 << 24)+50000)] |
| 142 | + [InlineData((1<<27)-50000, (1 << 27)+50000)] |
| 143 | + [InlineData((1<<30)-50000, (1 << 30)+50000)] |
| 144 | + [InlineData(-5, 5)] |
| 145 | + public void OrderedIEnumerateTest(int from, int to) |
129 | 146 | { |
130 | | - var intSet = new Kibnet.IntSet(TestHelper.GetEnumerable(100000, 0)); |
| 147 | + var intSet = new Kibnet.IntSet(TestHelper.GetEnumerable(to, from)); |
131 | 148 |
|
132 | | - var last = -1; |
| 149 | + int? last = null; |
133 | 150 | var enumerable = intSet as IEnumerable; |
134 | 151 | foreach (int i in enumerable) |
135 | 152 | { |
136 | | - Assert.Equal(last + 1, i); |
| 153 | + if (last == null) |
| 154 | + { |
| 155 | + last = i; |
| 156 | + continue; |
| 157 | + } |
| 158 | + Assert.Equal(last+1, i); |
137 | 159 | last = i; |
138 | 160 | } |
139 | 161 | } |
@@ -197,6 +219,22 @@ public void FullSetTest(int from, int to) |
197 | 219 | } |
198 | 220 | } |
199 | 221 |
|
| 222 | + [Theory] |
| 223 | + [InlineData(int.MinValue, int.MinValue + 1000000, 997)] |
| 224 | + [InlineData(int.MaxValue - 1000000, int.MaxValue, 997)] |
| 225 | + [InlineData(-5000000, 5000000, 997)] |
| 226 | + [InlineData(int.MinValue, int.MaxValue, 2147477)] |
| 227 | + public void FullSteppedSetTest(int from, int to, int step) |
| 228 | + { |
| 229 | + var intSet = new Kibnet.IntSet(false, true); |
| 230 | + intSet.Add(0); |
| 231 | + |
| 232 | + for (int i = from; i < to; i += step) |
| 233 | + { |
| 234 | + Assert.True(intSet.Contains(i)); |
| 235 | + } |
| 236 | + } |
| 237 | + |
200 | 238 | [Theory] |
201 | 239 | [InlineData(int.MinValue, int.MinValue + 100000)] |
202 | 240 | [InlineData(int.MaxValue - 100000, int.MaxValue)] |
@@ -230,10 +268,18 @@ public void FullEnumeratorTest() |
230 | 268 | { |
231 | 269 | var intSet = new Kibnet.IntSet(false, true); |
232 | 270 |
|
233 | | - var last = -1; |
| 271 | + var last = int.MinValue; |
| 272 | + var first = true; |
234 | 273 | foreach (var i in intSet.Take(100000)) |
235 | 274 | { |
236 | | - Assert.Equal(last + 1, i); |
| 275 | + if (first) |
| 276 | + { |
| 277 | + Assert.Equal(last, i); |
| 278 | + first = false; |
| 279 | + } |
| 280 | + |
| 281 | + else |
| 282 | + Assert.Equal(last + 1, i); |
237 | 283 | Assert.True(intSet.Contains(i)); |
238 | 284 | last = i; |
239 | 285 | } |
@@ -385,5 +431,25 @@ public void ExceptWithTest() |
385 | 431 |
|
386 | 432 | intSet.EqualRange(10001, 100000); |
387 | 433 | } |
| 434 | + |
| 435 | + [Fact] |
| 436 | + public void Contains_DefaultValue_ReturnsFalse() |
| 437 | + { |
| 438 | + var set = new Kibnet.IntSet(); // èçíà÷àëüíî âñå áèòû = 0 |
| 439 | + Assert.False(set.Contains(0)); // äîëæíî âåðíóòü false |
| 440 | + Assert.False(set.Contains(42)); // ëþáîå çíà÷åíèå |
| 441 | + } |
| 442 | + |
| 443 | + [Fact] |
| 444 | + public void CopyTo_MatchExactSpace_CopiesAll() |
| 445 | + { |
| 446 | + var set = new Kibnet.IntSet(); |
| 447 | + set.Add(1); |
| 448 | + set.Add(2); |
| 449 | + set.Add(3); |
| 450 | + var dst = new int[5]; |
| 451 | + set.CopyTo(dst, 2); |
| 452 | + Assert.Equal(new[] { 0, 0, 1, 2, 3 }, dst); |
| 453 | + } |
388 | 454 | } |
389 | 455 | } |
0 commit comments