-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISorterTests.cs
73 lines (70 loc) · 2.28 KB
/
ISorterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using NUnit.Framework;
using System.Collections.Generic;
namespace Sort
{
public class ISorterTests
{
public static IEnumerable<ISorter> sorters {
get {
yield return new SelectionSort();
yield return new InsertionSort();
}
}
public static IEnumerable<SortTestData> testData {
get {
yield return new SortTestData(
new int[0],
new int[0]
);
yield return new SortTestData(
new [] { 0 },
new [] { 0 }
);
yield return new SortTestData(
new int[] {5, 4, 3, 2, 1 },
new int[] {1, 2, 3, 4, 5 }
);
yield return new SortTestData(
new int[] { 1, 2, 3, 4, 5, 6 },
new int[] { 1, 2, 3, 4, 5, 6 }
);
yield return new SortTestData(
new int[] { 1, 2, -3, 4, 5 },
new int[] { -3, 1, 2, 4, 5 }
);
yield return new SortTestData(
new int[] { 1, 2, 3, 5, 4 },
new int[] { 1, 2, 3, 4, 5 }
);
yield return new SortTestData(
new int[] { 5000000, 100, 2000, 30000, 400000 },
new int[] { 100, 2000, 30000, 400000, 5000000 }
);
yield return new SortTestData(
new int[] { 4, 1, 1, 1, 1 },
new int[] { 1, 1, 1, 1, 4 }
);
yield return new SortTestData(
new int[] { 1, 1, 1, 1, 1 },
new int[] { 1, 1, 1, 1, 1 }
);
}
}
[Test]
[Combinatorial]
public void TestCase(
[ValueSource("sorters")] ISorter sorter,
[ValueSource("testData")] SortTestData testData)
{
CollectionAssert.AreEqual(testData.Sorted, sorter.Sort(testData.Unsorted));
}
}
public class SortTestData{
public int[] Unsorted { get; set; }
public int[] Sorted { get; set; }
public SortTestData(int[] unsorted, int[] sorted) {
Unsorted = unsorted;
Sorted = sorted;
}
}
}