~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/NUnitCore/tests/PairwiseTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
// ****************************************************************
6
 
 
7
 
using System;
8
 
using System.Collections;
9
 
using NUnit.Framework;
10
 
using NUnit.Core.Builders;
11
 
 
12
 
namespace NUnit.Core.Tests
13
 
{
14
 
    [TestFixture]
15
 
    public class PairwiseTest
16
 
    {
17
 
        [TestFixture]
18
 
        public class LiveTest
19
 
        {
20
 
            public Hashtable pairsTested = new Hashtable();
21
 
 
22
 
            [TestFixtureSetUp]
23
 
            public void TestFixtureSetUp()
24
 
            {
25
 
                pairsTested = new Hashtable();
26
 
            }
27
 
 
28
 
            [TestFixtureTearDown]
29
 
            public void TestFixtureTearDown()
30
 
            {
31
 
                Assert.That(pairsTested.Count, Is.EqualTo(16));
32
 
            }
33
 
 
34
 
            [Test, Pairwise]
35
 
            public void Test(
36
 
                [Values("a", "b", "c")] string a,
37
 
                [Values("+", "-")] string b,
38
 
                [Values("x", "y")] string c)
39
 
            {
40
 
                Console.WriteLine("Pairwise: {0} {1} {2}", a, b, c);
41
 
 
42
 
                pairsTested[a + b] = null;
43
 
                pairsTested[a + c] = null;
44
 
                pairsTested[b + c] = null;
45
 
            }
46
 
        }
47
 
 
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[]
52
 
        {
53
 
#if ORIGINAL
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")
63
 
#else
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")
73
 
#endif
74
 
        };
75
 
 
76
 
        [Test, TestCaseSource("cases")]
77
 
        public void Test(int[] dimensions, int bestSoFar, int targetCases)
78
 
        {
79
 
            int features = dimensions.Length;
80
 
 
81
 
            string[][] sources = new string[features][];
82
 
 
83
 
            for (int i = 0; i < features; i++)
84
 
            {
85
 
                string featureName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(i, 1);
86
 
 
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();
91
 
            }
92
 
 
93
 
            CombiningStrategy strategy = new PairwiseStrategy(sources);
94
 
 
95
 
            Hashtable pairs = new Hashtable();
96
 
            int cases = 0;
97
 
            foreach (NUnit.Core.Extensibility.ParameterSet testcase in strategy.GetTestCases())
98
 
            {
99
 
                for (int i = 1; i < features; i++)
100
 
                    for (int j = 0; j < i; j++)
101
 
                    {
102
 
                        string a = testcase.Arguments[i] as string;
103
 
                        string b = testcase.Arguments[j] as string;
104
 
                        pairs[a + b] = null;
105
 
                    }
106
 
 
107
 
                ++cases;
108
 
            }
109
 
 
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];
114
 
 
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");
117
 
#if DEBUG
118
 
            //Assert.That(cases, Is.AtMost(targetCases), "Number of test cases exceeded target");
119
 
#endif
120
 
        }
121
 
    }
122
 
}
 
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
// ****************************************************************
 
6
 
 
7
using System;
 
8
using System.Collections;
 
9
using NUnit.Framework;
 
10
using NUnit.Core.Builders;
 
11
 
 
12
namespace NUnit.Core.Tests
 
13
{
 
14
    [TestFixture]
 
15
    public class PairwiseTest
 
16
    {
 
17
        [TestFixture]
 
18
        public class LiveTest
 
19
        {
 
20
            public Hashtable pairsTested = new Hashtable();
 
21
 
 
22
            [TestFixtureSetUp]
 
23
            public void TestFixtureSetUp()
 
24
            {
 
25
                pairsTested = new Hashtable();
 
26
            }
 
27
 
 
28
            [TestFixtureTearDown]
 
29
            public void TestFixtureTearDown()
 
30
            {
 
31
                Assert.That(pairsTested.Count, Is.EqualTo(16));
 
32
            }
 
33
 
 
34
            [Test, Pairwise]
 
35
            public void Test(
 
36
                [Values("a", "b", "c")] string a,
 
37
                [Values("+", "-")] string b,
 
38
                [Values("x", "y")] string c)
 
39
            {
 
40
                Console.WriteLine("Pairwise: {0} {1} {2}", a, b, c);
 
41
 
 
42
                pairsTested[a + b] = null;
 
43
                pairsTested[a + c] = null;
 
44
                pairsTested[b + c] = null;
 
45
            }
 
46
        }
 
47
 
 
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[]
 
52
        {
 
53
#if ORIGINAL
 
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")
 
63
#else
 
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")
 
73
#endif
 
74
        };
 
75
 
 
76
        [Test, TestCaseSource("cases")]
 
77
        public void Test(int[] dimensions, int bestSoFar, int targetCases)
 
78
        {
 
79
            int features = dimensions.Length;
 
80
 
 
81
            string[][] sources = new string[features][];
 
82
 
 
83
            for (int i = 0; i < features; i++)
 
84
            {
 
85
                string featureName = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(i, 1);
 
86
 
 
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();
 
91
            }
 
92
 
 
93
            CombiningStrategy strategy = new PairwiseStrategy(sources);
 
94
 
 
95
            Hashtable pairs = new Hashtable();
 
96
            int cases = 0;
 
97
            foreach (NUnit.Core.Extensibility.ParameterSet testcase in strategy.GetTestCases())
 
98
            {
 
99
                for (int i = 1; i < features; i++)
 
100
                    for (int j = 0; j < i; j++)
 
101
                    {
 
102
                        string a = testcase.Arguments[i] as string;
 
103
                        string b = testcase.Arguments[j] as string;
 
104
                        pairs[a + b] = null;
 
105
                    }
 
106
 
 
107
                ++cases;
 
108
            }
 
109
 
 
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];
 
114
 
 
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");
 
117
#if DEBUG
 
118
            //Assert.That(cases, Is.AtMost(targetCases), "Number of test cases exceeded target");
 
119
#endif
 
120
        }
 
121
    }
 
122
}