예제 #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
        //
        //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 CreateSearchJobs
        ///</summary>
        public void ApplyConstraintsTestHelper <TKey>()
        {
            // 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
                });
            }

            IConstraints <int> constraints = new Constraints <int>();
            Keys <int>         group       = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            IConstraint <int> constraint = new ConstraintMutuallyExclusive <int>("row1", group);
            Keys <int>        group2     = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };

            IConstraint <int> constraint2 = new ConstraintMutuallyExclusive <int>("grid1", group2);

            constraints.Add(constraint);
            constraints.Add(constraint2);

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

            puzzle.Space       = space;
            puzzle.Constraints = constraints;
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

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

            init[1] = new Possible()
            {
                1
            };
            engine.SetInitialValues(init);
            Assert.AreEqual(1, engine.Count, "Constraint not added to queue");
            engine.DoNextJob();
            // this brings back keys 2 and 3 with constraint grid1? is
            Assert.AreEqual(2, engine.Count, "MutuallyExclusive constraint did not create jobs");
        }
예제 #4
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");
        }
예제 #5
0
    // Use this for initialization
    void Start()
    {
        Dialog = transform.Find("DialogBase").GetComponent<DialogManager>();
        Puzzle = transform.Find("PuzzleBase").GetComponent<PuzzleBase>();

        if (FadeInScene)
        {
            if (fadeImage == null)
                fadeImage = gameObject.AddComponent<Image>();

            fadeImage.color = Color.black;
            startFadingIn = true;
        }
    }
예제 #6
0
    // Use this for initialization
    void Start()
    {
        Dialog = transform.Find("DialogBase").GetComponent <DialogManager>();
        Puzzle = transform.Find("PuzzleBase").GetComponent <PuzzleBase>();

        if (FadeInScene)
        {
            if (fadeImage == null)
            {
                fadeImage = gameObject.AddComponent <Image>();
            }

            fadeImage.color = Color.black;
            startFadingIn   = true;
        }
    }
예제 #7
0
 public void StartPuzzle()
 {
     // Gets a random puzzle and starts it.
     currentPuzzle        = GetPuzzle();
     currentQuestionIndex = 0;
 }
예제 #8
0
 public void StartPuzzle(PuzzleBase puzzle)
 {
     // Gets a pre-selected puzzle and starts it.
     currentPuzzle        = puzzle;
     currentQuestionIndex = 0;
 }
예제 #9
0
    protected override void ActionStart()
    {
        puzzleMgr = GameObject.Find("UICanvas").GetComponent<UIManager>().Puzzle;

        puzzleMgr.LoadPuzzle(PuzzleName);
    }
예제 #10
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");
        }
예제 #11
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));
        }
예제 #12
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");
        }
예제 #13
0
    protected override void ActionStart()
    {
        puzzleMgr = GameObject.Find("UICanvas").GetComponent <UIManager>().Puzzle;

        puzzleMgr.LoadPuzzle(PuzzleName);
    }
예제 #14
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");
        }
예제 #15
0
 private void Awake()
 {
     instance = this;
 }