Beispiel #1
0
        public void TestIfMethodGetBlockTypeReturnGivenString()
        {
            Block  zBlock            = new Z_Block(2, 1);
            string expectedBlockType = "Z_Block";
            string actualResult      = zBlock.GetBlockType();

            Assert.AreEqual(expectedBlockType, actualResult);
        }
Beispiel #2
0
        public void TestIfMiddlePointIsSetCorrectly()
        {
            int           middleX             = 4;
            int           middleY             = 7;
            Block         zBlock              = new Z_Block(middleX, middleY);
            PrivateObject po                  = new PrivateObject(zBlock);
            Point         actualMiddlePoint   = (Point)po.GetField("middlePoint");
            Point         expectedMiddlePoint = new Point(middleX, middleY);

            Assert.AreEqual(expectedMiddlePoint.Get()[0], actualMiddlePoint.Get()[0]);
            Assert.AreEqual(expectedMiddlePoint.Get()[1], actualMiddlePoint.Get()[1]);
        }
Beispiel #3
0
    Block CreateBlock(char shape_ch, int type)
    {
        Node[] nl = new Node[4];
        for (int i = 0; i < 4; i++)
        {
            GameObject o = Instantiate(resBlock);
            o.transform.SetParent(transform.Find("Panel"));
            o.transform.localScale = Vector3.one;
            nl[i] = new Node(o.transform);
        }
        Block tmp_b = new Block();

        switch (shape_ch)
        {
        case 'I':
            tmp_b  = new I_Block(nl, type);
            t_type = 1;
            break;

        case 'L':
            tmp_b  = new L_Block(nl, type);
            t_type = 2;
            break;

        case 'J':
            tmp_b  = new J_Block(nl, type);
            t_type = 3;
            break;

        case 'T':
            tmp_b  = new T_Block(nl, type);
            t_type = 4;
            break;

        case 'Z':
            tmp_b  = new Z_Block(nl, type);
            t_type = 5;
            break;

        case 'S':
            tmp_b  = new S_Block(nl, type);
            t_type = 6;
            break;

        case 'O':
            tmp_b  = new O_Block(nl, type);
            t_type = 7;
            break;
        }
        return(tmp_b);
    }
Beispiel #4
0
        public void TestWhetherMethodIfBlockOutOfGridOnRotateWhenRotationPoseEqualsThreeReturnsFalse()
        {
            Block         zBlock = new Z_Block(10, 23);
            PrivateObject po     = new PrivateObject(zBlock);

            po.SetField("rotationPose", 3);
            int gridX = 56;

            object[] args           = new object[] { gridX };
            bool     actualResult   = (bool)po.Invoke("IfBlockOutOfGridOnRotate", args);
            bool     expectedResult = false;

            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #5
0
        public void TestWhetherMethodIfBlockOutOfGridOnRotateWhenRotationPoseEqualsZeroReturnsTrue()
        {
            Block         zBlock = new Z_Block(30, 50);
            PrivateObject po     = new PrivateObject(zBlock);

            po.SetField("rotationPose", 0);
            int gridX = 10;

            object[] args           = new object[] { gridX };
            bool     actualResult   = (bool)po.Invoke("IfBlockOutOfGridOnRotate", args);
            bool     expectedResult = true;

            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #6
0
        public void TestIfRestPointsAreSetCorrectly()
        {
            int           middleX = 3;
            int           middleY = 5;
            Block         zBlock  = new Z_Block(middleX, middleY);
            PrivateObject po      = new PrivateObject(zBlock);

            Point[] actualRestPoints   = (Point[])po.GetField("restPoints");
            Point[] expectedRestPoints = new Point[3] {
                new Point(2, 4), new Point(3, 4), new Point(4, 5)
            };
            for (int i = 0; i < actualRestPoints.Length; i++)
            {
                Assert.AreEqual(expectedRestPoints[i].Get()[0], actualRestPoints[i].Get()[0]);
                Assert.AreEqual(expectedRestPoints[i].Get()[1], actualRestPoints[i].Get()[1]);
            }
        }
Beispiel #7
0
        public void TestIfTwoPrivateFieldsAreSetByConstructorCall()
        {
            int           middleX = 22254;
            int           middleY = 11212;
            Block         zBlock  = new Z_Block(middleX, middleY);
            PrivateObject po      = new PrivateObject(zBlock);

            Point actualMiddlePoint = (Point)po.GetField("middlePoint");

            Point[] actualRestPoints = (Point[])po.GetField("restPoints");

            int expectedMiddlePointLength = 2;
            int expectedRestPointsLength  = 3;

            Assert.AreEqual(expectedMiddlePointLength, actualMiddlePoint.Get().Length);
            Assert.AreEqual(expectedRestPointsLength, actualRestPoints.Length);
        }
Beispiel #8
0
        public void TestRotateMethodWhenRotationPoseEqualsZero()
        {
            Block         zBlock = new Z_Block(3, 5);
            PrivateObject po     = new PrivateObject(zBlock);

            po.SetField("rotationPose", 0);
            po.Invoke("Rotate");

            Point[] actualRestPoints   = (Point[])po.GetField("restPoints");
            Point[] expectedRestPoints = new Point[3] {
                new Point(4, 4), new Point(4, 3), new Point(3, 6)
            };

            for (int i = 0; i < actualRestPoints.Length; i++)
            {
                Assert.AreEqual(expectedRestPoints[i].Get()[0], actualRestPoints[i].Get()[0]);
                Assert.AreEqual(expectedRestPoints[i].Get()[1], actualRestPoints[i].Get()[1]);
            }
        }