5.1 Testing

Source: Internet
Author: User

 PackageSizeys;ImportJava.text.DecimalFormat;ImportJava.util.Scanner; Public classH { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); Try{System.out.print ("Please enter the first number:"); Doublex =scanner.nextdouble (); System.out.print ("Please enter a second number:"); Doubley =scanner.nextdouble (); System.out.print ("Please enter operator:"); String s=Scanner.next (); Charz = S.charat (0);        Js.yunsuan (x, y, z); } Catch(Exception e) {System.out.println ("Please enter the correct data!" "); }    }} PackageSizeys;ImportJava.text.DecimalFormat; Public classJS { Public Static voidYunsuan (DoubleXDoubley, Character z) {DecimalFormat R=NewDecimalFormat (); R.applypattern ("#0.00"); if(Z.equals (' + ')) {jia.yunsuan1 (x, y); //System.out.println (x + "+" + y + "=" + R.format ((x + y));}Else if(Z.equals ('-')) {jia.yunsuan2 (x, y); //System.out.println (x + "-" + y + "=" + R.format ((x-y)));}Else if(Z.equals (' * ')) {jia.yunsuan3 (x, y); //System.out.println (x + "*" + y + "=" + R.format ((x * y));}Else if(Z.equals ('/'))) {            if(y = = 0) {System.out.println ("Dividend cannot be 0"); } Else{jia.yunsuan4 (x, y); //System.out.println (x + "/" + y + "=" + R.format ((x/y)));            }        } Else{System.out.println ("Change operator not recognized"); }    }} PackageSizeys;ImportJava.text.DecimalFormat; Public classJia { Public Static DoubleYunsuan1 (DoubleXDoubley) {DecimalFormat R=NewDecimalFormat (); R.applypattern ("#0.00"); SYSTEM.OUT.PRINTLN (x+ "+" + y + "=" + r.format (x +( y))); returnX +y; }     Public Static DoubleYunsuan2 (DoubleXDoubley) {DecimalFormat R=NewDecimalFormat (); R.applypattern ("#0.00"); SYSTEM.OUT.PRINTLN (x+ "-" + y + "=" + R.format (X-( y))); returnX-y; }     Public Static DoubleYUNSUAN3 (DoubleXDoubley) {DecimalFormat R=NewDecimalFormat (); R.applypattern ("#0.00"); SYSTEM.OUT.PRINTLN (x+ "*" + y + "=" + R.format (x *( y))); returnX *y; }     Public Static DoubleYunsuan4 (DoubleXDoubley) {DecimalFormat R=NewDecimalFormat (); R.applypattern ("#0.00"); SYSTEM.OUT.PRINTLN (x+ "/" + y + "=" + R.format ((X/( y))); returnX/y; }} PackageSizeys;Import Staticorg.junit.assert.*;Importorg.junit.Test; Public classjiatest {@SuppressWarnings ("Static-access") @Test Public voidtestYunsuan1 () {Jia Core1=NewJia (); DoubleA = Core1.yunsuan1 (9,-3); //Test: 9 and 3 incoming in my Add method, the result will be 6? //Assertequals (6, a);} @Test Public voidtestYunsuan2 () {Jia Core2=NewJia (); Doubleb = core2.yunsuan2 (9, 4); } @Test Public voidtestYunsuan3 () {Jia Core3=NewJia (); Doublec = CORE3.YUNSUAN3 (9,-1); } @Test Public voidTestYunsuan4 () {Jia Core4=NewJia (); DoubleD = Core4.yunsuan4 (9, 5); }}

The following are black-box and white-Box testing techniques:

1. Black box method test. The test is primarily to test the functionality and use of the code in terms of user perspective:

Test Cases

Input criteria

Valid equivalence classes

Invalid equivalence class

Question Validity judgment

Allow only numbers

8

OP

Validity judgment of input characters

(8,2,OP)

8,2

OP

Test object

Test instructions

Test data

Test results

Number of topics

Enter illegal data

T

Please enter the correct data!

Subtraction Calculation

Wrong input symbol

5 6 O

The operator is not recognized

Calculation range

Accuracy

11.0 and 11 and 11.00

That's right

2. White box method test. Detailed examination of the procedural details of the software.

Test Cases

Use case description

Actual results

Additive processing

1.2+2.3

3.50

Subtraction Processing

9-4.2

4.80

Multiplication processing

11*3.0

33.00

Division Processing

8.0/2

4.0

Except 0 processing

5.0/0

Throw exception

Code Coverage

100%

100%

Companion: 201306114456, 刁怿.
Weibo: http://www.cnblogs.com/diaoyi/

5.1 Testing

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.