예제 #1
0
 public void BadBigBlockPlacementTest( int x, int y )
 {
     Field field = new Field( 5, 10 );
     IBlock block = new Block();
     createBigBlock( block );
     field.SetBlock( block, new Point( x, y ) );
 }
예제 #2
0
        public void Test_CanMoveLeft_WhenNotAtTheLeftEdge_ReturnsTrue()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(UNUSED_BLOCK, new Vector2(1, 5));

            Assert.IsTrue(subject.CanMoveLeft());
        }
예제 #3
0
        public void Test_CanMoveLeft_WhenAtTheLeftEdge_ReturnsFalse()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(2, 1), new Vector2(0, 5));

            Assert.That(subject.CanMoveLeft(), Is.False);
        }
예제 #4
0
        public void Test_ColorAt_WhenNoBlockIsThere_ReturnsNull()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(), new Vector2(3, 4));

            Assert.IsNull(subject.ColorAt(new Vector2(3, 3)));
        }
예제 #5
0
 public void BadBlockPlacementTest( int x, int y )
 {
     Field field = new Field( 2, 10 );
     IBlock block = new Block();
     block.Grid [ 2 ] [ 2 ] = Color.Tomato;
     field.SetBlock( block, new Point( x, y ) );
 }
 public void SetUp()
 {
     IBlockFactory mockBlockFactory = new BlockHelper.MockBlockFactory();
     position = new Vector2(4, 4);
     field = new Field(10, 10);
     field.SetBlock(new BlockHelper.MockBlock(), position);
     subject = new GameMechanics(field, mockBlockFactory);
 }
예제 #7
0
        public void FixBlock_BlockIsDrawnWhenFixed()
        {
            Field f = new Field(1,1);
            f.SetBlock(new Block(), new Vector2(0, 0));
            GameMechanics mech = new GameMechanics(f, new BlockFactory());
            mech.AdvanceIfPossible();

            Color? color = f.ColorAt(new Vector2(0, 0));
            Assert.IsNotNull(color);
        }
예제 #8
0
        public void Test_CanAdvance_WhenNotAtTheBottom_ReturnsTrue()
        {
            int blockHeight = 3;
            int fieldHeight = 10;

            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(1, blockHeight), new Vector2(2, fieldHeight - blockHeight - 1));

            Assert.That(subject.CanAdvance(), Is.True);
        }
예제 #9
0
        public void Test_CanAdvance_WhenAtBottom_ReturnsFalse()
        {
            int blockHeight = 3;
            int fieldHeight = 10;

            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(1, blockHeight), new Vector2(3, fieldHeight - blockHeight));

            Assert.That(subject.CanAdvance(), Is.False);
        }
예제 #10
0
        public void Test_AdvanceBlock()
        {
            Field subject = new Field(10, 10);

            subject.SetBlock(UNUSED_BLOCK, new Vector2(3, 4));

            subject.AdvanceBlock();

            Assert.AreEqual(new Vector2(3, 5), subject.Position);
        }
예제 #11
0
        public void Test_ColorAt_WhenBlockIsThereWithColor_ReturnsBlockColorAt()
        {
            Field subject = new Field(10, 10);

            Mock<IBlock> block = new Mock<IBlock>();
            block.Setup(b => b.ColorAt(new Vector2(1, 2))).Returns(Color.White);
            block.Setup(b => b.Width).Returns(2);
            block.Setup(b => b.Height).Returns(3);
            subject.SetBlock(block.Object, new Vector2(4, 4));

            Color? result = subject.ColorAt(new Vector2(5, 6));
            Assert.AreEqual(Color.White, result.Value);
        }
예제 #12
0
        public void Test_CanAdvance_WhenNotAtTheBottom_ReturnsTrue()
        {
            int blockHeight = 3;
            int fieldHeight = 10;

            Mock<IBlock> block = new Mock<IBlock>();
            block.Setup(b => b.Height).Returns(blockHeight);

            Field subject = new Field(10, 10);
            subject.SetBlock(block.Object, new Vector2(2, fieldHeight - blockHeight - 1));

            Assert.IsTrue(subject.CanAdvance());
        }
예제 #13
0
 public void BadPositionTest( int x, int y )
 {
     IField field = new Field( 10, 10 );
     IBlock block = new BlockFactory().MakeBlock();
     field.SetBlock( block, new Point( 5, 5 ) );
     try
     {
         if ( field.Checker.Check( field, block, x, y ) )
         {
             throw new Exception( string.Format( "bad position has succeeded: x: {0}, y: {1}", x, y ) );
         }
     }
     catch ( FieldException )
     {
     }
 }
예제 #14
0
        public void Test_CanAdvance_WhenNotAtTheBottomButBlockInWay_ReturnsFalse()
        {
            int blockHeight = 3;
            int fieldHeight = 10;

            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(1, blockHeight), new Vector2(2, fieldHeight - blockHeight - 1));
            subject.SetContentsForTest(new Color?[,]{
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,Color.Red},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null,null,null,null}
            });

            Assert.That(subject.CanAdvance(), Is.False);
        }
예제 #15
0
        public void Test_ColorAt_WhenBlockIsThereAndNoColor_ItReturnsFieldColorAt()
        {
            Field subject = new Field(4, 4);
            Color white = Color.White;

            subject.SetContentsForTest(new Color?[,]
            { { null, null,  null,  null},
              { null, white, white, null },
              { null, white, white, null },
              { null, null,  null,  null} });

            Mock<IBlock> block = new Mock<IBlock>();
            Color? nullColor = null;

            block.Setup(b => b.Width).Returns(2);
            block.Setup(b => b.Height).Returns(2);
            block.Setup(b => b.ColorAt(new Vector2(0, 1))).Returns(nullColor);

            subject.SetBlock(block.Object, new Vector2(1, 1));

            Color? result = subject.ColorAt(new Vector2(1, 2));
            Assert.AreEqual(Color.White, result.Value);
        }
예제 #16
0
        public void Test_SetBlock()
        {
            Field subject = new Field(10, 10);
            IBlock block = new BlockHelper.MockBlock(4, 4);
            Vector2 position = new Vector2(2, 3);

            subject.SetBlock(block, position);

            Assert.AreEqual(block, subject.Block);
            Assert.AreEqual(position, subject.Position);
        }
예제 #17
0
        public void Test_MoveRight()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(), new Vector2(3, 4));
            subject.MoveBlockRight();

            Assert.AreEqual(new Vector2(4, 4), subject.Position);
        }
예제 #18
0
 public void PositionTest( int x, int y )
 {
     IField field = new Field( 10, 10 );
     IBlock block = new BlockFactory().MakeBlock();
     field.SetBlock( block, new Point( x, y ) );
     field.Checker.Check( field, block, x, y );
 }
예제 #19
0
        public void Test_CanRotateRight_RightSideNotFreeToRotate_ReturnsFalse()
        {
            int blockHeight = 2;

            Field subject = new Field(3, 3);
            subject.SetBlock(new BlockHelper.MockBlock(1, blockHeight), new Vector2(1, 0));
            subject.SetContentsForTest(new Color?[,]{
                {null,null,null},
                {null,null,null},
                {null,null,null}
            });

            Assert.That(subject.CanRotateRight(), Is.True);
        }
예제 #20
0
        public void Test_CanMoveRight_WhenNotAtTheRightEdge_ReturnsTrue()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(new BlockHelper.MockBlock(2, 1), new Vector2(7, 5));

            Assert.That(subject.CanMoveRight(), Is.True);
        }
예제 #21
0
        public void Test_CanMoveRight_WhenAtTheRightdge_ReturnsFalse()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(UNUSED_BLOCK, new Vector2(9, 5));

            Assert.IsFalse(subject.CanMoveRight());
        }
예제 #22
0
        public void TwoColumnMoveLeftOkTest()
        {
            Field field = new Field( 2, 10 );
            IBlock block = new Block();
            field.SetBlock( block, new Point( 1, 0 ) );
            block.Grid [ 0 ] [ 0 ] = Color.Tomato;

            bool moveleft = field.CanMoveLeft();
            Assert.AreEqual( true, moveleft );
        }
예제 #23
0
        public void SingleColumnNoMovesTest()
        {
            Field field = new Field( 1, 10 );
            IBlock block = new Block();
            block.Grid [ 0 ] [ 0 ] = Color.Tomato;

            field.SetBlock( block, new Point( 0, 0 ) );

            block.Grid [ 0 ] [ 0 ] = Color.Tomato;

            bool moveleft = field.CanMoveLeft();
            Assert.AreEqual( false, moveleft );
            bool moveright = field.CanMoveRight();
            Assert.AreEqual( false, moveright );
        }
예제 #24
0
        public void Test_MoveLeft()
        {
            Field subject = new Field(10, 10);
            subject.SetBlock(UNUSED_BLOCK, new Vector2(3, 4));
            subject.MoveBlockLeft();

            Assert.AreEqual(new Vector2(2, 4), subject.Position);
        }
예제 #25
0
 public void FixSquareBlockTest()
 {
     Field field = new Field( 2, 10 );
     IBlock block = new Block();
     block.Grid [ 0 ] [ 0 ] = Color.Tomato;
     block.Grid [ 0 ] [ 1 ] = Color.Tomato;
     block.Grid [ 1 ] [ 0 ] = Color.Tomato;
     block.Grid [ 1 ] [ 1 ] = Color.Tomato;
     field.SetBlock( block, new Point( 0, 0 ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 0, 9 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 1, 9 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 0, 8 ) ) );
     Assert.AreEqual( null, field.ColorAt( new Point( 1, 8 ) ) );
     field.FixBlock();
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 0, 9 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 1, 9 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 0, 8 ) ) );
     Assert.AreEqual( Color.Tomato, field.ColorAt( new Point( 1, 8 ) ) );
 }