Пример #1
0
            /// <summary>
            /// Creates a set of test cases for specified dimensions.
            /// </summary>
            /// <param name="dimensions">
            /// An array which contains information about dimensions. Each element of
            /// this array represents a number of features in the specific dimension.
            /// </param>
            /// <returns>
            /// A set of test cases.
            /// </returns>
            public IEnumerable GetTestCases(int[] dimensions)
            {
                _prng       = new FleaRand(15485863);
                _dimensions = dimensions;

                CreateAllTuples();

                List <TestCaseInfo> testCases = new List <TestCaseInfo>();

                while (true)
                {
                    FeatureTuple tuple = GetNextTuple();

                    if (tuple == null)
                    {
                        break;
                    }

                    TestCaseInfo testCase = CreateTestCase(tuple);

                    RemoveTuplesCoveredByTest(testCase);

                    testCases.Add(testCase);
                }

#if DEBUG
                SelfTest(testCases);
#endif

                return(testCases);
            }
Пример #2
0
            private int MaximizeCoverage(TestCaseInfo testCase, FeatureTuple tuple)
            {
                // It starts with one because we always have one tuple which is covered by the test.
                int totalCoverage = 1;

                int[] mutableDimensions = GetMutableDimensions(tuple);

                while (true)
                {
                    bool progress = false;

                    ScrambleDimensions(mutableDimensions);

                    for (int i = 0; i < mutableDimensions.Length; i++)
                    {
                        int d = mutableDimensions[i];

                        int bestCoverage = CountTuplesCoveredByTest(testCase, d, testCase.Features[d]);

                        int newCoverage = MaximizeCoverageForDimension(testCase, d, bestCoverage);

                        totalCoverage += newCoverage;

                        if (newCoverage > bestCoverage)
                        {
                            progress = true;
                        }
                    }

                    if (!progress)
                    {
                        return(totalCoverage);
                    }
                }
            }
            /// <summary>
            /// Creates a set of test cases for specified dimensions.
            /// </summary>
            /// <param name="dimensions">
            /// An array which contains information about dimensions. Each element of
            /// this array represents a number of features in the specific dimension.
            /// </param>
            /// <returns>
            /// A set of test cases.
            /// </returns>
            public List <TestCaseInfo> GetTestCases(int[] dimensions)
            {
                this.prng       = new FleaRand(15485863);
                this.dimensions = dimensions;

                this.CreateAllTuples();

                List <TestCaseInfo> testCases = new List <TestCaseInfo>();

                while (true)
                {
                    FeatureTuple tuple = this.GetNextTuple();

                    if (tuple == null)
                    {
                        break;
                    }

                    TestCaseInfo testCase = this.CreateTestCase(tuple);

                    this.RemoveTuplesCoveredByTest(testCase);

                    testCases.Add(testCase);
                }

                return(testCases);
            }
Пример #4
0
            private bool IsTupleCovered(List <TestCaseInfo> testCases, FeatureTuple tuple)
            {
                foreach (TestCaseInfo testCase in testCases)
                {
                    if (testCase.IsTupleCovered(tuple))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        private static bool IsTupleCovered(this TestCaseInfo testCaseInfo, FeatureTuple tuple)
        {
            for (int i = 0; i < tuple.Length; i++)
            {
                if (testCaseInfo.Features[tuple[i].Dimension] != tuple[i].Feature)
                {
                    return(false);
                }
            }

            return(true);
        }
        private static bool IsTupleCovered(this TestCaseInfo testCaseInfo, FeatureTuple tuple)
        {
            for (int i = 0; i < tuple.Length; i++)
            {
                if (testCaseInfo.Features[tuple[i].Dimension] != tuple[i].Feature)
                {
                    return false;
                }
            }

            return true;
        }
Пример #7
0
            public bool IsTupleCovered(FeatureTuple tuple)
            {
                for (int i = 0; i < tuple.Length; i++)
                {
                    if (Features[tuple[i].Dimension] != tuple[i].Feature)
                    {
                        return(false);
                    }
                }

                return(true);
            }
Пример #8
0
            private TestCaseInfo CreateRandomTestCase(FeatureTuple tuple)
            {
                TestCaseInfo result = new TestCaseInfo(_dimensions.Length);

                for (int d = 0; d < _dimensions.Length; d++)
                {
                    result.Features[d] = GetNextRandomNumber() % _dimensions[d];
                }

                for (int i = 0; i < tuple.Length; i++)
                {
                    result.Features[tuple[i].Dimension] = tuple[i].Feature;
                }

                return(result);
            }
Пример #9
0
            private FeatureTuple GetNextTuple()
            {
                for (int d = 0; d < _uncoveredTuples.Length; d++)
                {
                    for (int f = 0; f < _uncoveredTuples[d].Length; f++)
                    {
                        List <FeatureTuple> tuples = _uncoveredTuples[d][f];

                        if (tuples.Count > 0)
                        {
                            FeatureTuple tuple = tuples[0];
                            tuples.RemoveAt(0);
                            return(tuple);
                        }
                    }
                }

                return(null);
            }
Пример #10
0
            private TestCaseInfo CreateTestCase(FeatureTuple tuple)
            {
                TestCaseInfo bestTestCase = null;
                int          bestCoverage = -1;

                for (int i = 0; i < 7; i++)
                {
                    TestCaseInfo testCase = CreateRandomTestCase(tuple);

                    int coverage = MaximizeCoverage(testCase, tuple);

                    if (coverage > bestCoverage)
                    {
                        bestTestCase = testCase;
                        bestCoverage = coverage;
                    }
                }

                return(bestTestCase);
            }
Пример #11
0
            private void SelfTest(List <TestCaseInfo> testCases)
            {
                for (int d1 = 0; d1 < _dimensions.Length - 1; d1++)
                {
                    for (int d2 = d1 + 1; d2 < _dimensions.Length; d2++)
                    {
                        for (int f1 = 0; f1 < _dimensions[d1]; f1++)
                        {
                            for (int f2 = 0; f2 < _dimensions[d2]; f2++)
                            {
                                FeatureTuple tuple = new FeatureTuple(new FeatureInfo(d1, f1), new FeatureInfo(d2, f2));

                                if (!IsTupleCovered(testCases, tuple))
                                {
                                    throw new InvalidOperationException(string.Format("PairwiseStrategy : Not all pairs are covered : {0}", tuple.ToString()));
                                }
                            }
                        }
                    }
                }
            }
Пример #12
0
            private int[] GetMutableDimensions(FeatureTuple tuple)
            {
                List <int> result = new List <int>();

                bool[] immutableDimensions = new bool[_dimensions.Length];

                for (int i = 0; i < tuple.Length; i++)
                {
                    immutableDimensions[tuple[i].Dimension] = true;
                }

                for (int d = 0; d < _dimensions.Length; d++)
                {
                    if (!immutableDimensions[d])
                    {
                        result.Add(d);
                    }
                }

                return(result.ToArray());
            }
Пример #13
0
            public bool IsTupleCovered( FeatureTuple tuple )
            {
                for ( int i = 0; i < tuple.Length; i++ )
                {
                    if ( Features[tuple[i].Dimension] != tuple[i].Feature )
                    {
                        return false;
                    }
                }

                return true;
            }
Пример #14
0
            private void SelfTest( List<TestCaseInfo> testCases )
            {
                for ( int d1 = 0; d1 < _dimensions.Length - 1; d1++ )
                {
                    for ( int d2 = d1 + 1; d2 < _dimensions.Length; d2++ )
                    {
                        for ( int f1 = 0; f1 < _dimensions[d1]; f1++ )
                        {
                            for ( int f2 = 0; f2 < _dimensions[d2]; f2++ )
                            {
                                FeatureTuple tuple = new FeatureTuple( new FeatureInfo( d1, f1 ), new FeatureInfo( d2, f2 ) );

                                if ( !IsTupleCovered( testCases, tuple ) )
                                {
                                    throw new InvalidOperationException( string.Format( "PairwiseStrategy : Not all pairs are covered : {0}", tuple.ToString() ) );
                                }
                            }
                        }
                    }
                }
            }
            private int[] GetMutableDimensions(FeatureTuple tuple)
            {
                List<int> result = new List<int>();

                bool[] immutableDimensions = new bool[this.dimensions.Length];

                for (int i = 0; i < tuple.Length; i++)
                {
                    immutableDimensions[tuple[i].Dimension] = true;
                }

                for (int d = 0; d < this.dimensions.Length; d++)
                {
                    if (!immutableDimensions[d])
                    {
                        result.Add(d);
                    }
                }

                return result.ToArray();
            }
            private int MaximizeCoverage(TestCaseInfo testCase, FeatureTuple tuple)
            {
                // It starts with one because we always have one tuple which is covered by the test.
                int totalCoverage = 1;
                int[] mutableDimensions = this.GetMutableDimensions(tuple);

                while (true)
                {
                    bool progress = false;

                    this.ScrambleDimensions(mutableDimensions);

                    for (int i = 0; i < mutableDimensions.Length; i++)
                    {
                        int d = mutableDimensions[i];

                        int bestCoverage = this.CountTuplesCoveredByTest(testCase, d, testCase.Features[d]);

                        int newCoverage = this.MaximizeCoverageForDimension(testCase, d, bestCoverage);

                        totalCoverage += newCoverage;

                        if (newCoverage > bestCoverage)
                        {
                            progress = true;
                        }
                    }

                    if (!progress)
                    {
                        return totalCoverage;
                    }
                }
            }
            private TestCaseInfo CreateRandomTestCase(FeatureTuple tuple)
            {
                TestCaseInfo result = new TestCaseInfo(this.dimensions.Length);

                for (int d = 0; d < this.dimensions.Length; d++)
                {
                    result.Features[d] = this.GetNextRandomNumber() % this.dimensions[d];
                }

                for (int i = 0; i < tuple.Length; i++)
                {
                    result.Features[tuple[i].Dimension] = tuple[i].Feature;
                }

                return result;
            }
            private TestCaseInfo CreateTestCase(FeatureTuple tuple)
            {
                TestCaseInfo bestTestCase = null;
                int bestCoverage = -1;

                for (int i = 0; i < 7; i++)
                {
                    TestCaseInfo testCase = this.CreateRandomTestCase(tuple);

                    int coverage = this.MaximizeCoverage(testCase, tuple);

                    if (coverage > bestCoverage)
                    {
                        bestTestCase = testCase;
                        bestCoverage = coverage;
                    }
                }

                return bestTestCase;
            }
Пример #19
0
            private bool IsTupleCovered( List<TestCaseInfo> testCases, FeatureTuple tuple )
            {
                foreach ( TestCaseInfo testCase in testCases )
                {
                    if ( testCase.IsTupleCovered( tuple ) )
                    {
                        return true;
                    }
                }

                return false;
            }