public void DoAction(VacuumWorldState state, VacuumWorldAction action) { if (action != VacuumWorldAction.Suck) { throw new InvalidOperationException(); } var squareWasClean = !state.SquareIsDirty(state.VacuumPos); _decoratedHandler.DoAction(state, action); if (squareWasClean) { if (_random.TrueWithProbability(_makeDirtyProbability)) { state.MakeSquareDirty(state.VacuumPos); } } else { if (_random.TrueWithProbability(_cleanExtraProbability)) { CleanRandomDirtyNeighbour(state); } } }
public void Suck_dirty_should_make_it_clean() { _state.MakeSquareDirty(1, 1); _state.VacuumPos = new Point2D(1, 1); _handler.DoAction(_state, VacuumWorldAction.Suck); Assert.IsFalse(_state.SquareIsDirty(_state.VacuumPos)); }
public void GivenCleanExtraProbabilityOf1_Suck_ShouldCleanAdjacentSquare() { // arrange _state.SetAllSquaresDirty(); _state.VacuumPos = new Point2D(1, 1); const double cleanExtraProbability = 1.0; _handler = new ErraticSuckActionHandler(_decoratedHandler, cleanExtraProbability); // act _handler.DoAction(_state, VacuumWorldAction.Suck); // assert var numDirtyNeighbours = _state.AdjacentSquares(_state.VacuumPos).Count(s => _state.SquareIsDirty(s)); Assert.AreEqual(3, numDirtyNeighbours); }