File tree Expand file tree Collapse file tree 4 files changed +186
-18
lines changed
main/ma/ac/insea/calculator Expand file tree Collapse file tree 4 files changed +186
-18
lines changed Original file line number Diff line number Diff line change 1- # Compiled class file
2- * .class
31
4- # Log file
5- * .log
2+ # Created by https://www.gitignore.io/api/eclipse
3+ # Edit at https://www.gitignore.io/?templates=eclipse
64
7- # BlueJ files
8- * .ctxt
5+ # ## Eclipse ###
6+ .metadata
7+ bin /
8+ tmp /
9+ * .tmp
10+ * .bak
11+ * .swp
12+ * ~.nib
13+ local.properties
14+ .settings /
15+ .loadpath
16+ .recommenders
917
10- # Mobile Tools for Java (J2ME)
11- .mtj.tmp /
18+ # External tool builders
19+ .externalToolBuilders /
1220
13- # Package Files #
14- * .jar
15- * .war
16- * .nar
17- * .ear
18- * .zip
19- * .tar.gz
20- * .rar
21+ # Locally stored "Eclipse launch configurations"
22+ * .launch
2123
22- # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23- hs_err_pid *
24+ # PyDev specific (Python IDE for Eclipse)
25+ * .pydevproject
26+
27+ # CDT-specific (C/C++ Development Tooling)
28+ .cproject
29+
30+ # CDT- autotools
31+ .autotools
32+
33+ # Java annotation processor (APT)
34+ .factorypath
35+
36+ # PDT-specific (PHP Development Tools)
37+ .buildpath
38+
39+ # sbteclipse plugin
40+ .target
41+
42+ # Tern plugin
43+ .tern-project
44+
45+ # TeXlipse plugin
46+ .texlipse
47+
48+ # STS (Spring Tool Suite)
49+ .springBeans
50+
51+ # Code Recommenders
52+ .recommenders /
53+
54+ # Annotation Processing
55+ .apt_generated /
56+
57+ # Scala IDE specific (Scala & Java development for Eclipse)
58+ .cache-main
59+ .scala_dependencies
60+ .worksheet
61+
62+ # ## Eclipse Patch ###
63+ # Eclipse Core
64+ .project
65+
66+ # JDT-specific (Eclipse Java Development Tools)
67+ .classpath
68+
69+ # Annotation Processing
70+ .apt_generated
71+
72+ .sts4-cache /
73+
74+ # End of https://www.gitignore.io/api/eclipse
Original file line number Diff line number Diff line change 1+ package ma .ac .insea .calculator .implementations ;
2+
3+ import ma .ac .insea .calculator .interfaces .ICalculator ;
4+
5+ public class CalculatorImpl implements ICalculator {
6+
7+ @ Override
8+ public int add (int a , int b ) {
9+ // TODO Auto-generated method stub
10+ if (b >0 ){
11+ while (b -- >0 ){
12+ a ++;
13+
14+ }
15+ return a ;
16+ }
17+ else
18+ if (a > 0 ){
19+ while (a -- > 0 ){
20+ b ++;
21+
22+ }
23+ return b ;
24+ }
25+ else
26+ while (b ++ < 0 ){
27+ a --;
28+ }
29+ return a ;
30+ }
31+
32+ @ Override
33+ public int substact (int a , int b ) {
34+ // TODO Auto-generated method stub
35+ return add (a ,b );
36+ }
37+
38+ @ Override
39+ public float divide (int a , int b ) {
40+ // TODO Auto-generated method stub
41+ return 0 ;
42+ }
43+
44+ @ Override
45+ public int multiply (int a , int b ) {
46+ // TODO Auto-generated method stub
47+ return 0 ;
48+ }
49+
50+ }
Original file line number Diff line number Diff line change 1+ package ma .ac .insea .calculator .interfaces ;
2+
3+ public interface ICalculator {
4+ public int add (int a , int b );
5+ public int substact (int a , int b );
6+ public float divide (int a , int b );
7+ public int multiply (int a , int b );
8+ }
Original file line number Diff line number Diff line change 1+ package CalculatorImpl ;
2+
3+ import static org .junit .Assert .*;
4+
5+ import org .junit .Test ;
6+
7+ import ma .ac .insea .calculator .implementations .CalculatorImpl ;
8+
9+ public class CalculatorTest {
10+
11+ @ Test
12+ public void testAdd () {
13+ CalculatorImpl cal = new CalculatorImpl ();
14+ int a = 5 , b =7 ;
15+ if (cal .add (a , b ) != 12 )
16+ fail ("tous positif" );
17+
18+ a = -5 ; b =7 ;
19+ if (cal .add (a , b ) != 2 )
20+ fail ("a est negatif" );
21+
22+ a = 5 ; b =-7 ;
23+ if (cal .add (a , b ) != -2 )
24+ fail ("b est negatif" );
25+
26+ a = 0 ; b =7 ;
27+ if (cal .add (a , b ) != 7 )
28+ fail ("a est nul et b positif" );
29+
30+ a = 0 ; b =-7 ;
31+ if (cal .add (a , b ) != -7 )
32+ fail ("a est nul et b negatif" );
33+
34+ a = 5 ; b =0 ;
35+ if (cal .add (a , b ) != 5 )
36+ fail ("a est positif et b nul" );
37+
38+ a = -5 ; b =0 ;
39+ if (cal .add (a , b ) != -5 )
40+ fail ("a est negatif et b nul" );
41+
42+ }
43+
44+ @ Test
45+ public void testSubstact () {
46+ testAdd ();
47+ }
48+
49+ @ Test
50+ public void testDivide () {
51+ fail ("Not yet implemented" );
52+ }
53+
54+ @ Test
55+ public void testMultiply () {
56+ fail ("Not yet implemented" );
57+ }
58+
59+ }
You can’t perform that action at this time.
0 commit comments