public void OneMineMinefield_PropagationShouldUncoverAllButOne() { //Arrange IBooleansGenerator booleansGenerator = Substitute.For <IBooleansGenerator>(); booleansGenerator.GenerateBooleans(Arg.Any <int>(), Arg.Any <int>()) .Returns(x => { var r = new bool[(int)x[0]]; r[0] = true; //Only the first item will be set to true. return(r); }); int horizontalTilesCount = 5; int verticalTilesCount = 5; IMinefieldFactory factory = new MinefieldFactory(booleansGenerator); var minefield = factory.CreateNew(horizontalTilesCount, verticalTilesCount, 1); var someTile = minefield.Tiles[3][3]; //Act minefield.TilesCovered.ShouldBe(horizontalTilesCount * verticalTilesCount); someTile.UncoverTile(); //Assert minefield.TilesCovered.ShouldBe(1); }
public void CreateNew_ShouldThrowArgumentException_WhenMoreMinesThanTiles(int rows, int columns, int bombsCount) { IBooleansGenerator booleansGenerator = new RandomBooleansGenerator(); IMinefieldFactory factory = new MinefieldFactory(booleansGenerator); Should.Throw <ArgumentException>(() => factory.CreateNew(rows, columns, bombsCount)); }
public void CreateNew_ShouldReturn_ValidMinefield(int rows, int columns, int bombsCount) { IBooleansGenerator booleansGenerator = new RandomBooleansGenerator(); IMinefieldFactory factory = new MinefieldFactory(booleansGenerator); var result = factory.CreateNew(rows, columns, bombsCount); result.Tiles.SelectMany(t => t).Count().ShouldBe(rows * columns); result.BombsInMinefiled.ShouldBe(bombsCount); result.Tiles.SelectMany(t => t).All(t => t.Neighbours.Count() >= 3 && t.Neighbours.Count() <= 8).ShouldBeTrue(); }
public void ToggleFlag_ShouldToggle() { IBooleansGenerator booleansGenerator = new RandomBooleansGenerator(); IMinefieldFactory factory = new MinefieldFactory(booleansGenerator); var minefield = factory.CreateNew(5, 5, 10); var firstTile = minefield.Tiles[0][0]; firstTile.State.ShouldBe(Tile.TileState.Covered); firstTile.ToggleFlag(); firstTile.State.ShouldBe(Tile.TileState.Flagged); firstTile.ToggleFlag(); firstTile.State.ShouldBe(Tile.TileState.Covered); }