FunctionTest.java
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package kernel.test;
import kernel.Cell;
import kernel.Grid;
import kernel.LanguageEnum;
import kernel.function.Average;
import kernel.function.Sum;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class FunctionTest {
private List<Cell> cells;
@Before
public void initData() {
Grid.language = LanguageEnum.EN;
this.cells = new ArrayList<>();
Cell a1 = new Cell("A", 1, 10.);
Cell a2 = new Cell("A", 2, 0.);
Cell a3 = new Cell("A", 3, 20.);
this.cells.add(a1);
this.cells.add(a2);
this.cells.add(a3);
}
@Test
public void testSum() {
Sum sum = new Sum(this.cells);
assertNotNull(sum);
assertEquals(30, sum.eval(), 0);
assertEquals("SUM(A1,A2,A3)", sum.toString());
}
@Test
public void testAverage() {
Average average = new Average(this.cells);
assertNotNull(average);
assertEquals(10, average.eval(), 0);
assertEquals("AVERAGE(A1,A2,A3)", average.toString());
}
}