software_testing_work3_question2

 1 package com.Phantom;
 2 
 3 import java.rmi.server.Operation;
 4 import java.util.Scanner;
 5 
 6 public class Work3_2 {
 7 
 8     /**
 9      * @param args
10      */
11     float x;
12     float y;
13     String step1;
14     String step2;
15     String step3;
16 
17     public void setX(float x) {
18         this.x = x;
19     }
20 
21     public void setY(float y) {
22         this.y = y;
23     }
24 
25     public Work3_2() {
26     }
27 
28     
29     public int operation(){
30         step1="a";
31         if(x<4||y>0){
32             step2="b";
33             if(y>1){
34                 step3="c";
35                 y=y+1;
36             }
37             else{
38                 step3="d";
39             }
40         }
41         else{
42             step2="e";
43             if(x>=5){
44                 step3="f";
45                 x=x-y;
46             }
47             else{
48                 step3="g";
49                 x=x+y;
50             }
51         }
52         System.out.println("输出X >>>"+x);
53         System.out.println("输出Y >>>"+y);
54         System.out.println("路径:");
55         System.out.println(step1+"——>"+step2+"——>"+step3);
56         return 0;
57     }
58 
59 }

测试类

 1 package com.Phantom;
 2 
 3 import static org.junit.Assert.*;
 4 
 5 import org.junit.After;
 6 import org.junit.Before;
 7 import org.junit.Test;
 8 
 9 public class Work3_2_teting {
10     private Work3_2 w1;
11     @Before
12     public void setUp() throws Exception {
13         w1=new Work3_2();
14     }
15 
16     @After
17     public void tearDown() throws Exception {
18     }
19 
20     @Test
21     public void test() {
22         /*
23          * a-e-g
24          * */
25         w1.setX(4);
26         w1.setY(0);
27         w1.operation();
28         System.out.println("-----------------");
29         /*
30          * a-e-f
31          * */
32         w1.setX(5);
33         w1.setY(0);
34         w1.operation();
35         System.out.println("-----------------");
36         /*
37          * a-b-d_(1)
38          * */
39         w1.setX(4);
40         w1.setY((float) 0.1);
41         w1.operation();
42         System.out.println("-----------------");
43         /*
44          * a-b-d_(2)
45          * */
46         w1.setX(3);
47         w1.setY(-1);
48         w1.operation();
49         System.out.println("-----------------");
50         /*
51          * a-b-c
52          * */
53         w1.setX(4);
54         w1.setY(2);
55         w1.operation();
56         System.out.println("-----------------");
57         
58     }
59 
60 }

运行junit测试

 

原文地址:https://www.cnblogs.com/Phantom-void/p/5347526.html