Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit db1c7be

Browse files
author
J Burnett
committed
Improve test reliability
1 parent f073ac5 commit db1c7be

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

test/IntListRandomizerTests.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class IntListRandomizerTests : IClassFixture<IntListTestFixture>
1414
{
1515
IntListTestFixture _testData;
1616

17+
1718
public IntListRandomizerTests(IntListTestFixture testData)
1819
{
1920
_testData = testData;
@@ -25,14 +26,10 @@ public IntListRandomizerTests(IntListTestFixture testData)
2526
[Fact]
2627
public void random_element_from_int_list()
2728
{
28-
// Get random elements from ~1/10 of the list. The probability of sequential duplicates
29-
// increases when covering more of the available elements.
30-
int prev = -1;
31-
for (int i = 0; i < _testData.TestList.Count/10; ++i)
29+
for (int i = 0; i < _testData.TestList.Count; ++i)
3230
{
3331
int curr = _testData.TestList.Random();
34-
curr.Should().NotBe(prev);
35-
prev = curr;
32+
curr.Should().BeGreaterOrEqualTo(IntListTestFixture.MinTestValue);
3633
}
3734
}
3835

@@ -44,7 +41,7 @@ public void random_element_from_int_list_by_IEnumerable()
4441
foreach (var itr in enumr)
4542
{
4643
int curr = enumr.Random();
47-
curr.Should().BeGreaterThan(-1);
44+
curr.Should().BeGreaterOrEqualTo(IntListTestFixture.MinTestValue);
4845
}
4946
}
5047

@@ -73,12 +70,11 @@ public void random_element_from_()
7370

7471
// Get random elements from ~1/10 of the list. The probability of sequential duplicates
7572
// increases when covering more of the available elements.
76-
KeyValuePair<int, string> prev = new KeyValuePair<int, string>();
77-
for (int i = 0; i < list.Count/10; ++i)
73+
for (int i = 0; i < list.Count; ++i)
7874
{
7975
var curr = list.Random();
80-
curr.Should().NotBe(prev);
81-
prev = curr;
76+
curr.Key.Should().BeGreaterOrEqualTo(IntListTestFixture.MinTestValue);
77+
curr.Value.Should().BeEquivalentTo(curr.Key.ToString());
8278
}
8379
}
8480

test/IntListTestFixture.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ public class IntListTestFixture : IDisposable
1010
{
1111

1212
public List<int> TestList { get; set; }
13+
public const int MinTestValue = 0;
14+
public const int MaxTestValue = 250;
15+
1316

1417
public IntListTestFixture()
1518
{
1619
TestList = new List<int>();
17-
for (int i = 0; i < 250; ++i)
20+
for (int i = MinTestValue; i < MaxTestValue; ++i)
1821
{
1922
TestList.Add(i);
2023
}
21-
2224
}
2325

2426

0 commit comments

Comments
 (0)