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

Commit e909e79

Browse files
author
J Burnett
committed
Implement better test data
1 parent 43108b8 commit e909e79

2 files changed

Lines changed: 58 additions & 11 deletions

File tree

test/IntListTestFixture.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Xunit;
4+
5+
6+
namespace Test.AMT.LinqExtensions
7+
{
8+
9+
public class TestDataFixture : IDisposable
10+
{
11+
12+
public List<int> TestList { get; set; }
13+
14+
public TestDataFixture()
15+
{
16+
TestList = new List<int>();
17+
for (int i = 0; i < 250; ++i)
18+
{
19+
TestList.Add(i);
20+
}
21+
22+
}
23+
24+
25+
#region IDisposable Support
26+
private bool disposedValue = false; // To detect redundant calls
27+
28+
protected virtual void Dispose(bool disposing)
29+
{
30+
if (!disposedValue)
31+
{
32+
disposedValue = true;
33+
}
34+
}
35+
36+
// This code added to correctly implement the disposable pattern.
37+
void IDisposable.Dispose()
38+
{
39+
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
40+
Dispose(true);
41+
}
42+
43+
#endregion IDisposable Support
44+
45+
}
46+
47+
}

test/LinqExtensionsTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ namespace Test.AMT.LinqExtensions
1010
// TODO: include when doing code coverage
1111
// [ExcludeFromCodeCoverage]
1212

13-
public class LinqRandomizerTests
13+
public class LinqRandomizerTests : IClassFixture<TestDataFixture>
1414
{
15+
TestDataFixture _testData;
16+
17+
public LinqRandomizerTests(TestDataFixture testData)
18+
{
19+
_testData = testData;
20+
}
21+
1522

1623
#region Positive tests
1724

1825
[Fact]
1926
public void random_element_from_int_list()
2027
{
21-
List<int> list = new List<int>();
22-
for (int i = 0; i < 250; ++i) { list.Add(i); }
23-
2428
// Get random elements from ~1/10 of the list. The probability of sequential duplicates
2529
// increases when covering more of the available elements.
2630
int prev = -1;
27-
for (int i = 0; i < list.Count/10; ++i)
31+
for (int i = 0; i < _testData.TestList.Count/10; ++i)
2832
{
29-
int curr = list.Random();
33+
int curr = _testData.TestList.Random();
3034
curr.Should().NotBe(prev);
3135
prev = curr;
3236
}
@@ -36,10 +40,7 @@ public void random_element_from_int_list()
3640
[Fact]
3741
public void random_element_from_int_list_by_IEnumerable()
3842
{
39-
List<int> list = new List<int>();
40-
for (int i = 0; i < 250; ++i) { list.Add(i); }
41-
42-
IEnumerable<int> enumr = list;
43+
IEnumerable<int> enumr = _testData.TestList;
4344
foreach (var itr in enumr)
4445
{
4546
int curr = enumr.Random();
@@ -67,7 +68,6 @@ public void random_element_from_single_item_list()
6768
[Fact]
6869
public void random_element_from_()
6970
{
70-
7171
SortedList<int, string> list = new SortedList<int, string>();
7272
for (int i = 0; i < 250; ++i) { list.Add(i, i.ToString()); }
7373

0 commit comments

Comments
 (0)