示例#1
0
        public static Collection <FileInfo> Reduce(Collection <FileInfo> tests)
        {
            Dictionary <EquivClass, TestCase> representatives          = new Dictionary <EquivClass, TestCase>();
            Dictionary <EquivClass, FileInfo> representativesFileInfos = new Dictionary <EquivClass, FileInfo>();


            foreach (FileInfo file in tests)
            {
                TestCase testCase;
                try
                {
                    testCase = new TestCase(file);
                }
                catch (Exception)
                {
                    // File does not contain a valid test case, or
                    // test case is malformed.
                    continue;
                }


                EquivClass partition = new EquivClass(testCase);
                // If there are no representatives for this partition,
                // use testCase as the representative.
                if (!representatives.ContainsKey(partition))
                {
                    representatives[partition]          = testCase;
                    representativesFileInfos[partition] = file;
                }
                // if testCase is smaller than the current representative,
                // use testCase as the representative.
                // Delete the old representative.
                else if (testCase.NumTestLines < representatives[partition].NumTestLines)
                {
                    //representativesFileInfos[partition].Delete();
                    representativesFileInfos[partition].MoveTo(representativesFileInfos[partition].FullName + ".reduced");

                    representatives[partition]          = testCase;
                    representativesFileInfos[partition] = file;
                }
                // Representative is redundant and larger than current representative.
                // Delete representative.
                else
                {
                    //file.Delete();
                    file.MoveTo(file.FullName + ".reduced");
                }
            }

            List <FileInfo> retval = new List <FileInfo>();

            retval.AddRange(representativesFileInfos.Values);
            return(new Collection <FileInfo>(retval));
        }
示例#2
0
            public override bool Equals(object obj)
            {
                EquivClass other = obj as EquivClass;

                if (other == null)
                {
                    return(false);
                }
                if (!this.representative.exception.Equals(other.representative.exception))
                {
                    return(false);
                }
                if (!this.representative.lastAction.Equals(other.representative.lastAction))
                {
                    return(false);
                }
                return(true);
            }
示例#3
0
            public override bool Equals(object obj)
            {
                EquivClass other = obj as EquivClass;

                if (other == null)
                {
                    return(false);
                }
                if (!this.representative.exception.Equals(other.representative.exception)) // if "throw the same exception"
                {
                    return(false);
                }
                if (!this.representative.lastAction.Equals(other.representative.lastAction)) // if "end with the same method call"
                {
                    return(false);
                }
                return(true);
            }
示例#4
0
        /// <summary>
        /// Given an array of predidates {p_1, p_2, ..., p_n} where n>=0.
        /// Enumerate all satisfiable Boolean combinations Tuple({b_1, b_2, ..., b_n}, p)
        /// where p is satisfiable and equivalent to p'_1 &amp; p'_2 &amp; ... &amp; p'_n,
        /// where p'_i = p_i if b_i = true and p'_i is Not(p_i) otherwise.
        /// If n=0 return Tuple({},True).
        /// </summary>
        /// <param name="preds">array of predicates</param>
        /// <param name="useEquivalenceChecking">optimization flag: if true, uses equivalence checking to cluster equivalent predicates; otherwise does not use equivalence checking</param>
        /// <returns>all minterms of the given predicate sequence</returns>
        public IEnumerable <Tuple <bool[], PRED> > GenerateMinterms(bool useEquivalenceChecking, params PRED[] preds)
        {
            if (preds.Length == 0)
            {
                yield return(new Tuple <bool[], PRED>(new bool[] { }, ba.True));
            }
            else
            {
                var count = preds.Length;

                List <PRED> nonequivalentSets = new List <PRED>();

                //work only with nonequivalent sets as distinct elements
                var indexLookup = new Dictionary <int, int>();
                var newIndexMap = new Dictionary <EquivClass, int>();
                var equivs      = new List <List <int> >();

                for (int i = 0; i < count; i++)
                {
                    int        newIndex;
                    EquivClass equiv = CreateEquivalenceClass(useEquivalenceChecking, preds[i]);
                    if (!newIndexMap.TryGetValue(equiv, out newIndex))
                    {
                        newIndex           = newIndexMap.Count;
                        newIndexMap[equiv] = newIndex;
                        nonequivalentSets.Add(preds[i]);
                        equivs.Add(new List <int>());
                    }
                    indexLookup[i] = newIndex;
                    equivs[newIndex].Add(i);
                }

                //var pairs = new List<Tuple<IntSet, PRED>>(GenerateMinterms1(nonequivalentSets.ToArray()));
                //foreach (var pair in pairs)
                //{
                //    var characteristic = new bool[preds.Length];
                //    for (int i = 0; i < count; i++)
                //        if (pair.First.Contains(indexLookup[i]))
                //            characteristic[i] = true;
                //    yield return
                //        new Tuple<bool[], PRED>(characteristic, pair.Second);
                //}

                var tree = new PartitonTree <PRED>(ba);
                foreach (var psi in nonequivalentSets)
                {
                    tree.Refine(psi);
                }
                foreach (var leaf in tree.GetLeaves())
                {
                    var characteristic = new bool[preds.Length];
                    foreach (var k in leaf.GetPath())
                    {
                        foreach (var n in equivs[k])
                        {
                            characteristic[n] = true;
                        }
                    }
                    yield return
                        (new Tuple <bool[], PRED>(characteristic, leaf.phi));
                }
            }
        }
示例#5
0
        public static Collection<FileInfo> Reduce(Collection<FileInfo> tests)
        {
            Dictionary<EquivClass, TestCase> representatives = new Dictionary<EquivClass, TestCase>();
            Dictionary<EquivClass, FileInfo> representativesFileInfos = new Dictionary<EquivClass, FileInfo>();


            foreach (FileInfo file in tests)
            {
                TestCase testCase;
                try
                {
                    testCase = new TestCase(file);
                }
                catch (Exception)
                {
                    // File does not contain a valid test case, or
                    // test case is malformed.
                    continue;
                }


                EquivClass partition = new EquivClass(testCase);
                // If there are no representatives for this partition,
                // use testCase as the representative.
                if (!representatives.ContainsKey(partition))
                {
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // if testCase is smaller than the current representative,
                // use testCase as the representative.
                // Delete the old representative.
                else if (testCase.NumTestLines < representatives[partition].NumTestLines)
                {
                    representativesFileInfos[partition].Delete();
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // Representative is redundant and larger than current representative.
                // Delete representative.
                else
                {
                    file.Delete();
                }
            }

            List<FileInfo> retval = new List<FileInfo>();
            retval.AddRange(representativesFileInfos.Values);
            return new Collection<FileInfo>(retval);
        }