예제 #1
0
파일: UnitTest1.cs 프로젝트: curtca/AoC2020
        public void Test(string input, long expected)
        {
            Conway c      = new Conway(input);
            long   cycles = c.RunCycles(6);

            Assert.Equal(expected, cycles);
        }
예제 #2
0
        public void First_state_is_initial_state(int[][] initialState)
        {
            var state = ToBoolArray(initialState);

            Assert.That(Conway.States(state).First(),
                        Is.EqualTo(state));
        }
        public void GetBlinkerDataTest_OneChange()
        {
            //Given
            Conway conway = new Conway(new FakeDisplay());
            var    result = conway.GetBlinkerData();

            //When

            conway.DrawNextGeneration(result, 5, 5);

            var cell1 = result.Where(w => w.X == 1 && w.Y == 2).First();
            var cell2 = result.Where(w => w.X == 2 && w.Y == 2).First();
            var cell3 = result.Where(w => w.X == 3 && w.Y == 2).First();


            //Then
            Assert.AreEqual(25, result.Count);
            Assert.AreEqual(1, cell1.CurrentState);
            Assert.AreEqual(1, cell1.PreviousState);

            Assert.AreEqual(1, cell2.CurrentState);
            Assert.AreEqual(1, cell2.PreviousState);

            Assert.AreEqual(1, cell3.CurrentState);
            Assert.AreEqual(1, cell3.PreviousState);
        }
예제 #4
0
        public void Next_state_is_generated_correctly(int[][] initialState,
                                                      int[][] nextState)
        {
            var state1 = ToBoolArray(initialState);

            var state2 = ToBoolArray(nextState);

            Assert.That(Conway.States(state1).Skip(1).First(),
                        Is.EqualTo(state2));
        }
예제 #5
0
        public void CellsWithMoreThanThreeLiveNeighbors()
        {
            // Any live cell with more than three live neighbours dies
            StateOfCell CurrentCellState   = StateOfCell.Alive;
            int         NumOfLiveNeighbors = 4;

            StateOfCell output = Conway.GetNewCellState(CurrentCellState, NumOfLiveNeighbors);

            Assert.AreEqual(StateOfCell.Dead, output);
        }
예제 #6
0
        public void CellsWithTwoOrThreeliveNeighbors()
        {
            // Any live cell with two or three live neighbours lives
            StateOfCell CurrentCellState   = StateOfCell.Alive;
            int         NumOfLiveNeighbors = 3;

            StateOfCell output = Conway.GetNewCellState(CurrentCellState, NumOfLiveNeighbors);

            Assert.AreEqual(StateOfCell.Alive, output);
        }
예제 #7
0
        public void CellsWithLessThanTwoLiveNeighb()
        {
            // Any live cell with fewer than two live neighbours dies
            StateOfCell CurrentCellState   = StateOfCell.Alive;
            int         NumOfLiveNeighbors = 1;

            StateOfCell output = Conway.GetNewCellState(CurrentCellState, NumOfLiveNeighbors);

            Assert.AreEqual(StateOfCell.Dead, output);
        }
        public void BuildRandomBoardSizeTest_0Column_1Row()
        {
            //Given
            Conway conway = new Conway(new FakeDisplay());

            //When
            var result = conway.BuildRandomBoard(1, 0);

            //Then
            Assert.AreEqual(0, result.Count);
        }
        public void BuildRandomBoardSizeTest_24()
        {
            //Given
            Conway conway = new Conway(new FakeDisplay());

            //When
            var result = conway.BuildRandomBoard(4, 6);

            //Then
            Assert.AreEqual(24, result.Count);
        }
예제 #10
0
        public void DeadCellsWithExaltyThreeLiveNeighbors()
        {
            // Any dead cell with exactly three live neighbours becomes a live cell

            StateOfCell CurrentCellState   = StateOfCell.Dead;
            int         NumOfLiveNeighbors = 3;

            StateOfCell output = Conway.GetNewCellState(CurrentCellState, NumOfLiveNeighbors);

            Assert.AreEqual(StateOfCell.Alive, output);
        }
예제 #11
0
        public void Oscillating_blinker_example()
        {
            var horizontalState = ToBoolArray(new []
                                              { new [] { 0, 0, 0 },
                                                new [] { 1, 1, 1 },
                                                new [] { 0, 0, 0 } });

            var verticalState = ToBoolArray(new []
                                            { new [] { 0, 1, 0 },
                                              new [] { 0, 1, 0 },
                                              new [] { 0, 1, 0 } });

            var states = Conway.States(horizontalState);

            Assert.That(states.Take(3),
                        Is.EqualTo(new [] { horizontalState,
                                            verticalState,
                                            horizontalState }));
        }
예제 #12
0
 public void Cannot_call_with_null_arguments()
 {
     Assert.That(() => Conway.States(null).ToArray(),
                 Throws.TypeOf <ArgumentNullException>());
 }
예제 #13
0
 public void Next_state_is_generated_correctly(bool[][] initialState,
                                               bool[][] nextState)
 {
     Assert.That(Conway.NextState(initialState), Is.EqualTo(nextState));
 }
예제 #14
0
 void Awake()
 {
     Current = this;
     VisualTilesReady += OnVisualTilesReady;
     InitialStateReady += OnInitialStateReady;
     world = new World ( width, height );
     conway = new Conway ( world.Width, world.Height );
     Camera.main.transform.position = new Vector3 ( world.Width / 2, world.Height / 2, Camera.main.transform.position.z );
 }