コード例 #1
0
        //Any live cell with fewer than two live neighbours dies, as if caused by under population
        public void TestRule1()
        {
            //test with 0 live neighbors
            GeneticLife test = new GeneticLife(2);
            test.GetCell(0, 0).IsAlive = true;
            test.GetCell(0, 1).IsAlive = false;
            test.GetCell(1, 0).IsAlive = false;
            test.GetCell(1, 1).IsAlive = false;
            test.Iterate();

            Assert.IsFalse(test.GetCell(0, 0).IsAlive);
            Assert.IsFalse(test.GetCell(0, 1).IsAlive);
            Assert.IsFalse(test.GetCell(1, 0).IsAlive);
            Assert.IsFalse(test.GetCell(1, 1).IsAlive);


            //test with 1 live neighbors
            test = new GeneticLife(2);
            test.GetCell(0, 0).IsAlive = true;
            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(1, 0).IsAlive = false;
            test.GetCell(1, 1).IsAlive = false;
            test.Iterate();

            Assert.IsFalse(test.GetCell(0, 0).IsAlive);
            Assert.IsFalse(test.GetCell(0, 1).IsAlive);
            Assert.IsFalse(test.GetCell(1, 0).IsAlive);
            Assert.IsFalse(test.GetCell(1, 1).IsAlive);
        }
コード例 #2
0
        public void testRule2()
        {
            //test with 2 neighbors
            GeneticLife test = new GeneticLife(2);
            ColorCell testCell = test.GetCell(0, 0);
            testCell.IsAlive = true;
            testCell.red = Byte.MaxValue / 2;
            testCell.green = Byte.MaxValue / 2;
            testCell.blue = Byte.MaxValue / 2;
            
            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(0, 1).red = Byte.MaxValue;
            test.GetCell(1, 0).IsAlive = true;
            test.GetCell(1, 0).blue = Byte.MaxValue;
            test.GetCell(1, 1).IsAlive = false;
            test.Iterate();

            Assert.IsTrue(test.GetCell(0, 0).IsAlive);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.red);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.green);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.blue);

            //test with 3 neighbors
            test = new GeneticLife(2);
            testCell = test.GetCell(0, 0);
            testCell.IsAlive = true;
            testCell.red = Byte.MaxValue / 2;
            testCell.green = Byte.MaxValue / 2;
            testCell.blue = Byte.MaxValue / 2;

            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(0, 1).red = Byte.MaxValue;
            test.GetCell(1, 0).IsAlive = true;
            test.GetCell(1, 0).blue = Byte.MaxValue;
            test.GetCell(1, 1).IsAlive = true;
            test.Iterate();

            Assert.IsTrue(test.GetCell(0, 0).IsAlive);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.red);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.green);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.blue);



        }
コード例 #3
0
        public void testRule3()
        {
            //test with 4 neighbors
            GeneticLife test = new GeneticLife(3);
            test.GetCell(0, 0).IsAlive = false;
            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(0, 2).IsAlive = false;
            test.GetCell(1, 0).IsAlive = true;            
            test.GetCell(1, 1).IsAlive = true;
            test.GetCell(1, 2).IsAlive = true;
            test.GetCell(2, 0).IsAlive = false;
            test.GetCell(2, 1).IsAlive = true;
            test.GetCell(2, 2).IsAlive = false;
            test.Iterate();

            Assert.IsFalse(test.GetCell(1, 1).IsAlive);
        }
コード例 #4
0
        public void testRule4()
        {
            GeneticLife test = new GeneticLife(2);
            ColorCell testCell = test.GetCell(0, 0);
            testCell.IsAlive = false;
            test.GetCell(0, 1).IsAlive = true;
            initializeSimpleColors(test.GetCell(0, 1));
            test.GetCell(0, 1).IsAlive = true;
            initializeSimpleColors(test.GetCell(1, 0));
            test.GetCell(1, 0).IsAlive = true;
            initializeSimpleColors(test.GetCell(1, 1));
            test.GetCell(1, 1).IsAlive = true;
            test.Iterate();

            testCell = test.GetCell(0, 0);
            Assert.IsTrue(testCell.IsAlive);
            Assert.AreEqual(testCell.red, 1);
            Assert.AreEqual(testCell.green, 2);
            Assert.AreEqual(testCell.blue, 3);
        }