Example #1
0
        public void CreateXWingActionsHardTest()
        {
            // Setup
            Keys <int> row1 = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Keys <int> col1 = new Keys <int>()
            {
                1, 10, 19, 28, 37, 46, 55, 64, 73
            };
            Keys <int> col3 = new Keys <int>()
            {
                3, 12, 21, 30, 39, 48, 57, 66, 75
            };
            Keys <int> col9 = new Keys <int>()
            {
                9, 18, 27, 36, 45, 54, 63, 72, 81
            };
            Keys <int> row3 = new Keys <int>()
            {
                19, 20, 21, 22, 23, 24, 25, 26, 27
            };
            Keys <int> row4 = new Keys <int>()
            {
                28, 29, 30, 31, 32, 33, 34, 35, 36
            };
            Keys <int> grid1 = 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
                });
            }
            Keys <int> reducedSet1 = new Keys <int>()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };

            foreach (int k in reducedSet1)
            {
                space[k].Values.Remove(2);
            }
            Keys <int> reducedSet2 = new Keys <int>()
            {
                2, 10, 11, 12, 19, 20
            };

            foreach (int k in reducedSet2)
            {
                space[k].Values.Remove(2);
            }

            ConstraintMutuallyExclusive <int> cGrid1 = new ConstraintMutuallyExclusive <int>("grid1", grid1);
            ConstraintTester <int>            cCol1  = new ConstraintTester <int>("col1", col1);
            ConstraintMutuallyExclusive <int> cCol3  = new ConstraintMutuallyExclusive <int>("col3", col3);
            ConstraintMutuallyExclusive <int> cCol9  = new ConstraintMutuallyExclusive <int>("col9", col9);
            ConstraintTester <int>            cRow1  = new ConstraintTester <int>("row1", row1);
            ConstraintTester <int>            cRow3  = new ConstraintTester <int>("row3", row3);

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

            puzzle.Constraints.Add(cGrid1);
            puzzle.Constraints.Add(cCol1);
            puzzle.Constraints.Add(cCol3);
            puzzle.Constraints.Add(cCol9);
            puzzle.Constraints.Add(cRow1);
            puzzle.Constraints.Add(cRow3);

            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            //SpaceAdapter<int>.ToFile(puzzle.Space.ToString(),0);
            // Action
            cRow1.CreateActions3(reducedSet1, engine);
            //SpaceAdapter<int>.ToFile(puzzle.Space.ToString(),1);
            Assert.AreEqual(0, engine.Count, "Two X wing sets not found");
        }
Example #2
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));
        }