PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/NUnit/core/Builders/CombinatorialStrategy.cs

#
C# | 60 lines | 43 code | 12 blank | 5 comment | 7 complexity | b0ecfbd06d3691519ffa341bb2112d4c MD5 | raw file
 1// ****************************************************************
 2// Copyright 2008, 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
 7using System;
 8using System.Collections;
 9using System.Reflection;
10using NUnit.Core.Extensibility;
11#if NET_2_0
12using System.Collections.Generic;
13#endif
14
15namespace NUnit.Core.Builders
16{
17    public class CombinatorialStrategy : CombiningStrategy
18    {
19        public CombinatorialStrategy(IEnumerable[] sources) : base(sources) { }
20
21        public override IEnumerable GetTestCases()
22        {
23            IEnumerator[] enumerators = new IEnumerator[Sources.Length];
24            int index = -1;
25
26#if NET_2_0
27            List<ParameterSet> testCases = new List<ParameterSet>();
28#else
29			ArrayList testCases = new ArrayList();
30#endif
31
32            for (; ; )
33            {
34                while (++index < Sources.Length)
35                {
36                    enumerators[index] = Sources[index].GetEnumerator();
37                    if (!enumerators[index].MoveNext())
38						return testCases;
39                }
40
41                object[] testdata = new object[Sources.Length];
42
43                for (int i = 0; i < Sources.Length; i++)
44                    testdata[i] = enumerators[i].Current;
45
46                ParameterSet testCase = new ParameterSet();
47                testCase.Arguments = testdata;
48				testCases.Add(testCase);
49
50                index = Sources.Length;
51
52                while (--index >= 0 && !enumerators[index].MoveNext()) ;
53
54                if (index < 0) break;
55            }
56
57			return testCases;
58        }
59    }
60}