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

            Assert.AreEqual(expectedBlockType, actualResult);
        }
Beispiel #2
0
        public void TestIfMiddlePointIsSetCorrectly()
        {
            int           middleX             = 4;
            int           middleY             = 7;
            Block         lBlock              = new L_Block(middleX, middleY);
            PrivateObject po                  = new PrivateObject(lBlock);
            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         lBlock = new L_Block(10, 23);
            PrivateObject po     = new PrivateObject(lBlock);

            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         lBlock = new L_Block(30, 50);
            PrivateObject po     = new PrivateObject(lBlock);

            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 = 30;
            int           middleY = 50;
            Block         lBlock  = new L_Block(middleX, middleY);
            PrivateObject po      = new PrivateObject(lBlock);

            Point[] actualRestPoints   = (Point[])po.GetField("restPoints");
            Point[] expectedRestPoints = new Point[3] {
                new Point(29, 50), new Point(31, 50), new Point(31, 49)
            };
            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 = 2654;
            int           middleY = 1;
            Block         lBlock  = new L_Block(middleX, middleY);
            PrivateObject po      = new PrivateObject(lBlock);

            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 TestRotateMethodWhenRotationPoseEqualsThree()
        {
            Block         lBlock = new L_Block(30, 50);
            PrivateObject po     = new PrivateObject(lBlock);

            po.SetField("rotationPose", 3);
            po.Invoke("Rotate");
            Point[] expectedRestPoints = new Point[3] {
                new Point(28, 49), new Point(32, 51), new Point(33, 49)
            };
            Point[] actualRestPoints = (Point[])po.GetField("restPoints");

            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]);
            }
        }