If not tested, as a programmer you absolutely do not know how careless you are

Source: Internet
Author: User

Over the last two months, our Kinect game project is progressing well and the corresponding tests are underway.

In the morning of Friday, my teammates and I tested the Kinect function in the lab. The whole testing process is really embarrassing, I was simply too careless, the error in the code is endless.

As a result of the two-person model, so the program is difficult to test immediately, only when the teammates have time to test together.

Our project consists of eight different actions corresponding to different operations. The beginning of the test is not smooth, the leg movement is very strange, in order to find the wrong position faster, we commented out the action of the leg, only to see the hands of action.

                    Skeletonpoint playera_head = two[0]. Joints[jointtype.head].
                    Position; Skeletonpoint playerb_head = two[1]. Joints[jointtype.head].

                    Position; Skeletonpoint Playera_leftshoulder = two[0]. Joints[jointtype.shoulderleft].
                    Position; Skeletonpoint Playerb_leftshoulder = two[1]. Joints[jointtype.shoulderleft].

                    Position; Skeletonpoint Playera_rightshoulder = two[0]. Joints[jointtype.shoulderright].
                    Position; Skeletonpoint Playerb_rightshoulder = two[1]. Joints[jointtype.shoulderright].


                    Position; Skeletonpoint Playera_lefthand = two[0]. Joints[jointtype.handleft].
                    Position; Skeletonpoint Playerb_lefthand = two[1]. Joints[jointtype.handleft].

                    Position; Skeletonpoint Playera_righthand = two[0]. Joints[jointtype.handright].
                    Position; Skeletonpoint Playerb_righthand = two[1]. Joints[jointtype.handright]. Position;

The logic of the program is based on the distance between the hand and the shoulder to judge the action of the hand, because there is a large number of code duplication, resulting in the place should write left to paste over without modification, or right. This is the first problem found during the testing process.

After the hand function was normal, we opened the comment on the leg code and began to test the function of the legs. The logic of the program is that the left leg lifts the trigger event one, and the right leg lifts the trigger event two. But two teammates cannot trigger events no matter how high they lift their legs. After checking the code we found that the set leg lift threshold is one metre,

                    Private Const DOUBLE legxstretchedthreshold = 0.2; Leg x-axis extension of the valve value, unit meter
                    Private Const double Legystretchedthreshold = 1.0;//Leg y-axis extension of valve value, Unit m

Finally found the cause of the problem, the threshold set so large, teammates have to jump up to achieve the required threshold. We thought that after correcting the problem, the program would run normally, but again we found that the event could not be triggered. After reading the source code carefully, we found that the logic of the program is to judge the distance between the head and the foot, which is the reason why the threshold of one meter appears.

                    BOOL playera_isleftfootstretched = (playera_head. Y-PLAYERA_RIGHTFOOT.Y) < legystretchedthreshold);
                    if (playera_isleftfootstretched)
                    {
                            KeyboardToolkit.Keyboard.Type (KEY.K);
                            Playera_leftlegraised = true;
                    }

In practical applications, this method of judging is actually unreasonable, because our users have 1.5-meter height of the Meng sister, also has a height of 1.8-meter female men, this case to judge the distance between the head and feet is caused by the problem. We then changed the logic to determine the distance between the left foot and the right foot. The code is as follows:


                    BOOL playera_isleftfootstretched = ((PLAYERA_LEFTFOOT.Y-PLAYERA_RIGHTFOOT.Y) > Legystretchedthreshold);
                    if (playera_isleftfootstretched)
                    {
                            KeyboardToolkit.Keyboard.Type (KEY.K);
                            Playera_leftlegraised = true;
                    }


After finally being able to successfully trigger the leg incident, we found that the same event will be triggered several times when the leg is raised, which feels a bit like pressing the keyboard key does not let go, we want to click on the good. The solution to this problem is more popular, is to add a bool variable record has been pressed, the code is as follows:

                    BOOL playera_isleftfootstretched = ((PLAYERA_LEFTFOOT.Y-PLAYERA_RIGHTFOOT.Y) > Legystretchedthreshold);
                    if (playera_isleftfootstretched)
                    {
                        if (! playera_leftlegraised)
                        {
                            KeyboardToolkit.Keyboard.Type (KEY.K);
                            Playera_leftlegraised = true;
                        }
                    }

After the test, our program is finally able to run normally. Procedures that have not been tested are difficult to reassure.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.