Skip to content

Commit d8a129b

Browse files
committed
fix: Full root set enumaraiting was fail
1 parent 0255a1d commit d8a129b

File tree

2 files changed

+76
-10
lines changed

2 files changed

+76
-10
lines changed

src/IntSet.Tests/IntSetTests.cs

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

2+
using System;
23
using System.Collections;
34
using System.Linq;
45
using Xunit;
6+
using static Kibnet.IntSet;
57

68
namespace IntSet.Tests
79
{
8-
public class IntSetTests
10+
public partial class IntSetTests
911
{
1012
[Fact]
1113
public void GetEnumerableTest()
@@ -124,16 +126,36 @@ public void OrderedEnumerateTest()
124126
}
125127
}
126128

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)
129146
{
130-
var intSet = new Kibnet.IntSet(TestHelper.GetEnumerable(100000, 0));
147+
var intSet = new Kibnet.IntSet(TestHelper.GetEnumerable(to, from));
131148

132-
var last = -1;
149+
int? last = null;
133150
var enumerable = intSet as IEnumerable;
134151
foreach (int i in enumerable)
135152
{
136-
Assert.Equal(last + 1, i);
153+
if (last == null)
154+
{
155+
last = i;
156+
continue;
157+
}
158+
Assert.Equal(last+1, i);
137159
last = i;
138160
}
139161
}
@@ -197,6 +219,22 @@ public void FullSetTest(int from, int to)
197219
}
198220
}
199221

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+
200238
[Theory]
201239
[InlineData(int.MinValue, int.MinValue + 100000)]
202240
[InlineData(int.MaxValue - 100000, int.MaxValue)]
@@ -230,10 +268,18 @@ public void FullEnumeratorTest()
230268
{
231269
var intSet = new Kibnet.IntSet(false, true);
232270

233-
var last = -1;
271+
var last = int.MinValue;
272+
var first = true;
234273
foreach (var i in intSet.Take(100000))
235274
{
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);
237283
Assert.True(intSet.Contains(i));
238284
last = i;
239285
}
@@ -385,5 +431,25 @@ public void ExceptWithTest()
385431

386432
intSet.EqualRange(10001, 100000);
387433
}
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+
}
388454
}
389455
}

src/IntSet/IntSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,14 @@ private IEnumerable<int> TraverseRootCards(Card root)
531531
{
532532
for (int i0 = 32; i0 < 64; i0++)
533533
{
534-
if (root.Cards[i0] != null)
534+
if (root.Full || root.Cards[i0] != null)
535535
{
536536
yield return i0;
537537
}
538538
}
539539
for (int i0 = 0; i0 < 32; i0++)
540540
{
541-
if (root.Cards[i0] != null)
541+
if (root.Full || root.Cards[i0] != null)
542542
{
543543
yield return i0;
544544
}

0 commit comments

Comments
 (0)