public void TestIfMementoProvidesDeepCopy() { var game = new GameModel(); this.logic.RandomizeBalloonField(game.Field); this.memento.SaveState(game); var stateFromMemento = this.memento.GetState(); game.Field[0, 0].IsPopped = true; Assert.IsFalse(ReferenceEquals(game.Field, stateFromMemento.Field)); bool areEqual = true; for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { if (game.Field[i, j].IsPopped != stateFromMemento.Field[i, j].IsPopped) { areEqual = false; } } } Assert.IsFalse(areEqual); }
public void TestIfResetMethodCorrectlyResetsTheUserMovesCount() { var gameModel = new GameModel(); gameModel.IncrementMoves(); gameModel.ResetUserMoves(); Assert.AreEqual(0, gameModel.UserMovesCount); }
public void TestIfFieldPropertyReturnTheSameFieldItIsSetTo() { var field = new IBalloon[5, 10]; var gameModel = new GameModel(); gameModel.Field = field; Assert.AreSame(field, gameModel.Field); }
public void TestIfFieldPropertyReturnsTheSameValueItIsSetTo() { var game = new GameModel(); var field = new IBalloon[5, 10]; game.Field = field; Assert.AreEqual(field, game.Field); }
public void TestIfConstructorWithParametersHasTheSameBehaviorAsTheSetter() { var game = new GameModel(); this.logic.RandomizeBalloonField(game.Field); this.memento.SaveState(game); var memento2 = new Saver<IGameModel>(); memento2.SaveState(game); var stateFromMemento = this.memento.GetState(); var areEqual = new QueryableMatrix<IBalloon>(memento2.GetState().Field) .Join(new QueryableMatrix<IBalloon>(stateFromMemento.Field), x => x, y => y, (x, y) => (x.IsPopped == y.IsPopped) && (x.Number == y.Number)) .All(x => x); Assert.IsTrue(areEqual); }
public void TestIfGetterEncapsulatesTheCurrentState() { var game = new GameModel(); this.logic.RandomizeBalloonField(game.Field); this.memento.SaveState(game); var state = this.memento.GetState(); state.Field[0, 0].Number = 99; Assert.AreNotEqual(game.Field[0, 0].Number, 99); var moves = state.UserMovesCount; game.IncrementMoves(); var moves2 = game.UserMovesCount; Assert.AreNotEqual(moves, moves2); }
public void TestIfPrintFieldChangesTheSourceOfTheImages() { var game = new GameModel(); Assert.AreEqual(0, this.view.BalloonGrid.Children.Count); this.controller.PrintField(game.Field); var sources = this.view.BalloonGrid.Children.Cast<Image>().Select(x => x.Source).ToList(); var redField = new QueryableMatrix<IBalloon>(5, 10).Select(x => new Balloon() { Number = 1 }).ToMatrix(5, 10); this.controller.PrintField(redField); var sources2 = this.view.BalloonGrid.Children.Cast<Image>().Select(x => x.Source).ToList(); bool different = false; for (int i = 0; i < sources.Count; i++) { different = sources[i].ToString() != sources2[i].ToString(); } Assert.IsTrue(different); }
public void TestIfPrintFieldInitializesTheImageSourcesAtFirstPrint() { var game = new GameModel(); Assert.AreEqual(0, this.view.BalloonGrid.Children.Count); this.controller.PrintField(game.Field); Assert.AreEqual(50, this.view.BalloonGrid.Children.Count); }
public void TestIfInitialMovesCountIsZero() { var gameModel = new GameModel(); Assert.AreEqual(0, gameModel.UserMovesCount); }
public void TestIfIncrementMovesMethodCorrectlyIncrementTheMovesCount() { var gameModel = new GameModel(); gameModel.IncrementMoves(); Assert.AreEqual(1, gameModel.UserMovesCount); }
public void TestIfGameModelIsCreatedWithInitializedField() { var gameModel = new GameModel(); Assert.IsNotNull(gameModel.Field); }
public void TestIfHasStatesReturnsTrueWhenThereArePushedStates() { var game = new GameModel(); this.memento.SaveState(game); Assert.IsTrue(this.memento.HasStates); }
public void TestIfMementoReturnsTheSameStateItAccepter() { var game = new GameModel(); this.logic.RandomizeBalloonField(game.Field); this.memento.SaveState(game); var stateFromMemento = this.memento.GetState(); var areEqual = new QueryableMatrix<IBalloon>(game.Field) .Join(new QueryableMatrix<IBalloon>(stateFromMemento.Field), x => x, y => y, (x, y) => (x.IsPopped == y.IsPopped) && (x.Number == y.Number)) .All(x => x); Assert.IsTrue(areEqual); }