Exemple #1
0
        public void GenerateBooleans_ShouldReturnOnlyNegatives_GivenZeroPositives()
        {
            IBooleansGenerator generator = new RandomBooleansGenerator();

            bool[] result = generator.GenerateBooleans(10, 0);
            result.All(x => !x).ShouldBeTrue();
        }
Exemple #2
0
        public void GenerateBooleans_ShouldReturnOnlyPositives_GivenSameInputs()
        {
            IBooleansGenerator generator = new RandomBooleansGenerator();

            bool[] result = generator.GenerateBooleans(10, 10);
            result.All(x => x).ShouldBeTrue();
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        public void GenerateBooleans_ShouldReturnDifferent_ForDifferentSeed(int allCount, int positivesCount, int seedA, int seedB)
        {
            IBooleansGenerator generatorA = new RandomBooleansGenerator(seedA);
            IBooleansGenerator generatorB = new RandomBooleansGenerator(seedB);

            bool[] resultA = generatorA.GenerateBooleans(allCount, positivesCount);
            bool[] resultB = generatorB.GenerateBooleans(allCount, positivesCount);
            resultA.SequenceEqual(resultB).ShouldBeFalse();
        }
Exemple #5
0
        public void GenerateBooleans_ShouldReturnSame_ForSameSeed(int allCount, int positivesCount, int seed)
        {
            IBooleansGenerator generatorA = new RandomBooleansGenerator(seed);
            IBooleansGenerator generatorB = new RandomBooleansGenerator(seed);

            bool[] resultA = generatorA.GenerateBooleans(allCount, positivesCount);
            bool[] resultB = generatorB.GenerateBooleans(allCount, positivesCount);
            resultA.SequenceEqual(resultB).ShouldBeTrue();
        }
Exemple #6
0
        public void GenerateBooleans_ShouldReturnX_GivenXPositives(int allCount, int positivesCount)
        {
            IBooleansGenerator generator = new RandomBooleansGenerator();

            bool[] result = generator.GenerateBooleans(allCount, positivesCount);
            result.Length.ShouldBe(allCount);
            result.Count(x => x).ShouldBe(positivesCount);
            result.Count(x => !x).ShouldBe(allCount - positivesCount);
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        public void GenerateBooleans_ShouldThrowException_GivenInvalidInputs(int allCount, int positivesCount)
        {
            IBooleansGenerator generator = new RandomBooleansGenerator();

            Should.Throw <ArgumentException>(() => generator.GenerateBooleans(allCount, positivesCount));
        }