Commit 0c16a45a703811bf9458d1e101499f20fc3781c4
1 parent
94ba86ff
test
Showing
6 changed files
with
142 additions
and
0 deletions
Show diff stats
.classpath
... | ... | @@ -2,5 +2,6 @@ |
2 | 2 | <classpath> |
3 | 3 | <classpathentry kind="src" path="src"/> |
4 | 4 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
5 | + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | |
5 | 6 | <classpathentry kind="output" path="bin"/> |
6 | 7 | </classpath> | ... | ... |
src/kernel/Cell.java
src/kernel/function/Average.java
src/kernel/operation/Addition.java
... | ... | @@ -0,0 +1,133 @@ |
1 | +package kernel.test; | |
2 | + | |
3 | +import static org.junit.Assert.*; | |
4 | + | |
5 | +import java.util.ArrayList; | |
6 | +import java.util.List; | |
7 | + | |
8 | +import kernel.Cell; | |
9 | +import kernel.function.Sum; | |
10 | +import kernel.operation.Addition; | |
11 | + | |
12 | + | |
13 | +public class Test { | |
14 | + | |
15 | + @org.junit.Test | |
16 | + public void CreateCellValueTest() { | |
17 | + Cell A1= new Cell("A",1,25.); | |
18 | + assertEquals(A1.getValue(),25.,0); | |
19 | + assertEquals(A1.containFormula(),false); | |
20 | + assertEquals(A1.getUsedIn().size(),0); | |
21 | + assertEquals(A1.getId(),"A1"); | |
22 | + } | |
23 | + | |
24 | + | |
25 | + @org.junit.Test | |
26 | + public void CreateCellBinaryOperationTest() { | |
27 | + Cell A1= new Cell("A",1,25.); | |
28 | + Cell A2= new Cell("A",2,35.); | |
29 | + | |
30 | + | |
31 | + Cell A3= new Cell("A",3,new Addition(A1,A2)); | |
32 | + | |
33 | + assertEquals(A3.getValue(),60.,0); | |
34 | + assertEquals(A3.containFormula(),true); | |
35 | + assertEquals(A3.getUsedIn().size(),0); | |
36 | + assertEquals(A3.getId(),"A3"); | |
37 | + | |
38 | + assertEquals(A3.toString(),"A1 + A2"); | |
39 | + assertEquals(A1.getUsedIn().size(),1); | |
40 | + assertEquals(A2.getUsedIn().size(),1); | |
41 | + | |
42 | + | |
43 | + } | |
44 | + | |
45 | + | |
46 | + @org.junit.Test | |
47 | + public void CreateCellFunctionTest() { | |
48 | + Cell A1= new Cell("A",1,25.); | |
49 | + Cell A2= new Cell("A",2,35.); | |
50 | + Cell A3= new Cell("A",3,new Addition(A1,A2)); | |
51 | + Cell A5= new Cell("A",5,45.); | |
52 | + List<Cell> sumList = new ArrayList<>(); | |
53 | + sumList.add(A1); | |
54 | + sumList.add(A2); | |
55 | + sumList.add(A3); | |
56 | + sumList.add(A5); | |
57 | + Cell A4= new Cell("A",4,new Sum(sumList)); | |
58 | + | |
59 | + assertEquals(A4.getValue(),165.,0); | |
60 | + assertEquals(A4.containFormula(),true); | |
61 | + assertEquals(A4.getUsedIn().size(),0); | |
62 | + | |
63 | + | |
64 | + assertEquals(A4.toString(),"SOMME(A1,A2,A3,A5)"); | |
65 | + assertEquals(A4.getDevelopedFormula(),"SOMME(A1,A2,A1 + A2,A5)"); | |
66 | + assertEquals(A1.getUsedIn().size(),2); | |
67 | + assertEquals(A2.getUsedIn().size(),2); | |
68 | + assertEquals(A3.getUsedIn().size(),1); | |
69 | + assertEquals(A5.getUsedIn().size(),1); | |
70 | + | |
71 | + | |
72 | + } | |
73 | + | |
74 | + | |
75 | + @org.junit.Test | |
76 | + public void ModifyCellValueTest() { | |
77 | + Cell A1= new Cell("A",1,25.); | |
78 | + Cell A2= new Cell("A",2,35.); | |
79 | + Cell A3= new Cell("A",3,new Addition(A1,A2)); | |
80 | + assertEquals(A1.getValue(),25.,0); | |
81 | + assertEquals(A2.getValue(),35.,0); | |
82 | + assertEquals(A3.getValue(),60.,0); | |
83 | + A1.setValue(45.); | |
84 | + assertEquals(A1.getValue(),45.,0); | |
85 | + assertEquals(A3.getValue(),80.,0); | |
86 | + | |
87 | + } | |
88 | + | |
89 | + @org.junit.Test | |
90 | + public void ModifyCellFormulaTest() { | |
91 | + Cell A1= new Cell("A",1,25.); | |
92 | + Cell A2= new Cell("A",2,35.); | |
93 | + Cell A3= new Cell("A",3,new Addition(A1,A2)); | |
94 | + Cell A5= new Cell("A",5,45.); | |
95 | + List<Cell> sumList = new ArrayList<>(); | |
96 | + sumList.add(A1); | |
97 | + sumList.add(A2); | |
98 | + sumList.add(A3); | |
99 | + sumList.add(A5); | |
100 | + Cell A4= new Cell("A",4,new Sum(sumList)); | |
101 | + | |
102 | + assertEquals(A4.getValue(),165.,0); | |
103 | + assertEquals(A4.containFormula(),true); | |
104 | + assertEquals(A4.getUsedIn().size(),0); | |
105 | + | |
106 | + assertEquals(A1.containFormula(),false); | |
107 | + A1.setFormula(new Addition(A2,A5)); | |
108 | + assertEquals(A1.containFormula(),true); | |
109 | + | |
110 | + assertEquals(A1.getValue(),80.,0); | |
111 | + assertEquals(A3.getValue(),115.,0); | |
112 | + assertEquals(A4.getValue(),275.,0); | |
113 | + | |
114 | + assertEquals(A1.getUsedIn().size(),2); | |
115 | + assertEquals(A2.getUsedIn().size(),2); | |
116 | + assertEquals(A3.getUsedIn().size(),1); | |
117 | + assertEquals(A5.getUsedIn().size(),1); | |
118 | + | |
119 | + | |
120 | + assertEquals(A1.toString(),"A2 + A5"); | |
121 | + assertEquals(A4.getDevelopedFormula(),"SOMME(A2 + A5,A2,A1 + A2,A5)"); | |
122 | + | |
123 | + | |
124 | + assertEquals(A1.getUsedIn().size(),2); | |
125 | + assertEquals(A2.getUsedIn().size(),3); | |
126 | + assertEquals(A3.getUsedIn().size(),1); | |
127 | + assertEquals(A5.getUsedIn().size(),2); | |
128 | + | |
129 | + | |
130 | + } | |
131 | + | |
132 | + | |
133 | +} | ... | ... |