protected IUndoableEdit FillTestCasesFromNegativeCombinations(ICollection <TestCase> testCases)
        {
            CompoundEdit ce = new CompoundEdit();

            TestCase testCase = null;

            foreach (Dependency dependency in dependencies)
            {
                foreach (Combination combination in dependency.Combinations)
                {
                    if (combination.CurrentState == State.NEGATIVE)
                    {
                        testCase = new TestCase();

                        ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(testCase, "Origin", TestCaseOrigin.GENERATED));
                        testCase.Origin = TestCaseOrigin.GENERATED;
                        ce.AddEdit(PolicyFactory.instance.AddCombinationToTestCasePolicy(testCase, combination));
                        testCases.Add(testCase);
                    }
                }
            }


            return(ce);
        }
        public virtual IUndoableEdit Generate()
        {
            ValidateModel();
            CompoundEdit     ce    = new CompoundEdit();
            IPolicyFactory   pfact = new PolicyFactory();
            IList <TestCase> generatedTestCases = new List <TestCase>();

            //generate the test cases
            ce.AddEdit(FillTestCases(generatedTestCases));
            //delete the common test cases from the structure
            ce.AddEdit(pfact.DeleteCommonTestCasesPolicy(structure, genState, dependencies));
            if (generatedTestCases.Count + structure.GetTestCases(genState).Count > maxTestCases)
            {
                ce.EndAllEdits();
                ce.Undo();
                throw new Exception("Maximal number of " + EntityWithEvents.GetDescription(genState) + " Test Cases reached");
            }

            //add the new generated test cases
            foreach (TestCase tc in generatedTestCases)
            {
                //check if the structure has the same test cases before insert
                if (!structure.ContainsSameTestCaseByRelations(tc))
                {
                    ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(tc, "Position", structure.GetNewTestCasePosition()));
                    tc.Position = structure.GetNewTestCasePosition();
                    ce.AddEdit(EditFactory.instance.CreateAddTestCaseEdit(structure, tc));
                    structure.AddTestCase(tc);
                }
            }
            return(ce);
        }
Beispiel #3
0
        public IUndoableEdit DeleteCombination(TestCasesStructure structure)
        {
            CompoundEdit ce = new CompoundEdit();

            if (structure != null)
            {
                //delete the reference from all test cases
                foreach (TestCase testCase in structure.TestCases)
                {
                    if (testCase.Combinations.Contains(combination))
                    {
                        ce.AddEdit(
                            EditFactory.instance.CreateRemoveCombinationEdit(testCase, combination));
                        testCase.RemoveCombination(combination);
                    }
                }
                //delete the combination from all other combinations
                foreach (Combination combination1 in combination.ParentDependency.Combinations)
                {
                    if (combination1.Combinations.Contains(combination))
                    {
                        ce.AddEdit(EditFactory.instance.CreateRemoveCombinationEdit(combination1, combination1));
                        combination1.RemoveCombination(combination);
                    }
                }
            }
            ce.AddEdit(EditFactory.instance.CreateRemoveCombinationEdit(combination.ParentDependency, combination));
            combination.ParentDependency.RemoveCombination(combination);
            return(ce);
        }
        public IUndoableEdit ChangeRiskLevel(int newRiskLevel)
        {
            CompoundEdit ce = new CompoundEdit();

            //check if is posible to assign the new risk level
            if (riskLevelObject.GetParentRiskLevels() != null)
            {
                foreach (IRiskLevelObject parentRiskLevel in riskLevelObject.GetParentRiskLevels())
                {
                    if (newRiskLevel < parentRiskLevel.RiskLevel)
                    {
                        throw new Exception("The risk level cannot change, contains a greater risk level as a parent");
                    }
                }
            }
            //change the risk level of each children
            if (riskLevelObject.GetChildrenRiskLevels() != null)
            {
                foreach (IRiskLevelObject o in riskLevelObject.GetChildrenRiskLevels())
                {
                    RiskLevelManager rlm = new RiskLevelManager(o);
                    ce.AddEdit(rlm.ChangeRiskLevel(newRiskLevel));
                }
            }
            ce.AddEdit(EditFactory.instance.CreateChangeRiskLevelEdit(riskLevelObject, newRiskLevel));
            riskLevelObject.RiskLevel = newRiskLevel;
            return(ce);
        }
Beispiel #5
0
        public void BasicFunctionality()
        {
            IEditFactory fact = EditFactory.instance;
            Element      elem = new Element();

            EquivalenceClass equivalenceClass = new EquivalenceClass();
            Effect           effect           = new Effect();

            ce.AddEdit(fact.CreateAddEquivalenceClassEdit(elem, equivalenceClass));
            elem.AddEquivalenceClass(equivalenceClass);
            ce.AddEdit(fact.CreateAddEffectEdit(equivalenceClass, effect));
            equivalenceClass.AddEffect(effect);
            Assert.IsFalse(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
            //finalize all edits so it can be undoed
            ce.EndAllEdits();
            Assert.IsTrue(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
            ce.Undo();
            Assert.IsFalse(equivalenceClass.Effects.Contains(effect));
            Assert.IsFalse(elem.EquivalenceClasses.Contains(equivalenceClass));
            ce.Redo();
            Assert.IsTrue(equivalenceClass.Effects.Contains(effect));
            Assert.IsTrue(elem.EquivalenceClasses.Contains(equivalenceClass));

            ce.Die();
            Assert.IsFalse(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
        }
Beispiel #6
0
        private IUndoableEdit MergeEffects(IList <Combination> combinationsToMerge)
        {
            CompoundEdit ce = new CompoundEdit();

            foreach (Combination combi in combinationsToMerge)
            {
                foreach (Effect effect in combi.Effects)
                {
                    if (!combination.Effects.Contains(effect))
                    {
                        ce.AddEdit(EditFactory.instance.CreateAddEffectEdit(combination, effect));
                        combination.AddEffect(effect);
                    }
                }
            }
            foreach (Combination combi in combinationsToMerge)
            {
                foreach (Effect effect in combi.Effects)
                {
                    if (!combi.Effects.Contains(effect))
                    {
                        ce.AddEdit(EditFactory.instance.CreateAddEffectEdit(combi, effect));
                        combi.AddEffect(effect);
                    }
                    //update risk level
                    RiskLevelManager rlm = new RiskLevelManager(effect);
                    ce.AddEdit(rlm.ApplyRiskLevelToChildren());
                    //update state
                    StateObjectManager som = new StateObjectManager(effect);
                    ce.AddEdit(som.ApplyStateToChildren());
                }
            }
            return(ce);
        }
Beispiel #7
0
        public void GenerateUpdateDeleteEquivalence()
        {
            CompoundEdit ce = new CompoundEdit();

            IGenerator gen = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());
            //deleting an equivalence
            IGenerator genUpdater = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.UPDATE);

            ce.AddEdit(EditFactory.instance.CreateRemoveEquivalenceClassEdit(dep, eq12));
            dep.RemoveEquivalenceClass(eq12);
            ce.AddEdit(genUpdater.Generate());
            Assert.AreEqual(18, dep.Combinations.Count);

            Assert.AreEqual(10, dep.Combinations[9].Position);
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq13));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq31));
            //add a new equivalence
            ce.AddEdit(EditFactory.instance.CreateRemoveEquivalenceClassEdit(dep, eq24));
            dep.AddEquivalenceClass(eq24);
            ce.AddEdit(genUpdater.Generate());
            Assert.AreEqual(24, dep.Combinations.Count);
            Assert.AreEqual(10, dep.Combinations[9].Position);
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq24));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq31));
            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
        protected override IUndoableEdit FillTestCases(IList <TestCase> testCases)
        {
            CompoundEdit ce = new CompoundEdit();

            ce.AddEdit(FillTestCasesFromNegativeEquivalenceClasses(testCases));
            ce.AddEdit(FillTestCasesFromNegativeCombinations(testCases));
            return(ce);
        }
Beispiel #9
0
        public IUndoableEdit UnMergeCombinations(EquivalenceClass selectedEquivalenceClass)
        {
            if (combination.Origin != CombinationOrigin.PERMUTATION)
            {
                throw new InvalidOperationException("The Unmerge is available only for combinations generated by permutation");
            }

            if (!combination.GetChildrenCombinationEquivalenceClasses().Contains(selectedEquivalenceClass))
            {
                throw new ArgumentException("The combination does not contain any child combination containing this equivalence class");
            }
            if (combination.EquivalenceClasses.Contains(selectedEquivalenceClass))
            {
                throw new ArgumentException("The combination contains this equivalence class and cannot be separated");
            }

            CompoundEdit ce = new CompoundEdit();
            //1-get all the combinations involved
            ISet <Combination> allCombinations = new HashedSet <Combination>(combination.Combinations);

            allCombinations.Add(combination);
            //2-get all the combinations involved that directly contains the equivalence class
            ISet <Combination> eqCombinations = new HashedSet <Combination>();

            foreach (Combination eqCombination in allCombinations)
            {
                if (eqCombination.EquivalenceClasses.Contains(selectedEquivalenceClass))
                {
                    eqCombinations.Add(eqCombination);
                }
            }
            //3 remove any hierarchy
            foreach (Combination allCombination in allCombinations)
            {
                if (allCombination.ParentCombination != null)
                {
                    ce.AddEdit(
                        EditFactory.instance.CreateRemoveCombinationEdit(allCombination.ParentCombination,
                                                                         allCombination));
                    allCombination.ParentCombination.RemoveCombination(allCombination);
                }
            }
            //4 - merge the combinations that don't contain the equivalence class using the original root combination
            if (allCombinations.Minus(eqCombinations).Count > 0)
            {
                ce.AddEdit(MergeCombinations(new List <Combination>(allCombinations.Minus(eqCombinations))));
            }
            //5- merge the combinations that contains the equivalence class using the first combination in the set
            if (eqCombinations.Count > 1)
            {
                CombinationManager cm = new CombinationManager(FindRootCombination(eqCombinations));
                ce.AddEdit(cm.MergeCombinations(new List <Combination>(eqCombinations)));
            }


            return(ce);
        }
        public override IUndoableEdit Generate()
        {
            CompoundEdit ce = new CompoundEdit();
            AbstractTestCaseGenerator gen = new PositiveTestCasesGenerator(dependencies, structure, maxTestCases);

            ce.AddEdit(gen.Generate());
            gen = new NegativeTestCasesGenerator(dependencies, structure, maxTestCases);
            ce.AddEdit(gen.Generate());
            gen = new FaultyTestCasesGenerator(dependencies, structure, maxTestCases);
            ce.AddEdit(gen.Generate());
            return(ce);
        }
        private static IUndoableEdit PropagateStateChangeInCombination(Combination target, EquivalenceClass parentEquivalenceClass)
        {
            CompoundEdit ce = new CompoundEdit();

            if (target.ParentDependency != null)
            {
                ce.AddEdit(EditFactory.instance.CreateRemoveEquivalenceClassEdit(target.ParentDependency, parentEquivalenceClass));
                target.ParentDependency.RemoveEquivalenceClass(parentEquivalenceClass);
                CombinationManager cman = new CombinationManager(target);
                ce.AddEdit(cman.DeleteCombination(target.ParentDependency.ParentStructure));
            }

            return(ce);
        }
        public void GenerateOverwrite()
        {
            CompoundEdit           ce  = new CompoundEdit();
            ICombinationsGenerator gen = new AllPairsCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());

            Assert.AreEqual(10, dep.Combinations.Count);
            Assert.AreEqual(1, dep.Combinations[0].Position);
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq31));

            Assert.AreEqual(2, dep.Combinations[1].Position);
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq22));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq32));

            //Assert.AreEqual(3, dep.Combinations[2].Position);
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq11));
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq23));
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq33));

            //Assert.AreEqual(7, dep.Combinations[6].Position);
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq12));
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq22));
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq33));

            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
Beispiel #13
0
        public void FindMergeableCombinationsTest()
        {
            //generate combinations
            CompoundEdit ce   = new CompoundEdit();
            Dependency   dep2 = new Dependency(structure);

            foreach (Element element in structure.Elements)
            {
                dep2.AddElement(element);
                foreach (EquivalenceClass equivalenceClass in element.EquivalenceClasses)
                {
                    dep2.AddEquivalenceClass(equivalenceClass);
                }
            }
            IGenerator gen = new PermutationCombinationsGenerator(dep2, 80000, CombinationsGenerationOption.OVERWRITE);

            //this generates 27 combinations
            ce.AddEdit(gen.Generate());
            //select the combination 02
            Assert.AreEqual(dep2.Combinations[1].Position, 2);
            CombinationManager  cm     = new CombinationManager(dep2.Combinations[1]);
            IList <Combination> combis = cm.FindMergeableCombinations(eq33);

            Assert.AreEqual(1, combis.Count);
            Assert.IsTrue(combis.Contains(dep2.Combinations[2]));
            CombinationManager cm1 = new CombinationManager(dep2.Combinations[0]);

            combis = cm1.FindMergeableCombinations(eq23);
            Assert.AreEqual(1, combis.Count);
            Assert.IsTrue(combis.Contains(dep2.Combinations[6]));
        }
        protected IUndoableEdit RemoveInvalidCombinations(IEnumerable <IList <EquivalenceClass> > patterns)
        {
            CompoundEdit   ce   = new CompoundEdit();
            IPolicyFactory fact = new PolicyFactory();
            //patterns.Equals()
            List <Combination> combinations = new List <Combination>(parentDependency.Combinations);

            foreach (IList <EquivalenceClass> list in patterns)
            {
                HashedSet <EquivalenceClass> eqSet = new HashedSet <EquivalenceClass>(list);
                foreach (Combination combination in parentDependency.Combinations)
                {
                    HashedSet <EquivalenceClass> combiEqSet = new HashedSet <EquivalenceClass>(combination.EquivalenceClasses);
                    if (eqSet.Equals(combiEqSet))
                    {
                        combinations.Remove(combination);
                    }
                }
            }
            foreach (Combination combination in combinations)
            {
                ce.AddEdit(fact.DeleteCombinationPolicy(combination, parentDependency.ParentStructure));
                parentDependency.RemoveCombination(combination);
            }

            return(ce);
        }
Beispiel #15
0
        public void GenerateOverwrite()
        {
            CompoundEdit ce  = new CompoundEdit();
            IGenerator   gen = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());

            Assert.AreEqual(27, dep.Combinations.Count);
            Assert.AreEqual(1, dep.Combinations[0].Position);
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq31));

            Assert.AreEqual(2, dep.Combinations[1].Position);
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq32));

            Assert.AreEqual(19, dep.Combinations[18].Position);
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq13));
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq31));

            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
        public IUndoableEdit DeleteCommonTestCases(State state, IList <Dependency> deps)
        {
            if (structure == null)
            {
                throw new NullReferenceException("The structure cannot be null");
            }
            CompoundEdit     ce = new CompoundEdit();
            IList <TestCase> deletedTestCases = new List <TestCase>();

            foreach (TestCase testCase in structure.TestCases)
            {
                if (testCase.CurrentState == state)
                {
                    if (hasCommonDependency(testCase, deps))
                    {
                        deletedTestCases.Add(testCase);
                    }
                }
            }
            foreach (TestCase tc in deletedTestCases)
            {
                ce.AddEdit(EditFactory.instance.CreateRemoveTestCaseEdit(structure, tc));
                structure.RemoveTestCase(tc);
            }
            return(ce);
        }
Beispiel #17
0
        public IUndoableEdit MergeCombinations(IList <Combination> combinationsToMerge)
        {
            if (combinationsToMerge.Count < 1)
            {
                throw new ArgumentException("The list of combinations to merge is empty");
            }
            if (combination.Origin != CombinationOrigin.PERMUTATION)
            {
                throw new InvalidOperationException("The merge is available only for combinations generated by permutation");
            }

            CompoundEdit ce = new CompoundEdit();

            //first merge the effects
            ce.AddEdit(MergeEffects(combinationsToMerge));
            foreach (Combination combi in combinationsToMerge)
            {
                if (!combination.Combinations.Contains(combi) && combination != combi)
                {
                    ce.AddEdit(EditFactory.instance.CreateAddCombinationEdit(combination, combi));
                    combination.AddCombination(combi);
                }
            }
            //remove all test cases referenced by the merged combinations (invalid testcases now)
            if (combination.ParentDependency != null && combination.ParentDependency.ParentStructure != null)
            {
                ISet <Combination> combinationsMerged = new HashedSet <Combination>(combinationsToMerge);
                IList <TestCase>   deletedTCs         = new List <TestCase>();
                foreach (TestCase testCase in combination.ParentDependency.ParentStructure.TestCases)
                {
                    ISet <Combination> tcCombinations = new HashedSet <Combination>(testCase.Combinations);
                    if (tcCombinations.Intersect(combinationsMerged).Count > 0)
                    {
                        //delete the referenced test case
                        deletedTCs.Add(testCase);
                    }
                }
                foreach (TestCase tc in deletedTCs)
                {
                    ce.AddEdit(
                        EditFactory.instance.CreateRemoveTestCaseEdit(combination.ParentDependency.ParentStructure, tc));
                    combination.ParentDependency.ParentStructure.RemoveTestCase(tc);
                }
            }

            return(ce);
        }
Beispiel #18
0
        public void UnMergeCombinationsTest()
        {
            //generate a 3 x 3 permutation
            CompoundEdit ce   = new CompoundEdit();
            Dependency   dep2 = new Dependency(structure);

            foreach (Element element in structure.Elements)
            {
                if (element.Position == 3)
                {
                    continue;
                }
                dep2.AddElement(element);
                foreach (EquivalenceClass equivalenceClass in element.EquivalenceClasses)
                {
                    dep2.AddEquivalenceClass(equivalenceClass);
                }
            }

            IGenerator gen = new PermutationCombinationsGenerator(dep2, 80000, CombinationsGenerationOption.OVERWRITE);

            //this generates 10 combinations
            ce.AddEdit(gen.Generate());
            //select the combination 02
            Assert.AreEqual(dep2.Combinations.Count, 9);

            CombinationManager cm = new CombinationManager(dep2.Combinations[0]);

            IList <Combination> combis = cm.FindMergeableCombinations(eq12);

            cm.MergeCombinations(combis);
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[3]));
            combis = cm.FindMergeableCombinations(eq13);
            cm.MergeCombinations(combis);
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[6]));
            combis = cm.FindMergeableCombinations(eq22);
            cm.MergeCombinations(combis);
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[4]));
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[7]));
            Assert.IsFalse(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[8]));
            combis = cm.FindMergeableCombinations(eq23);
            cm.MergeCombinations(combis);
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[2]));
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[5]));
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[8]));

            //now the unmerge
            cm.UnMergeCombinations(eq22);
            Assert.IsFalse(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[1]));
            Assert.IsTrue(dep2.Combinations[1].Combinations.Contains(dep2.Combinations[4]));
            Assert.IsTrue(dep2.Combinations[1].Combinations.Contains(dep2.Combinations[7]));
            Assert.IsTrue(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[3]));
            //this thows an arg exception
            cm.UnMergeCombinations(eq11);
            cm.UnMergeCombinations(eq13);
            Assert.IsFalse(dep2.Combinations[0].Combinations.Contains(dep2.Combinations[8]));
            Assert.IsTrue(dep2.Combinations[8].Combinations.Contains(dep2.Combinations[5]));
        }
        protected override IUndoableEdit FillTestCases(IList <TestCase> testCases)
        {
            CompoundEdit ce = new CompoundEdit();

            //for each combination in the dependency a test case must be created in the same order of the combination
            foreach (Dependency dependency in  dependencies)
            {
                foreach (Combination combination in dependency.GetCombinations(genState))
                {
                    TestCase testCase = new TestCase();

                    ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(testCase, "Origin", TestCaseOrigin.GENERATED));
                    testCase.Origin = TestCaseOrigin.GENERATED;
                    testCases.Add(testCase);
                    ce.AddEdit(PolicyFactory.instance.AddCombinationToTestCasePolicy(testCase, combination));
                }
            }
            return(ce);
        }
Beispiel #20
0
        public IUndoableEdit AddEquivalenceClass(EquivalenceClass equivalenceClass)
        {
            if (testCase == null)
            {
                throw new Exception("The test case cannot be null");
            }
            CompoundEdit ce = new CompoundEdit();

            ce.AddEdit(EditFactory.instance.CreateAddEquivalenceClassEdit(testCase, equivalenceClass));
            testCase.AddEquivalenceClass(equivalenceClass);
            RiskLevelManager rlc = new RiskLevelManager(equivalenceClass);

            ce.AddEdit(rlc.ApplyRiskLevelToChildren());
            StateObjectManager som = new StateObjectManager(equivalenceClass);

            ce.AddEdit(som.ApplyStateToChildren());


            return(ce);
        }
        public IUndoableEdit ChangeState(State newState)
        {
            CompoundEdit ce = new CompoundEdit();

            if ((stateObject == null))
            {
                return(ce);
            }
            //check if the new state can apply to the statebean

            if (stateObject.GetParentObjectStates() != null)
            {
                foreach (IStateObject parentStateObject in stateObject.GetParentObjectStates())
                {
                    if (CompareState(parentStateObject.CurrentState, newState) < 0)
                    {
                        throw new Exception("The state cannot change, contains a greater state as a parent");
                    }
                }
            }
            if (stateObject.GetChildrenObjectStates() == null)
            {
                return(ce);
            }
            foreach (IStateObject o in stateObject.GetChildrenObjectStates())
            {
                if (o is Combination && stateObject is EquivalenceClass && newState != State.POSITIVE)
                {
                    ce.AddEdit(PropagateStateChangeInCombination((Combination)o, (EquivalenceClass)stateObject));
                }
                else
                {
                    StateObjectManager rlc = new StateObjectManager(o);
                    ce.AddEdit(rlc.ChangeState(newState));
                }
            }
            ce.AddEdit(EditFactory.instance.CreateChangeStateEdit(stateObject, newState));
            stateObject.CurrentState = newState;

            return(ce);
        }
Beispiel #22
0
        public IUndoableEdit DeleteAllCombinations()
        {
            CompoundEdit       ce     = new CompoundEdit();
            List <Combination> combis = new List <Combination>(dependency.Combinations);

            foreach (Combination combination in combis)
            {
                CombinationManager man = new CombinationManager(combination);
                ce.AddEdit(man.DeleteCombination(dependency.ParentStructure));
            }
            return(ce);
        }
        protected IUndoableEdit FillTestCasesFromNegativeEquivalenceClasses(ICollection <TestCase> testCases)
        {
            CompoundEdit ce = new CompoundEdit();

            foreach (Element element in structure.Elements)
            {
                foreach (EquivalenceClass equivalenceClass in element.EquivalenceClasses)
                {
                    if (equivalenceClass.CurrentState == State.NEGATIVE)
                    {
                        TestCase testCase = new TestCase();
                        ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(testCase, "Origin", TestCaseOrigin.GENERATED));
                        testCase.Origin = TestCaseOrigin.GENERATED;
                        ce.AddEdit(PolicyFactory.instance.AddEquivalenceClassToTestCase(equivalenceClass, testCase));
                        testCases.Add(testCase);
                    }
                }
            }

            return(ce);
        }
        public void Generate()
        {
            List <Dependency> deps = new List <Dependency>();

            eq22.CurrentState   = State.FAULTY;
            combi2.CurrentState = State.FAULTY;
            CompoundEdit ce = new CompoundEdit();

            deps.Add(dep);
            FaultyTestCasesGenerator generator = new FaultyTestCasesGenerator(deps, structure, 10000);

            ce.AddEdit(generator.Generate());
            Assert.IsTrue(structure.TestCases.Count == 2);
            Assert.IsTrue(structure.TestCases[0].EquivalenceClasses.Contains(eq22));
            Assert.IsTrue(structure.TestCases[1].Combinations.Contains(combi2));
            //TODO add more complex tests here
        }
        public void Generate()
        {
            List <Dependency> deps = new List <Dependency>();
            CompoundEdit      ce   = new CompoundEdit();

            deps.Add(dep);
            PositiveTestCasesGenerator generator = new PositiveTestCasesGenerator(deps, structure, 10000);

            ce.AddEdit(generator.Generate());
            Assert.IsTrue(structure.TestCases.Count == 5);
            Assert.IsTrue(structure.TestCases[0].Combinations.Contains(combi1));
            Assert.IsTrue(structure.TestCases[1].Combinations.Contains(combi2));
            Assert.IsTrue(structure.TestCases[2].Combinations.Contains(combi3));
            Assert.IsTrue(structure.TestCases[3].Combinations.Contains(combi4));
            Assert.IsTrue(structure.TestCases[4].Combinations.Contains(combi5));
            //TODO add more complex tests here
        }
        public IUndoableEdit ApplyStateToChildren()
        {
            if (stateObject == null)
            {
                return(null);
            }
            CompoundEdit ce = new CompoundEdit();

            if (stateObject.GetChildrenObjectStates() == null)
            {
                return(ce);
            }
            foreach (IStateObject o in stateObject.GetChildrenObjectStates())
            {
                StateObjectManager rlc = new StateObjectManager(o);
                ce.AddEdit(rlc.ChangeState(stateObject.CurrentState));
            }
            return(ce);
        }
        protected IUndoableEdit CreateCombinationsFromPatterns(IList <IList <EquivalenceClass> > patterns, CombinationOrigin origin)
        {
            //order the patterns based on equivalenceclasses
            ((List <IList <EquivalenceClass> >)patterns).Sort(new PatternComparer());
            ////create a combination for each pattern in the patterns
            CompoundEdit   ce    = new CompoundEdit();
            IPolicyFactory pfact = new PolicyFactory();

            ////delete all combinations from the dependency
            if (generationOption == CombinationsGenerationOption.OVERWRITE)
            {
                ce.AddEdit(pfact.DeleteAllCombinationsPolicy(parentDependency));
            }
            else
            {
                ce.AddEdit(RemoveInvalidCombinations(patterns));
                RemoveRepeatedPatterns(patterns);
            }
            ////create the combinations from the pattern and remove the invalid ones
            foreach (IList <EquivalenceClass> list in patterns)
            {
                Combination comb = new Combination();
                ce.AddEdit(EditFactory.instance.CreateAddCombinationEdit(parentDependency, comb));
                parentDependency.AddCombination(comb);

                ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(comb, "Origin", origin));
                comb.Origin = origin;
                foreach (EquivalenceClass equivalenceClass in list)
                {
                    ce.AddEdit(EditFactory.instance.CreateAddEquivalenceClassEdit(comb, equivalenceClass));
                    comb.AddEquivalenceClass(equivalenceClass);
                }
            }
            ////put the positions
            int i = 1;

            foreach (Combination combination in parentDependency.Combinations)
            {
                if (combination.Position != i)
                {
                    ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(combination, "Position", i));
                    combination.Position = i;
                }
                i++;
            }

            return(ce);
        }
        public IUndoableEdit ApplyRiskLevelToChildren()
        {
            if (riskLevelObject == null)
            {
                return(null);
            }
            CompoundEdit ce = new CompoundEdit();

            if (riskLevelObject.GetChildrenRiskLevels() == null)
            {
                return(ce);
            }
            foreach (IRiskLevelObject o in riskLevelObject.GetChildrenRiskLevels())
            {
                if (o.RiskLevel < riskLevelObject.RiskLevel)
                {
                    RiskLevelManager rlc = new RiskLevelManager(o);
                    ce.AddEdit(rlc.ChangeRiskLevel(riskLevelObject.RiskLevel));
                }
            }
            return(ce);
        }
Beispiel #29
0
        protected override IUndoableEdit FillTestCases(IList <TestCase> testCases)
        {
            CompoundEdit        ce                   = new CompoundEdit();
            TestCase            testCase             = null;
            IList <Combination> rejectedCombinations = new List <Combination>();
            int maxNumOfPositiveCombinations         = 0;

            //check wich dependency has the maximal number of positive combniations
            foreach (Dependency dependency in dependencies)
            {
                int numOfPositiveCombinations = dependency.GetCombinations(State.POSITIVE).Count;
                if (numOfPositiveCombinations > maxNumOfPositiveCombinations)
                {
                    maxNumOfPositiveCombinations = numOfPositiveCombinations;
                }
            }
            //create a test case for each of this maximal number
            for (int i = 0; i < maxNumOfPositiveCombinations; i++)
            {
                //create the test case with his attributes
                testCase = new TestCase();
                ce.AddEdit(EditFactory.instance.CreateChangeStateEdit(testCase, State.POSITIVE));
                testCase.CurrentState = State.POSITIVE;
                ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(testCase, "Origin", TestCaseOrigin.GENERATED));
                testCase.Origin = TestCaseOrigin.GENERATED;
                testCases.Add(testCase);
                //if( !existsTestCaseWithTheSameValues(testCase, generatedTestCases, p_Structure.getLnkElements())) {

                //}
                foreach (Dependency dependency in dependencies)
                {
                    Combination        combination = dependency.GetCombinationAt(i, State.POSITIVE);
                    CombinationManager cm          = new CombinationManager(combination);
                    if (combination != null)
                    {
                        if (cm.CanBeAssignedToTestCase(testCase))
                        {
                            ce.AddEdit(PolicyFactory.instance.AddCombinationToTestCasePolicy(testCase, combination));
                        }
                        else
                        {
                            rejectedCombinations.Add(combination);
                        }
                    }
                }
            }
            List <Combination> usedRejectedCombinations = new List <Combination>();
            TestCase           testCaseOfRejectedCombinations;

            foreach (Combination rejectedCombination in rejectedCombinations)
            {
                bool combinationIsAssignedToATestCase = false;
                foreach (TestCase tc in testCases)
                {
                    if (!usedRejectedCombinations.Contains(rejectedCombination))
                    {
                        CombinationManager cm = new CombinationManager(rejectedCombination);
                        if (cm.CanBeAssignedToTestCase(tc))
                        {
                            ce.AddEdit(PolicyFactory.instance.AddCombinationToTestCasePolicy(tc, rejectedCombination));
                            combinationIsAssignedToATestCase = true;
                            usedRejectedCombinations.Add(rejectedCombination);
                        }
                    }
                }
                if (!combinationIsAssignedToATestCase)
                {
                    if (!usedRejectedCombinations.Contains(rejectedCombination))
                    {
                        testCaseOfRejectedCombinations = new TestCase();
                        ce.AddEdit(EditFactory.instance.CreateChangeStateEdit(testCaseOfRejectedCombinations, State.POSITIVE));
                        testCaseOfRejectedCombinations.CurrentState = State.POSITIVE;
                        ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(testCaseOfRejectedCombinations, "Origin", TestCaseOrigin.GENERATED));
                        testCaseOfRejectedCombinations.Origin = TestCaseOrigin.GENERATED;
                        testCases.Add(testCaseOfRejectedCombinations);
                        ce.AddEdit(PolicyFactory.instance.AddCombinationToTestCasePolicy(testCaseOfRejectedCombinations, rejectedCombination));
                        usedRejectedCombinations.Add(rejectedCombination);
                    }
                }
            }
            return(ce);
        }
        public void BasicFunctionalityLimit()
        {
            //only 3 edits permited
            queue.Limit = 3;
            CompoundEdit ce   = new CompoundEdit();
            IEditFactory fact = EditFactory.instance;
            Element      elem = new Element();

            EquivalenceClass equivalenceClass = new EquivalenceClass();
            Effect           effect           = new Effect();

            ce.AddEdit(fact.CreateAddEquivalenceClassEdit(elem, equivalenceClass));
            elem.AddEquivalenceClass(equivalenceClass);
            ce.AddEdit(fact.CreateAddEffectEdit(equivalenceClass, effect));
            equivalenceClass.AddEffect(effect);
            //a compound edit
            queue.AddEdit(ce);
            //a simple edit
            queue.AddEdit(fact.CreateChangePropertyEdit(effect, "Description", "Test Description"));
            effect.Description = "Test Description";
            //another edit
            queue.AddEdit(fact.CreateRemoveEquivalenceClassEdit(elem, equivalenceClass));
            elem.RemoveEquivalenceClass(equivalenceClass);
            //the final edit
            queue.AddEdit(fact.CreateRemoveEffectEdit(equivalenceClass, effect));
            equivalenceClass.RemoveEffect(effect);
            Assert.IsTrue(queue.CanUndo());
            Assert.IsFalse(queue.CanRedo());

            queue.Undo();
            Assert.IsTrue(equivalenceClass.Effects.Contains(effect));
            Assert.IsFalse(elem.EquivalenceClasses.Contains(equivalenceClass));
            Assert.IsTrue(queue.CanUndo());
            Assert.IsTrue(queue.CanRedo());

            queue.Undo();
            Assert.IsTrue(equivalenceClass.Effects.Contains(effect));
            Assert.IsTrue(elem.EquivalenceClasses.Contains(equivalenceClass));
            Assert.IsTrue(effect.Description.Equals("Test Description"));
            Assert.IsTrue(queue.CanUndo());
            Assert.IsTrue(queue.CanRedo());

            queue.Undo();
            Assert.IsTrue(equivalenceClass.Effects.Contains(effect));
            Assert.IsTrue(elem.EquivalenceClasses.Contains(equivalenceClass));
            Assert.IsTrue(effect.Description == null);
            //the firts edit now cannot be undoed
            Assert.IsFalse(queue.CanUndo());
            Assert.IsTrue(queue.CanRedo());



            queue.Redo();
            queue.Redo();
            queue.Redo();

            Assert.IsTrue(queue.CanUndo());
            Assert.IsFalse(queue.CanRedo());
            Assert.IsTrue(effect.Description.Equals("Test Description"));
            Assert.IsFalse(equivalenceClass.Effects.Contains(effect));
        }