示例#1
0
        public void CreateActionTestWith2x2()
        {
            // Setup
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 10; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }
            Keys <int> group = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            ConstraintMutuallyExclusive <int> target = new ConstraintMutuallyExclusive <int>("row1", group);

            IPuzzle <int> puzzle = new PuzzleBase <int>(space);

            puzzle.Constraints.Add(target);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            space[8].SetValues(new Possible()
            {
                1, 2
            });
            space[9].SetValues(new Possible()
            {
                1, 2
            });
            Keys <int> keysChangedIn = new Keys <int>()
            {
                8, 9
            };

            target.CreateSearchJobs(keysChangedIn, engine);

            // Tests
            Possible expectedFilter = new Possible()
            {
                1, 2
            };
            Keys <int> expectedKeys = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7
            };

            Assert.AreEqual(1, engine.Count, "Incorrect Jobs added");
            IJobFilter <int> nextJob = engine.Peek() as IJobFilter <int>;

            Assert.IsTrue(nextJob.Keys.SetEquals(expectedKeys), "ConstraintME did not change the correct keys");
            Assert.IsTrue(nextJob.Filter.SetEquals(expectedFilter), "ConstraintME did not set the correct values");
        }
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Process
        ///</summary>
        public void ProcessIntersectionEliminateProcessTestHelper <TKey>()
        {
            Keys <int> group1In = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Keys <int> group2In = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 22; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }
            // remove 1 from part of row1
            for (int i = 4; i < 10; i++)
            {
                space[i].Values.Remove(1);
            }
            space[1].Values.Remove(5);
            space[2].Values.Remove(5);
            space[3].Values.Remove(5);
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteIntersectActions(group1In, group2In, engine);

            // Tests
            Assert.AreEqual(1, jobsAdded, "Incorrect filter job count");
            Keys <int> expected = new Keys <int>()
            {
                10, 11, 12, 19, 20, 21
            };
            IJobFilter <int> job = engine.Peek() as IJobFilter <int>;

            Assert.IsNotNull(job);
            Assert.AreEqual(6, job.Keys.Count, "Unexpected key change.");
            Assert.IsTrue(expected.SetEquals(job.Keys), "Unexpected Keys Changed. Should be 10,11,12,19,20,21");
            Possible expectedValues = new Possible()
            {
                1
            };

            Assert.IsTrue(expectedValues.SetEquals(job.Filter), "Unexpected values. Should have eliminated 1");
        }
示例#3
0
        public void RunAlgorithmTest()
        {
            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }

            // Initialise one group (top row)
            Keys <int> group = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            space[1].SetValue(1);
            Keys <int> keysInner = new Keys <int>()
            {
                1
            };
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteSetActions(keysInner, group, engine);


            // Test
            Keys <int> expectedK = new Keys <int>()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };
            Possible expectedV = new Possible()
            {
                1
            };
            IJobFilter <int> job    = engine.Peek() as IJobFilter <int>;
            Keys <int>       actual = job.Keys;
            IPossible        filter = job.Filter;

            // Check the algorithm returned 8 changes
            Assert.AreEqual(8, actual.Count(), "Algorithm Eliminate did not return 8 changes");
            Assert.IsTrue(expectedK.SetEquals(actual));
            Assert.AreEqual(1, filter.Count, "Filter value incorrect");
            Assert.IsTrue(expectedV.SetEquals(filter), "Filter values incorrect");
        }
示例#4
0
        public void CreateXWingActionsTest()
        {
            // Setup
            Keys <int> group1In = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Keys <int> group2In = new Keys <int>()
            {
                1, 10, 19, 28, 37, 46, 55, 64, 73
            };
            Keys <int> group3In = new Keys <int>()
            {
                9, 18, 27, 36, 45, 54, 63, 72, 81
            };
            Keys <int> group4In = new Keys <int>()
            {
                28, 29, 30, 31, 32, 33, 34, 35, 36
            };
            Keys <int> group5In = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }
            ConstraintTester <int>            target1 = new ConstraintTester <int>("row1", group1In);
            ConstraintMutuallyExclusive <int> target2 = new ConstraintMutuallyExclusive <int>("col1", group2In);
            ConstraintMutuallyExclusive <int> target3 = new ConstraintMutuallyExclusive <int>("col9", group3In);
            ConstraintMutuallyExclusive <int> target4 = new ConstraintMutuallyExclusive <int>("row4", group4In);
            ConstraintMutuallyExclusive <int> target5 = new ConstraintMutuallyExclusive <int>("grid1", group5In);
            IPuzzle <int> puzzle = new PuzzleBase <int>(space);

            puzzle.Constraints.Add(target1);
            puzzle.Constraints.Add(target2);
            puzzle.Constraints.Add(target3);
            puzzle.Constraints.Add(target4);
            puzzle.Constraints.Add(target5);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            Keys <int> keysChanged = new Keys <int>()
            {
                2, 3, 4, 5, 6, 7, 8, 29, 30, 31, 32, 33, 34, 35
            };

            foreach (int k in keysChanged)
            {
                space[k].Values.Remove(2);
            }
            target1.CreateActions3(keysChanged, engine);

            // Test
            Possible origValue = new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Possible expectedFilter = new Possible()
            {
                2
            };

            Assert.AreEqual(2, engine.Count, "Two X wing sets not found");
            IJobFilter <int> job1 = engine.ElementAt(0) as IJobFilter <int>;
            IJobFilter <int> job2 = engine.ElementAt(1) as IJobFilter <int>;
            //Keys<int> kExpected11 = new Keys<int>() {1, 28};
            //Keys<int> kExpected12 = new Keys<int>() {9, 36};
            Keys <int> kExpected21 = new Keys <int>()
            {
                10, 19, 37, 46, 55, 64, 73
            };
            Keys <int> kExpected22 = new Keys <int>()
            {
                18, 27, 45, 54, 63, 72, 81
            };
            Keys <int> kNotExpected2 = new Keys <int>()
            {
                11, 12, 20, 21
            };

            Assert.IsTrue(job1.Keys.SetEquals(kExpected21));
            Assert.IsTrue(job1.Filter.SetEquals(expectedFilter));
            Assert.IsTrue(job2.Keys.SetEquals(kExpected22));
            Assert.IsTrue(job2.Filter.SetEquals(expectedFilter));
        }
示例#5
0
        public void CreateActions2Test()
        {
            // Setup
            Keys <int> group1In = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Keys <int> group2In = new Keys <int>()
            {
                10, 11, 12, 13, 14, 15, 16, 17, 18
            };
            Keys <int> group3In = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 22; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }

            ConstraintTester <int>            target1 = new ConstraintTester <int>("row1", group1In);
            ConstraintMutuallyExclusive <int> target2 = new ConstraintMutuallyExclusive <int>("row2", group2In);
            ConstraintMutuallyExclusive <int> target3 = new ConstraintMutuallyExclusive <int>("grid1", group3In);

            IPuzzle <int> puzzle = new PuzzleBase <int>(space);

            puzzle.Constraints.Add(target1);
            puzzle.Constraints.Add(target2);
            puzzle.Constraints.Add(target3);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            Possible no3 = new Possible()
            {
                1, 2, 4, 5, 6, 7, 8, 9
            };
            Keys <int> keysOuter1 = new Keys <int>()
            {
                4, 5, 6, 7, 8, 9
            };

            foreach (int k in keysOuter1)
            {
                space[k].SetValues(no3);
            }
            target1.CreateActions2(keysOuter1, engine);

            // Tests
            Possible expectedFilter = new Possible()
            {
                3
            };
            Keys <int> expectedKeys = new Keys <int>()
            {
                10, 11, 12, 19, 20, 21
            };
            IJobFilter <int> nextJob = engine.Peek() as IJobFilter <int>;

            Assert.AreEqual(1, engine.Count, "Incorrect Jobs added");
            Assert.IsTrue(nextJob.Keys.SetEquals(expectedKeys), "ConstraintME did not change the correct keys");
            Assert.IsTrue(nextJob.Filter.SetEquals(expectedFilter), "ConstraintME did not set the correct values");
        }
示例#6
0
        public void RunAlgorithmEliminateTest1()
        {
            // Initialise Possible
            IPossible possibleAll = new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible(possibleAll));
            }

            // Initialise one group (top row)
            Keys <int> group = new Keys <int>();

            for (int i = 1; i < 10; i++)
            {
                group.Add(i);
            }
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            Possible values2To9 = new Possible(possibleAll);

            values2To9.Remove(1);
            Keys <int> keysInner = new Keys <int>();

            for (int j = 2; j < 10; j++)
            {
                keysInner.Add(j);
                space[j] = new Possible(values2To9);
            }
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteSetActions(keysInner, group, engine);

            Assert.AreEqual(1, engine.Count);

            // Test
            Keys <int> expectedK = new Keys <int>()
            {
                1
            };
            IPossible expectedV = new Possible()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };

            IJobFilter <int> job    = engine.Peek() as IJobFilter <int>;
            Keys <int>       actual = job.Keys;
            IPossible        filter = job.Filter;

            Assert.AreEqual(1, actual.Count(), "Algorithm Eliminate did not return 8 changes");
            Assert.IsTrue(expectedK.SetEquals(actual));
            Assert.AreEqual(8, filter.Count, "Filter value incorrect");
            Assert.IsTrue(expectedV.SetEquals(filter), "Filter values incorrect");
        }