RIGHT-BICEP Unit Test--"Two pillars Arithmetic upgrade version"

Source: Internet
Author: User

RIGHT-BICEP Unit Test--"Two pillars Arithmetic upgrade version"

"Unit Test" This is a new professional meaning for us, and after we have written a simple unit test for the "max value of a set of numbers" function in the Software engineering class, we have a new understanding of it classroom.

Unit tests: that is,

The teacher let us go back after the "Two pillars Arithmetic upgrade version" of the program for unit testing (two pillars of the source code I have uploaded, here is no longer repeated, only the Unit Test section and analysis), as follows:

PS. Here are some of the methods that the teacher taught about RIGHT-BICEP testing:

6 Specific parts worth testing, they can improve our testing skills: right-The results are correct? B is all the boundary conditions correct? Can I check the inverse association? C-Can you cross-check the results with other means? E-Can you force error conditions to occur? Does p meet performance requirements?

First, the test plan

-is the test result correct? -Test to produce a specified range of random numbers? -Test can I choose whether to save to the file? -Test can I choose whether there is a true score? -Can the test choose to only add or subtract or arithmetic? -Can the test be selected plus minus or minus? -Test to choose whether division has an all-in-one number? Second, is the test result correct?

Third, test can produce a specified range of random number?

The last program that wrote the two pillars also used random random numbers to generate a knowledge point, which I have declared to be seen in the csdn of the Great gods. The following source code is used:

1#include <iostream>2#include <time.h>3 using namespacestd;4 #defineRandom (x) (rand ()%x)5 6 voidMain ()7 {8Srand ((int) Time (0));9one = rand ()% (r2-r1+1) +1;Tenboth = rand ()% (R2-r1 +1) +1; Onecout<<one<<" "<<two<<Endl; A}

In this way, it seems that only positive integers can be produced. However, since the requirements of this procedure involve the user setting "whether there are negative numbers", so I have two ideas. One is to also use the last method, set the Swich statement to control whether to manually add

Minus sign. The other is to generate a random number with negative numbers. So I went to another person's blog on the onlookers (forgive me I really can't remember the method of generating random numbers ╥﹏╥ ... ), after my test, the following method can produce an arbitrary interval of integers (including negative numbers), the source code is as follows:

1 //test program at the time of programming2 3#include <iostream>4#include <time.h>5 using namespacestd;6 #defineRandom (x) (rand ()%x)7 8 voidMain ()9 {Ten      One     intOne , the other; A     intR, R1, R2; -cout <<"enter the lower and upper limits, respectively:"<<Endl; -CIN >>R1; theCIN >>R2; -r = R2-R1; -Srand ((int) Time (0)); -     /*One = r1 + r2 * rand ()/(Rand_max + 1); + Both = r1 + r2 * rand ()/(Rand_max + 1); - three = r1 + R2 * rand ()/(Rand_max + 1); + Four = r1 + r2 * rand ()/(Rand_max + 1);*/ A  atone = r1 + rand ()%R; -both = R1 + rand ()%R; -  -cout << one<<" ,"<< <<Endl; -}

The test data is as follows: Test the integer between -30~50;0~30;-30~0 separately, test the result correctly!!

Iv. can the test choose whether to save to the file?

The teacher's topic requirements are "customizable printing", I see some students understand the output style according to different outputs, such as a line of output 5 or 10 formulas, this can be customized. But what I understand is that I want the user to choose whether or not to output to the file, so I looked up the C + + input and output stream code, as follows:

1#include <fstream>2#include <iostream>3#include <cmath>4 using namespacestd;5 6 intMain ()7 {8Ofstream outfile ("Prime.txt"Ios:: out);9     if(!outfile)Ten     { Onecout <<"Open error!"<<Endl; AExit1); -     } -OutFile << "1 2 3 4 5 6" <<Endl; the outfile.close (); -     return 0; -}

We will see the successful creation of the file and deposit the data into the file.

But...... (。?_?。 )? I have to say, I am in the development of the idea is to think, first let the user choose whether to print to the file, and then in each subsequent output is controlled by the IF statement, if only the screen output with cout<< output, if it is saved to a file with outfile<< output ...... But...... Since my output is really too big, the first round of code writing I just wrote the screen output amount of cout, and then yesterday because of the job to turn off the output part of the code, but I used a function to set up the file, there is time I will definitely add ...

Five, the test can choose whether there is no real score? Six, test can choose to only add or subtract operation or arithmetic? Seven, the test can choose whether plus minus? Eight, test can choose Division has no number?

RIGHT-BICEP Unit Test--"Two pillars Arithmetic upgrade version"

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.