0c16a45a
[mandjemb]
test
|
1
2
3
4
5
6
7
8
|
package kernel.test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import kernel.Cell;
|
eb07e5e3
[mandjemb]
avec serialisation
|
9
|
import kernel.exception.CreateCycleException;
|
4186cd92
Remi
fix tests
|
10
|
import kernel.exception.InvalidIntervalException;
|
eb07e5e3
[mandjemb]
avec serialisation
|
11
|
import kernel.function.Average;
|
0c16a45a
[mandjemb]
test
|
12
13
14
15
|
import kernel.function.Sum;
import kernel.operation.Addition;
|
eb07e5e3
[mandjemb]
avec serialisation
|
16
|
public class CellTest {
|
0c16a45a
[mandjemb]
test
|
17
18
|
@org.junit.Test
|
4186cd92
Remi
fix tests
|
19
|
public void CreateCellValueTest() throws InvalidIntervalException {
|
0c16a45a
[mandjemb]
test
|
20
21
22
23
24
25
26
27
28
|
Cell A1= new Cell("A",1,25.);
assertEquals(A1.getValue(),25.,0);
assertEquals(A1.containFormula(),false);
assertEquals(A1.getUsedIn().size(),0);
assertEquals(A1.getId(),"A1");
}
@org.junit.Test
|
4186cd92
Remi
fix tests
|
29
|
public void CreateCellBinaryOperationTest() throws CreateCycleException, InvalidIntervalException {
|
0c16a45a
[mandjemb]
test
|
30
31
32
33
34
35
36
37
38
39
40
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,35.);
Cell A3= new Cell("A",3,new Addition(A1,A2));
assertEquals(A3.getValue(),60.,0);
assertEquals(A3.containFormula(),true);
assertEquals(A3.getUsedIn().size(),0);
assertEquals(A3.getId(),"A3");
|
eb07e5e3
[mandjemb]
avec serialisation
|
41
|
assertEquals(A3.toString(),"A1+A2");
|
0c16a45a
[mandjemb]
test
|
42
43
44
45
46
47
48
49
|
assertEquals(A1.getUsedIn().size(),1);
assertEquals(A2.getUsedIn().size(),1);
}
@org.junit.Test
|
4186cd92
Remi
fix tests
|
50
|
public void CreateCellFunctionTest() throws CreateCycleException, InvalidIntervalException {
|
0c16a45a
[mandjemb]
test
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,35.);
Cell A3= new Cell("A",3,new Addition(A1,A2));
Cell A5= new Cell("A",5,45.);
List<Cell> sumList = new ArrayList<>();
sumList.add(A1);
sumList.add(A2);
sumList.add(A3);
sumList.add(A5);
Cell A4= new Cell("A",4,new Sum(sumList));
assertEquals(A4.getValue(),165.,0);
assertEquals(A4.containFormula(),true);
assertEquals(A4.getUsedIn().size(),0);
assertEquals(A4.toString(),"SOMME(A1,A2,A3,A5)");
|
eb07e5e3
[mandjemb]
avec serialisation
|
68
|
assertEquals(A4.getDevelopedFormula(),"SOMME(A1,A2,(A1+A2),A5)");
|
0c16a45a
[mandjemb]
test
|
69
70
71
72
73
74
75
76
77
78
|
assertEquals(A1.getUsedIn().size(),2);
assertEquals(A2.getUsedIn().size(),2);
assertEquals(A3.getUsedIn().size(),1);
assertEquals(A5.getUsedIn().size(),1);
}
@org.junit.Test
|
4186cd92
Remi
fix tests
|
79
|
public void ModifyCellValueTest() throws CreateCycleException, InvalidIntervalException {
|
0c16a45a
[mandjemb]
test
|
80
81
82
83
84
85
86
87
88
89
90
91
92
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,35.);
Cell A3= new Cell("A",3,new Addition(A1,A2));
assertEquals(A1.getValue(),25.,0);
assertEquals(A2.getValue(),35.,0);
assertEquals(A3.getValue(),60.,0);
A1.setValue(45.);
assertEquals(A1.getValue(),45.,0);
assertEquals(A3.getValue(),80.,0);
}
@org.junit.Test
|
4186cd92
Remi
fix tests
|
93
|
public void ModifyCellFormulaTest() throws CreateCycleException, InvalidIntervalException {
|
0c16a45a
[mandjemb]
test
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,35.);
Cell A3= new Cell("A",3,new Addition(A1,A2));
Cell A5= new Cell("A",5,45.);
List<Cell> sumList = new ArrayList<>();
sumList.add(A1);
sumList.add(A2);
sumList.add(A3);
sumList.add(A5);
Cell A4= new Cell("A",4,new Sum(sumList));
assertEquals(A4.getValue(),165.,0);
assertEquals(A4.containFormula(),true);
assertEquals(A4.getUsedIn().size(),0);
|
eb07e5e3
[mandjemb]
avec serialisation
|
109
110
111
112
113
|
assertEquals(A1.getUsedIn().size(),2);
assertEquals(A2.getUsedIn().size(),2);
assertEquals(A3.getUsedIn().size(),1);
assertEquals(A5.getUsedIn().size(),1);
|
0c16a45a
[mandjemb]
test
|
114
115
116
117
118
119
120
121
|
assertEquals(A1.containFormula(),false);
A1.setFormula(new Addition(A2,A5));
assertEquals(A1.containFormula(),true);
assertEquals(A1.getValue(),80.,0);
assertEquals(A3.getValue(),115.,0);
assertEquals(A4.getValue(),275.,0);
|
eb07e5e3
[mandjemb]
avec serialisation
|
122
|
|
0c16a45a
[mandjemb]
test
|
123
124
|
|
eb07e5e3
[mandjemb]
avec serialisation
|
125
126
127
128
|
assertEquals(A1.toString(),"A2+A5");
assertEquals(A1.getDevelopedFormula(),"(A2+A5)");
assertEquals(A4.toString(),"SOMME(A1,A2,A3,A5)");
assertEquals(A4.getDevelopedFormula(),"SOMME((A2+A5),A2,((A2+A5)+A2),A5)");
|
0c16a45a
[mandjemb]
test
|
129
130
131
132
133
134
135
136
137
138
|
assertEquals(A1.getUsedIn().size(),2);
assertEquals(A2.getUsedIn().size(),3);
assertEquals(A3.getUsedIn().size(),1);
assertEquals(A5.getUsedIn().size(),2);
}
|
eb07e5e3
[mandjemb]
avec serialisation
|
139
|
@org.junit.Test(expected=CreateCycleException.class)
|
4186cd92
Remi
fix tests
|
140
|
public void DirectCycleBynaryOperation() throws CreateCycleException, InvalidIntervalException {
|
eb07e5e3
[mandjemb]
avec serialisation
|
141
142
143
144
145
146
147
148
149
150
151
152
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,35.);
try{
A1.setFormula(new Addition(A1,A2));
}
catch(CreateCycleException ex){
throw ex;
}
}
@org.junit.Test(expected=CreateCycleException.class)
|
4186cd92
Remi
fix tests
|
153
|
public void DirectCycleFunction() throws CreateCycleException, InvalidIntervalException {
|
eb07e5e3
[mandjemb]
avec serialisation
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
Cell A2= new Cell("A",2,25.);
Cell B2= new Cell("B",2,35.);
Cell A3= new Cell("A",3,0.5);
List<Cell> sumList = new ArrayList<>();
sumList.add(A2);
sumList.add(B2);
sumList.add(A3);
try{
B2.setFormula(new Sum(sumList));
}
catch(CreateCycleException ex){
throw ex;
}
}
@org.junit.Test(expected=CreateCycleException.class)
|
4186cd92
Remi
fix tests
|
171
|
public void IndirectCycle() throws CreateCycleException, InvalidIntervalException {
|
eb07e5e3
[mandjemb]
avec serialisation
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
Cell A1= new Cell("A",1,25.);
Cell A2= new Cell("A",2,5.);
Cell B4= new Cell("B",4,new Addition(A1,A2));
Cell A4= new Cell("A",4,0.);
Cell A3= new Cell("A",3,0.5);
Cell B2= new Cell("B",2,12.);
List<Cell> sumList = new ArrayList<>();
sumList.add(A2);
sumList.add(B2);
sumList.add(A3);
Cell B6= new Cell("B",6,new Sum(sumList));
List<Cell> averageList = new ArrayList<>();
averageList.add(B6);
averageList.add(B4);
averageList.add(A4);
Cell C6= new Cell("C",6,new Average(averageList));
try{
B2.setFormula(new Addition(A1,C6));
}
catch(CreateCycleException ex){
throw ex;
}
}
|
0c16a45a
[mandjemb]
test
|
199
200
|
}
|