Exercise 5.1 Update--Arithmetic testing and encapsulation

Source: Internet
Author: User

 Packagecom.h1;Import Staticorg.junit.assert.*;ImportOrg.junit.Assert;ImportOrg.junit.Before;Importorg.junit.Test;ImportCom.h2.Core; Public classcoretest {@Test Public voidTestadd () {//addition        intn = 3;//Number of Operations        int[] Num1 = {1, 2, 3};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] No = {1, 1};//Operation PouteCore C =NewCore (); C.calcute (num1,op,no,n);//Operation 1+2+3        intR = (int) C.getresult ();        System.out.println (R); Assertequals (6, R); } @Test Public voidTestjian () {//Subtraction        intn = 3;//Number of Operations        int[] Num1 = {1, 2, 3};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] No = {2, 2};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation        intR = (int) C.getresult ();        System.out.println (R); Assertequals (-4, R); } @Test Public voidTestmulti () {//multiplication        intn = 3;//Number of Operations        int[] Num1 = {2, 2, 3};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] No = {3, 3};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 2*2*3        intR = (int) C.getresult ();        System.out.println (R); Assertequals (12, R); } @Test Public voidTestdiv () {//Division        intn = 2;//Number of Operations        int[] Num1 = {2, 2, 3};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] no = {4};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//operation 2/2        DoubleR =C.getresult ();        System.out.println (R); Assertequals (1, r,100); } @Test (Expected= ArithmeticException.class)     Public voidTestzero () {//divide by 0 .        intn = 3;//Number of Operations        int[] Num1 = {1, 0, 3};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] No = {4, 1};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 1/0+3} @Test Public voidTestnormal () {//Mixed Operations        intn = 5;//Number of Operations        int[] Num1 = {1, 2, 3, 4, 4};//Number of operands        Char[] op = {', ' + ', '-', ' * ', '/'};//operator        int[] No = {1, 3,2,4};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 1+2*3        intR = (int) C.getresult ();        System.out.println (R); Assertequals (6, R); }        }
Test Class

-this assignment is done with my partner Lin Juewen, and the detailed test code is here http://www.cnblogs.com/wzhz/

-(1) Black box test. This test is primarily to test the functionality and use of the code in terms of user perspective, as well as the presence of some external environment-related issues. such as:

-(2) white box test. Detailed examination of the procedural details of the software. The method is to put the test object

As an open box, it allows testers to design or select test Cases and test all the logical paths of the program, using the logical structure and related information inside the program. This is done by overwriting the path with conditional overrides. This is primarily a test of a module core with computational capabilities. (Because the computer screen is small, it only intercepts most of it.) Because this is the first time to do this test unit, so there are a lot of deficiencies, will gradually improve.

Exercise 5.1 Update--Arithmetic testing and encapsulation

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.