示例#1
0
        public void GivenSquareIsClean_Suck_ShouldReturnTwoPossibleStates()
        {
            var currentState = new VacuumWorldState(3);

            var possibleStateAllClean       = currentState.Clone();
            var possibleStateOneSquareDirty = currentState.Clone();

            possibleStateOneSquareDirty.MakeSquareDirty(currentState.VacuumPos);

            // act
            var potentialStates = _searchProblem.DoAction(currentState, VacuumWorldAction.Suck).ToList();

            // assert
            Assert.AreEqual(2, potentialStates.Count);
            Assert.AreEqual(1, potentialStates.Count(s => s.Equals(possibleStateAllClean)));
            Assert.AreEqual(1, potentialStates.Count(s => s.Equals(possibleStateOneSquareDirty)));
        }
示例#2
0
 private static IEnumerable <VacuumWorldState> CreateAllStatesWithOneCleanedNeighbour(VacuumWorldState state)
 {
     return(state
            .AdjacentSquares(state.VacuumPos)
            .Select(square =>
     {
         var neighbourState = state.Clone();
         neighbourState.CleanSquare(square);
         return neighbourState;
     }));
 }
示例#3
0
        public void GivenOnlyVacuumSquareIsDirty_Suck_ShouldReturnOnePossibleState()
        {
            var currentState = new VacuumWorldState(3);

            currentState.MakeSquareDirty(currentState.VacuumPos);

            var onlyPossibleState = currentState.Clone();

            onlyPossibleState.CleanSquare(currentState.VacuumPos);

            // act
            var potentialStates = _searchProblem.DoAction(currentState, VacuumWorldAction.Suck).ToList();

            // assert
            Assert.AreEqual(1, potentialStates.Count);
            Assert.AreEqual(1, potentialStates.Count(s => s.Equals(onlyPossibleState)));
        }
示例#4
0
        public void GivenAllSquaresAreDirty_Suck_ShouldReturnCleanedStatePlusCleanedNeighbourStates()
        {
            var currentState = new VacuumWorldState(3);

            currentState.SetAllSquaresDirty();
            currentState.VacuumPos = new Point2D(1, 1);

            var onlyOneSquareCleanedState = currentState.Clone();

            onlyOneSquareCleanedState.CleanSquare(currentState.VacuumPos);
            var neighbourCleanedStates = CreateAllStatesWithOneCleanedNeighbour(onlyOneSquareCleanedState);

            var expectedPotentialStates = neighbourCleanedStates
                                          .Concat(new[] { onlyOneSquareCleanedState }).ToList();

            // act
            var potentialStates = _searchProblem.DoAction(currentState, VacuumWorldAction.Suck).ToList();

            // assert
            CollectionAssert.AreEquivalent(expectedPotentialStates, potentialStates);
        }