예제 #1
0
        public void TestStackOperations()
        {
            var backup = new Backup <BimaruGrid>();

            var grid = new BimaruGrid(1, 2);
            var p0   = new GridPoint(0, 0);
            var p1   = new GridPoint(0, 1);

            grid[p0] = BimaruValue.SHIP_SINGLE;
            grid[p1] = BimaruValue.WATER;

            backup.SetSavePoint(grid);

            grid[p0] = BimaruValue.SHIP_CONT_DOWN;
            grid[p1] = BimaruValue.UNDETERMINED;

            backup.RestoreAndDeleteLastSavepoint(grid);

            BimaruValue[,] expectedFieldValues = new BimaruValue[1, 2]
            {
                { BimaruValue.SHIP_SINGLE, BimaruValue.WATER }
            };

            grid.AssertEqual(expectedFieldValues);

            AssertEmptyStack(backup);
        }
예제 #2
0
        private void AssertEmptyStack(Backup <BimaruGrid> backup)
        {
            var destination = new BimaruGrid(1, 1);

            Assert.ThrowsException <InvalidOperationException>(() => backup.RestoreAndDeleteLastSavepoint(destination));
        }
예제 #3
0
        public void TestRestoreSavePointToNull()
        {
            var backup = new Backup <BimaruGrid>();

            Assert.ThrowsException <ArgumentNullException>(() => backup.RestoreAndDeleteLastSavepoint(null));
        }