1
// ****************************************************************
2
// Copyright 2009, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using System.Collections;
10
using NUnit.Core.Builders;
12
namespace NUnit.Core.Tests
15
public class PairwiseTest
20
public Hashtable pairsTested = new Hashtable();
23
public void TestFixtureSetUp()
25
pairsTested = new Hashtable();
29
public void TestFixtureTearDown()
31
Assert.That(pairsTested.Count, Is.EqualTo(16));
36
[Values("a", "b", "c")] string a,
37
[Values("+", "-")] string b,
38
[Values("x", "y")] string c)
40
Console.WriteLine("Pairwise: {0} {1} {2}", a, b, c);
42
pairsTested[a + b] = null;
43
pairsTested[a + c] = null;
44
pairsTested[b + c] = null;
48
// Test data is taken from various sources. See "Lessons Learned
49
// in Software Testing" pp 53-59, for example. For orthogonal cases, see
50
// http://www.freequality.org/sites/www_freequality_org/documents/tools/Tagarray_files/tamatrix.htm
51
internal static object[] cases = new object[]
54
new TestCaseData( new int[] { 2, 4 }, 8, 8 ).SetName("Test 2x4"),
55
new TestCaseData( new int[] { 2, 2, 2 }, 5, 4 ).SetName("Test 2x2x2"),
56
new TestCaseData( new int[] { 3, 2, 2 }, 6, 6 ).SetName("Test 3x2x2"),
57
new TestCaseData( new int[] { 3, 2, 2, 2 }, 7, 6 ).SetName("Test 3x2x2x2"),
58
new TestCaseData( new int[] { 3, 2, 2, 2, 2 }, 8, 6 ).SetName("Test 3x2x2x2x2"),
59
new TestCaseData( new int[] { 3, 2, 2, 2, 2, 2 }, 9, 8 ).SetName("Test 3x2x2x2x2x2"),
60
new TestCaseData( new int[] { 3, 3, 3 }, 12, 9 ).SetName("Test 3x3x3"),
61
new TestCaseData( new int[] { 4, 4, 4 }, 22, 16 ).SetName("Test 4x4x4"),
62
new TestCaseData( new int[] { 5, 5, 5 }, 34, 25 ).SetName("Test 5x5x5")
64
new TestCaseData( new int[] { 2, 4 }, 8, 8 ).SetName("Test 2x4"),
65
new TestCaseData( new int[] { 2, 2, 2 }, 5, 4 ).SetName("Test 2x2x2"),
66
new TestCaseData( new int[] { 3, 2, 2 }, 7, 6 ).SetName("Test 3x2x2"),
67
new TestCaseData( new int[] { 3, 2, 2, 2 }, 8, 6 ).SetName("Test 3x2x2x2"),
68
new TestCaseData( new int[] { 3, 2, 2, 2, 2 }, 9, 6 ).SetName("Test 3x2x2x2x2"),
69
new TestCaseData( new int[] { 3, 2, 2, 2, 2, 2 }, 9, 8 ).SetName("Test 3x2x2x2x2x2"),
70
new TestCaseData( new int[] { 3, 3, 3 }, 9, 9 ).SetName("Test 3x3x3"),
71
new TestCaseData( new int[] { 4, 4, 4 }, 17, 16 ).SetName("Test 4x4x4"),
72
new TestCaseData( new int[] { 5, 5, 5 }, 27, 25 ).SetName("Test 5x5x5")
76
[Test, TestCaseSource("cases")]
77
public void Test(int[] dimensions, int bestSoFar, int targetCases)
79
int features = dimensions.Length;
81
string[][] sources = new string[features][];
83
for (int i = 0; i < features; i++)
85
string featureName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(i, 1);
87
int n = dimensions[i];
88
sources[i] = new string[n];
89
for (int j = 0; j < n; j++)
90
sources[i][j] = featureName + j.ToString();
93
CombiningStrategy strategy = new PairwiseStrategy(sources);
95
Hashtable pairs = new Hashtable();
97
foreach (NUnit.Core.Extensibility.ParameterSet testcase in strategy.GetTestCases())
99
for (int i = 1; i < features; i++)
100
for (int j = 0; j < i; j++)
102
string a = testcase.Arguments[i] as string;
103
string b = testcase.Arguments[j] as string;
110
int expectedPairs = 0;
111
for (int i = 1; i < features; i++)
112
for (int j = 0; j < i; j++)
113
expectedPairs += dimensions[i] * dimensions[j];
115
Assert.That(pairs.Count, Is.EqualTo(expectedPairs), "Number of pairs is incorrect");
116
Assert.That(cases, Is.AtMost(bestSoFar), "Regression: Number of test cases exceeded target previously reached");
118
//Assert.That(cases, Is.AtMost(targetCases), "Number of test cases exceeded target");
1
// ****************************************************************
2
// Copyright 2009, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using System.Collections;
10
using NUnit.Core.Builders;
12
namespace NUnit.Core.Tests
15
public class PairwiseTest
20
public Hashtable pairsTested = new Hashtable();
23
public void TestFixtureSetUp()
25
pairsTested = new Hashtable();
29
public void TestFixtureTearDown()
31
Assert.That(pairsTested.Count, Is.EqualTo(16));
36
[Values("a", "b", "c")] string a,
37
[Values("+", "-")] string b,
38
[Values("x", "y")] string c)
40
Console.WriteLine("Pairwise: {0} {1} {2}", a, b, c);
42
pairsTested[a + b] = null;
43
pairsTested[a + c] = null;
44
pairsTested[b + c] = null;
48
// Test data is taken from various sources. See "Lessons Learned
49
// in Software Testing" pp 53-59, for example. For orthogonal cases, see
50
// http://www.freequality.org/sites/www_freequality_org/documents/tools/Tagarray_files/tamatrix.htm
51
internal static object[] cases = new object[]
54
new TestCaseData( new int[] { 2, 4 }, 8, 8 ).SetName("Test 2x4"),
55
new TestCaseData( new int[] { 2, 2, 2 }, 5, 4 ).SetName("Test 2x2x2"),
56
new TestCaseData( new int[] { 3, 2, 2 }, 6, 6 ).SetName("Test 3x2x2"),
57
new TestCaseData( new int[] { 3, 2, 2, 2 }, 7, 6 ).SetName("Test 3x2x2x2"),
58
new TestCaseData( new int[] { 3, 2, 2, 2, 2 }, 8, 6 ).SetName("Test 3x2x2x2x2"),
59
new TestCaseData( new int[] { 3, 2, 2, 2, 2, 2 }, 9, 8 ).SetName("Test 3x2x2x2x2x2"),
60
new TestCaseData( new int[] { 3, 3, 3 }, 12, 9 ).SetName("Test 3x3x3"),
61
new TestCaseData( new int[] { 4, 4, 4 }, 22, 16 ).SetName("Test 4x4x4"),
62
new TestCaseData( new int[] { 5, 5, 5 }, 34, 25 ).SetName("Test 5x5x5")
64
new TestCaseData( new int[] { 2, 4 }, 8, 8 ).SetName("Test 2x4"),
65
new TestCaseData( new int[] { 2, 2, 2 }, 5, 4 ).SetName("Test 2x2x2"),
66
new TestCaseData( new int[] { 3, 2, 2 }, 7, 6 ).SetName("Test 3x2x2"),
67
new TestCaseData( new int[] { 3, 2, 2, 2 }, 8, 6 ).SetName("Test 3x2x2x2"),
68
new TestCaseData( new int[] { 3, 2, 2, 2, 2 }, 9, 6 ).SetName("Test 3x2x2x2x2"),
69
new TestCaseData( new int[] { 3, 2, 2, 2, 2, 2 }, 9, 8 ).SetName("Test 3x2x2x2x2x2"),
70
new TestCaseData( new int[] { 3, 3, 3 }, 9, 9 ).SetName("Test 3x3x3"),
71
new TestCaseData( new int[] { 4, 4, 4 }, 17, 16 ).SetName("Test 4x4x4"),
72
new TestCaseData( new int[] { 5, 5, 5 }, 27, 25 ).SetName("Test 5x5x5")
76
[Test, TestCaseSource("cases")]
77
public void Test(int[] dimensions, int bestSoFar, int targetCases)
79
int features = dimensions.Length;
81
string[][] sources = new string[features][];
83
for (int i = 0; i < features; i++)
85
string featureName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(i, 1);
87
int n = dimensions[i];
88
sources[i] = new string[n];
89
for (int j = 0; j < n; j++)
90
sources[i][j] = featureName + j.ToString();
93
CombiningStrategy strategy = new PairwiseStrategy(sources);
95
Hashtable pairs = new Hashtable();
97
foreach (NUnit.Core.Extensibility.ParameterSet testcase in strategy.GetTestCases())
99
for (int i = 1; i < features; i++)
100
for (int j = 0; j < i; j++)
102
string a = testcase.Arguments[i] as string;
103
string b = testcase.Arguments[j] as string;
110
int expectedPairs = 0;
111
for (int i = 1; i < features; i++)
112
for (int j = 0; j < i; j++)
113
expectedPairs += dimensions[i] * dimensions[j];
115
Assert.That(pairs.Count, Is.EqualTo(expectedPairs), "Number of pairs is incorrect");
116
Assert.That(cases, Is.AtMost(bestSoFar), "Regression: Number of test cases exceeded target previously reached");
118
//Assert.That(cases, Is.AtMost(targetCases), "Number of test cases exceeded target");