Commit 4186cd928855466780363d297d1e150b43c14822

Authored by Remi
1 parent ebf0bdb2

fix tests

src/app/Application.java
@@ -4,7 +4,7 @@ import kernel.Cell; @@ -4,7 +4,7 @@ import kernel.Cell;
4 import kernel.Grid; 4 import kernel.Grid;
5 import kernel.exception.CellNotFoundException; 5 import kernel.exception.CellNotFoundException;
6 import kernel.exception.CreateCycleException; 6 import kernel.exception.CreateCycleException;
7 -import kernel.exception.InvalidIntervalLineColumnEception; 7 +import kernel.exception.InvalidIntervalException;
8 import kernel.function.Average; 8 import kernel.function.Average;
9 import kernel.function.Sum; 9 import kernel.function.Sum;
10 import kernel.operation.Addition; 10 import kernel.operation.Addition;
@@ -46,7 +46,7 @@ public class Application { @@ -46,7 +46,7 @@ public class Application {
46 averageList.add(grid.getCell("B", 1)); 46 averageList.add(grid.getCell("B", 1));
47 47
48 grid.createCell("B", 2, new Average(averageList)); 48 grid.createCell("B", 2, new Average(averageList));
49 - } catch (CellNotFoundException | CreateCycleException | InvalidIntervalLineColumnEception exception) { 49 + } catch (CellNotFoundException | CreateCycleException | InvalidIntervalException exception) {
50 System.out.println(exception.getMessage()); 50 System.out.println(exception.getMessage());
51 } 51 }
52 52
src/ihm/TablooProto.java
@@ -25,7 +25,7 @@ import javax.swing.table.TableColumn; @@ -25,7 +25,7 @@ import javax.swing.table.TableColumn;
25 25
26 import kernel.Grid; 26 import kernel.Grid;
27 import kernel.exception.CellNotFoundException; 27 import kernel.exception.CellNotFoundException;
28 -import kernel.exception.InvalidIntervalLineColumnEception; 28 +import kernel.exception.InvalidIntervalException;
29 29
30 public class TablooProto extends JPanel { 30 public class TablooProto extends JPanel {
31 31
@@ -207,7 +207,7 @@ public class TablooProto extends JPanel { @@ -207,7 +207,7 @@ public class TablooProto extends JPanel {
207 else 207 else
208 try { 208 try {
209 calc.createCell(this.getColumnName(col), row+1, Double.parseDouble((String)value)); 209 calc.createCell(this.getColumnName(col), row+1, Double.parseDouble((String)value));
210 - } catch (InvalidIntervalLineColumnEception e) { 210 + } catch (InvalidIntervalException e) {
211 // TODO Auto-generated catch block 211 // TODO Auto-generated catch block
212 e.printStackTrace(); 212 e.printStackTrace();
213 } 213 }
src/kernel/Cell.java
1 package kernel; 1 package kernel;
2 2
3 import kernel.exception.CreateCycleException; 3 import kernel.exception.CreateCycleException;
4 -import kernel.exception.InvalidIntervalLineColumnEception; 4 +import kernel.exception.InvalidIntervalException;
5 5
6 import java.io.Serializable; 6 import java.io.Serializable;
7 import java.util.ArrayList; 7 import java.util.ArrayList;
8 import java.util.List; 8 import java.util.List;
9 9
10 public class Cell implements Serializable { 10 public class Cell implements Serializable {
11 -  
12 - private static final long serialVersionUID = 1L;  
13 - private static final int MAX_LIGNES = 20;  
14 -  
15 - private String column;  
16 - private int line;  
17 - private double value;  
18 - private Formula formula;  
19 - private List<Cell> usedIn = new ArrayList<>();  
20 -  
21 - public Cell(String column, int line, double value) throws InvalidIntervalLineColumnEception {  
22 - column = column.toUpperCase();  
23 - if (!validateInterval(column, line))  
24 - throw new InvalidIntervalLineColumnEception();  
25 -  
26 - this.column = column;  
27 - this.line = line;  
28 - this.setValue(value);  
29 - }  
30 -  
31 - public Cell(String column, int line, Formula formula)  
32 - throws CreateCycleException, InvalidIntervalLineColumnEception {  
33 - column = column.toUpperCase();  
34 - if (!validateInterval(column, line))  
35 - throw new InvalidIntervalLineColumnEception();  
36 -  
37 - this.column = column;  
38 - this.line = line;  
39 - this.setFormula(formula);  
40 - }  
41 -  
42 - public double getValue() {  
43 - return this.value;  
44 - }  
45 -  
46 - public Formula getFormula() {  
47 - return this.formula;  
48 - }  
49 -  
50 - public String getDevelopedFormula() {  
51 - return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();  
52 - }  
53 -  
54 - public String getId() {  
55 - return this.column + this.line;  
56 - }  
57 -  
58 - public List<Cell> getUsedIn() {  
59 - return this.usedIn;  
60 - }  
61 -  
62 - public String toString() {  
63 - return this.containFormula() ? this.formula.toString() : this.getId();  
64 - }  
65 -  
66 - public void updateValue() {  
67 - if (this.containFormula())  
68 - this.value = this.formula.eval();  
69 - }  
70 -  
71 - public boolean containFormula() {  
72 - return this.formula != null;  
73 - }  
74 -  
75 - public void setFormula(Formula formula) throws CreateCycleException {  
76 - if (formula.createCycle(this))  
77 - throw new CreateCycleException();  
78 -  
79 - this.formula = formula;  
80 - for (Cell cell : this.formula.getUtilisedCells())  
81 - cell.usedIn.add(this);  
82 - this.updateValue();  
83 - this.spreadValue();  
84 - }  
85 -  
86 - public void setValue(double value) {  
87 - this.value = value;  
88 - this.formula = null;  
89 - this.spreadValue();  
90 - }  
91 -  
92 - private void spreadValue() {  
93 - for (Cell cell : this.usedIn) {  
94 - cell.updateValue();  
95 - cell.spreadValue();  
96 - }  
97 - }  
98 -  
99 - private boolean validateInterval(String column, int line) {  
100 - return line >= 1 && line <= MAX_LIGNES && column.compareTo("A") >= 0 && column.compareTo("Z") <= 0;  
101 - } 11 +
  12 + private static final long serialVersionUID = 1L;
  13 + private static final int MAX_LIGNES = 20;
  14 +
  15 + private String column;
  16 + private int line;
  17 + private double value;
  18 + private Formula formula;
  19 + private List<Cell> usedIn = new ArrayList<>();
  20 +
  21 + public Cell(String column, int line, double value) throws InvalidIntervalException {
  22 + column = column.toUpperCase();
  23 + if (!validateInterval(column, line))
  24 + throw new InvalidIntervalException();
  25 +
  26 + this.column = column;
  27 + this.line = line;
  28 + this.setValue(value);
  29 + }
  30 +
  31 + public Cell(String column, int line, Formula formula)
  32 + throws CreateCycleException, InvalidIntervalException {
  33 + column = column.toUpperCase();
  34 + if (!validateInterval(column, line))
  35 + throw new InvalidIntervalException();
  36 +
  37 + this.column = column;
  38 + this.line = line;
  39 + this.setFormula(formula);
  40 + }
  41 +
  42 + public double getValue() {
  43 + return this.value;
  44 + }
  45 +
  46 + public Formula getFormula() {
  47 + return this.formula;
  48 + }
  49 +
  50 + public String getDevelopedFormula() {
  51 + return this.containFormula() ? this.formula.getDevelopedFormula() : this.getId();
  52 + }
  53 +
  54 + public String getId() {
  55 + return this.column + this.line;
  56 + }
  57 +
  58 + public List<Cell> getUsedIn() {
  59 + return this.usedIn;
  60 + }
  61 +
  62 + public String toString() {
  63 + return this.containFormula() ? this.formula.toString() : this.getId();
  64 + }
  65 +
  66 + public void updateValue() {
  67 + if (this.containFormula())
  68 + this.value = this.formula.eval();
  69 + }
  70 +
  71 + public boolean containFormula() {
  72 + return this.formula != null;
  73 + }
  74 +
  75 + public void setFormula(Formula formula) throws CreateCycleException {
  76 + if (formula.createCycle(this))
  77 + throw new CreateCycleException();
  78 +
  79 + this.formula = formula;
  80 + for (Cell cell : this.formula.getUtilisedCells())
  81 + cell.usedIn.add(this);
  82 + this.updateValue();
  83 + this.spreadValue();
  84 + }
  85 +
  86 + public void setValue(double value) {
  87 + this.value = value;
  88 + this.formula = null;
  89 + this.spreadValue();
  90 + }
  91 +
  92 + private void spreadValue() {
  93 + for (Cell cell : this.usedIn) {
  94 + cell.updateValue();
  95 + cell.spreadValue();
  96 + }
  97 + }
  98 +
  99 + private boolean validateInterval(String column, int line) {
  100 + return line >= 1 && line <= MAX_LIGNES && column.compareTo("A") >= 0 && column.compareTo("Z") <= 0;
  101 + }
102 } 102 }
src/kernel/Formula.java
@@ -3,14 +3,14 @@ package kernel; @@ -3,14 +3,14 @@ package kernel;
3 import java.util.List; 3 import java.util.List;
4 4
5 public interface Formula { 5 public interface Formula {
6 -  
7 - String getDevelopedFormula();  
8 -  
9 - String toString();  
10 -  
11 - double eval();  
12 -  
13 - boolean createCycle(Cell cell);  
14 -  
15 - List<Cell> getUtilisedCells(); 6 +
  7 + String getDevelopedFormula();
  8 +
  9 + String toString();
  10 +
  11 + double eval();
  12 +
  13 + boolean createCycle(Cell cell);
  14 +
  15 + List<Cell> getUtilisedCells();
16 } 16 }
src/kernel/Grid.java
@@ -2,7 +2,7 @@ package kernel; @@ -2,7 +2,7 @@ package kernel;
2 2
3 import kernel.exception.CellNotFoundException; 3 import kernel.exception.CellNotFoundException;
4 import kernel.exception.CreateCycleException; 4 import kernel.exception.CreateCycleException;
5 -import kernel.exception.InvalidIntervalLineColumnEception; 5 +import kernel.exception.InvalidIntervalException;
6 6
7 import java.io.Serializable; 7 import java.io.Serializable;
8 import java.util.ArrayList; 8 import java.util.ArrayList;
@@ -11,86 +11,86 @@ import java.util.List; @@ -11,86 +11,86 @@ import java.util.List;
11 import java.util.Map; 11 import java.util.Map;
12 12
13 public class Grid implements Serializable { 13 public class Grid implements Serializable {
14 -  
15 - private static final long serialVersionUID = 1L;  
16 -  
17 - private Map<String, Cell> cells = new HashMap<>();  
18 - public static LanguageEnum language = LanguageEnum.FR;  
19 - private List<Integer> listLine = new ArrayList<Integer>();  
20 - private List<Integer> listColumn=new ArrayList<Integer>();  
21 -  
22 - public void saveDifferentLineColumn(String column, int line) {  
23 - if (!this.listLine.contains(line))  
24 - listLine.add(line);  
25 - if (!this.listColumn.contains((int)column.charAt(0)))  
26 - listColumn.add((int)column.charAt(0)- (int)'A' + 1);  
27 -  
28 -  
29 - }  
30 - public String createCell(String column, int line, double value) throws InvalidIntervalLineColumnEception {  
31 - String id = this.getCellId(column, line);  
32 - Cell cell = new Cell(column, line, value);  
33 -  
34 - this.cells.put(id, cell);  
35 - saveDifferentLineColumn(column,line);  
36 - return id;  
37 - }  
38 -  
39 - public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalLineColumnEception {  
40 - String id = this.getCellId(column, line);  
41 - Cell cell = new Cell(column, line, formula);  
42 -  
43 - this.cells.put(id, cell);  
44 - saveDifferentLineColumn(column,line);  
45 - return id;  
46 - }  
47 -  
48 - public void setValue(String column, int line, double value) throws CellNotFoundException {  
49 - this.getCell(column, line).setValue(value);  
50 - }  
51 -  
52 - public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,  
53 - CreateCycleException {  
54 - this.getCell(column, line).setFormula(formula);  
55 - }  
56 -  
57 - public Cell getCell(String column, int line) throws CellNotFoundException {  
58 - Cell cell = this.cells.get(this.getCellId(column, line));  
59 -  
60 - if (cell != null)  
61 - return cell;  
62 - else  
63 - throw new CellNotFoundException();  
64 - }  
65 -  
66 - public List<Cell> getCells() {  
67 - return new ArrayList<>(this.cells.values());  
68 - }  
69 -  
70 - public List<String> getCellsId() {  
71 - return new ArrayList<>(this.cells.keySet());  
72 - }  
73 -  
74 - public double getValue(String column, int line) throws CellNotFoundException {  
75 - return this.getCell(column, line).getValue();  
76 - }  
77 -  
78 - public String getFormulaAsString(String column, int line) throws CellNotFoundException {  
79 - return this.getCell(column, line).toString();  
80 - }  
81 -  
82 - public String getDevelopedFormula(String column, int line) throws CellNotFoundException {  
83 - return this.getCell(column, line).getDevelopedFormula();  
84 - }  
85 -  
86 - private String getCellId(String column, int line) {  
87 - return column + line;  
88 - }  
89 - public List<Integer> getTotalColumn() {  
90 - return listColumn;  
91 - }  
92 - public List<Integer> getTotalLine() {  
93 - return listLine;  
94 -  
95 - } 14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + private Map<String, Cell> cells = new HashMap<>();
  18 + public static LanguageEnum language = LanguageEnum.FR;
  19 + private List<Integer> listLine = new ArrayList<>();
  20 + private List<Integer> listColumn = new ArrayList<>();
  21 +
  22 + public void saveDifferentLineColumn(String column, int line) {
  23 + if (!this.listLine.contains(line))
  24 + listLine.add(line);
  25 + if (!this.listColumn.contains((int) column.charAt(0)))
  26 + listColumn.add((int) column.charAt(0) - (int) 'A' + 1);
  27 + }
  28 +
  29 + public String createCell(String column, int line, double value) throws InvalidIntervalException {
  30 + String id = this.getCellId(column, line);
  31 + Cell cell = new Cell(column, line, value);
  32 +
  33 + this.cells.put(id, cell);
  34 + saveDifferentLineColumn(column, line);
  35 + return id;
  36 + }
  37 +
  38 + public String createCell(String column, int line, Formula formula) throws CreateCycleException, InvalidIntervalException {
  39 + String id = this.getCellId(column, line);
  40 + Cell cell = new Cell(column, line, formula);
  41 +
  42 + this.cells.put(id, cell);
  43 + saveDifferentLineColumn(column, line);
  44 + return id;
  45 + }
  46 +
  47 + public void setValue(String column, int line, double value) throws CellNotFoundException {
  48 + this.getCell(column, line).setValue(value);
  49 + }
  50 +
  51 + public void setFormula(String column, int line, Formula formula) throws CellNotFoundException,
  52 + CreateCycleException {
  53 + this.getCell(column, line).setFormula(formula);
  54 + }
  55 +
  56 + public Cell getCell(String column, int line) throws CellNotFoundException {
  57 + Cell cell = this.cells.get(this.getCellId(column, line));
  58 +
  59 + if (cell != null)
  60 + return cell;
  61 + else
  62 + throw new CellNotFoundException();
  63 + }
  64 +
  65 + public List<Cell> getCells() {
  66 + return new ArrayList<>(this.cells.values());
  67 + }
  68 +
  69 + public List<String> getCellsId() {
  70 + return new ArrayList<>(this.cells.keySet());
  71 + }
  72 +
  73 + public double getValue(String column, int line) throws CellNotFoundException {
  74 + return this.getCell(column, line).getValue();
  75 + }
  76 +
  77 + public String getFormulaAsString(String column, int line) throws CellNotFoundException {
  78 + return this.getCell(column, line).toString();
  79 + }
  80 +
  81 + public String getDevelopedFormula(String column, int line) throws CellNotFoundException {
  82 + return this.getCell(column, line).getDevelopedFormula();
  83 + }
  84 +
  85 + private String getCellId(String column, int line) {
  86 + return column + line;
  87 + }
  88 +
  89 + public List<Integer> getTotalColumn() {
  90 + return listColumn;
  91 + }
  92 +
  93 + public List<Integer> getTotalLine() {
  94 + return listLine;
  95 + }
96 } 96 }
src/kernel/LanguageEnum.java
1 package kernel; 1 package kernel;
2 2
3 public enum LanguageEnum { 3 public enum LanguageEnum {
4 - FR,  
5 - EN 4 + FR,
  5 + EN
6 } 6 }
src/kernel/exception/CellNotFoundException.java
1 package kernel.exception; 1 package kernel.exception;
2 2
3 public class CellNotFoundException extends Exception { 3 public class CellNotFoundException extends Exception {
4 -  
5 -  
6 - private static final long serialVersionUID = 1L;  
7 } 4 }
src/kernel/exception/CreateCycleException.java
1 package kernel.exception; 1 package kernel.exception;
2 2
3 public class CreateCycleException extends Exception { 3 public class CreateCycleException extends Exception {
4 -  
5 - private static final long serialVersionUID = 1L;  
6 } 4 }
src/kernel/exception/InvalidIntervalException.java 0 โ†’ 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +package kernel.exception;
  2 +
  3 +public class InvalidIntervalException extends Exception {
  4 +}
src/kernel/exception/InvalidIntervalLineColumnEception.java deleted
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -package kernel.exception;  
2 -  
3 -public class InvalidIntervalLineColumnEception extends Exception {  
4 -  
5 -  
6 - private static final long serialVersionUID = 1L;  
7 -  
8 -}  
src/kernel/function/Average.java
@@ -7,20 +7,16 @@ import java.util.List; @@ -7,20 +7,16 @@ import java.util.List;
7 import java.util.OptionalDouble; 7 import java.util.OptionalDouble;
8 8
9 public class Average extends Function { 9 public class Average extends Function {
10 -  
11 - private static final long serialVersionUID = 1L;  
12 -  
13 - public Average(List<Cell> listCells) {  
14 - super(listCells);  
15 - this.names.put(LanguageEnum.FR, "MOYENNE");  
16 - this.names.put(LanguageEnum.EN, "AVERAGE");  
17 - }  
18 -  
19 - public double eval() {  
20 - OptionalDouble average = this.listCells.stream()  
21 - .mapToDouble(Cell::getValue)  
22 - .average();  
23 -  
24 - return average.isPresent() ? average.getAsDouble() : 0.;  
25 - } 10 +
  11 + public Average(List<Cell> listCells) {
  12 + super(listCells);
  13 + this.names.put(LanguageEnum.FR, "MOYENNE");
  14 + this.names.put(LanguageEnum.EN, "AVERAGE");
  15 + }
  16 +
  17 + public double eval() {
  18 + OptionalDouble average = this.listCells.stream().mapToDouble(Cell::getValue).average();
  19 +
  20 + return average.isPresent() ? average.getAsDouble() : 0.;
  21 + }
26 } 22 }
src/kernel/function/Function.java
@@ -12,41 +12,43 @@ import java.util.Map; @@ -12,41 +12,43 @@ import java.util.Map;
12 import java.util.stream.Collectors; 12 import java.util.stream.Collectors;
13 13
14 abstract public class Function implements Formula, Serializable { 14 abstract public class Function implements Formula, Serializable {
15 -  
16 - private static final long serialVersionUID = 1L;  
17 - public Map<LanguageEnum, String> names = new HashMap<>();  
18 - public List<Cell> listCells;  
19 -  
20 - public Function(List<Cell> listCells) {  
21 - this.listCells = listCells;  
22 - }  
23 -  
24 - abstract public double eval();  
25 -  
26 - public String getDevelopedFormula() {  
27 - return names.get(Grid.language) + "("  
28 - + this.listCells.stream()  
29 - .map(Cell::getDevelopedFormula)  
30 - .collect(Collectors.joining(",")) + ")";  
31 - }  
32 -  
33 - public String toString() {  
34 - return names.get(Grid.language) + "("  
35 - + this.listCells.stream()  
36 - .map(Cell::getId)  
37 - .collect(Collectors.joining(",")) + ")";  
38 - }  
39 -  
40 - public boolean createCycle(Cell cell) {  
41 - if (!this.listCells.contains(cell))  
42 - for (Cell currentCell : this.listCells)  
43 - if (currentCell.containFormula() && currentCell.getFormula().createCycle(cell))  
44 - return true;  
45 -  
46 - return true;  
47 - }  
48 -  
49 - public List<Cell> getUtilisedCells() {  
50 - return this.listCells;  
51 - } 15 +
  16 + private static final long serialVersionUID = 1L;
  17 + public Map<LanguageEnum, String> names = new HashMap<>();
  18 + public List<Cell> listCells;
  19 +
  20 + public Function(List<Cell> listCells) {
  21 + this.listCells = listCells;
  22 + }
  23 +
  24 + abstract public double eval();
  25 +
  26 + public String getDevelopedFormula() {
  27 + return names.get(Grid.language) + "("
  28 + + this.listCells.stream()
  29 + .map(Cell::getDevelopedFormula)
  30 + .collect(Collectors.joining(",")) + ")";
  31 + }
  32 +
  33 + public String toString() {
  34 + return names.get(Grid.language) + "("
  35 + + this.listCells.stream()
  36 + .map(Cell::getId)
  37 + .collect(Collectors.joining(",")) + ")";
  38 + }
  39 +
  40 + public boolean createCycle(Cell cell) {
  41 + if (!this.listCells.contains(cell)) {
  42 + for (Cell currentCell : this.listCells)
  43 + if (currentCell.containFormula() && currentCell.getFormula().createCycle(cell))
  44 + return true;
  45 + } else
  46 + return true;
  47 +
  48 + return false;
  49 + }
  50 +
  51 + public List<Cell> getUtilisedCells() {
  52 + return this.listCells;
  53 + }
52 } 54 }
src/kernel/function/Sum.java
@@ -6,18 +6,14 @@ import kernel.LanguageEnum; @@ -6,18 +6,14 @@ import kernel.LanguageEnum;
6 import java.util.List; 6 import java.util.List;
7 7
8 public class Sum extends Function { 8 public class Sum extends Function {
9 -  
10 - private static final long serialVersionUID = 1L;  
11 -  
12 - public Sum(List<Cell> listCells) {  
13 - super(listCells);  
14 - this.names.put(LanguageEnum.FR, "SOMME");  
15 - this.names.put(LanguageEnum.EN, "SUM");  
16 - }  
17 -  
18 - public double eval() {  
19 - return this.listCells.stream()  
20 - .mapToDouble(Cell::getValue)  
21 - .sum();  
22 - } 9 +
  10 + public Sum(List<Cell> listCells) {
  11 + super(listCells);
  12 + this.names.put(LanguageEnum.FR, "SOMME");
  13 + this.names.put(LanguageEnum.EN, "SUM");
  14 + }
  15 +
  16 + public double eval() {
  17 + return this.listCells.stream().mapToDouble(Cell::getValue).sum();
  18 + }
23 } 19 }
src/kernel/operation/Addition.java
@@ -3,18 +3,16 @@ package kernel.operation; @@ -3,18 +3,16 @@ package kernel.operation;
3 import kernel.Cell; 3 import kernel.Cell;
4 4
5 public class Addition extends BinaryOperation { 5 public class Addition extends BinaryOperation {
6 -  
7 - private static final long serialVersionUID = 1L;  
8 -  
9 - public Addition(Cell leftCell, Cell rightCell) {  
10 - super(leftCell, rightCell);  
11 - }  
12 -  
13 - public String getOperator() {  
14 - return "+";  
15 - }  
16 -  
17 - public double eval() {  
18 - return this.leftCell.getValue() + this.rightCell.getValue();  
19 - } 6 +
  7 + public Addition(Cell leftCell, Cell rightCell) {
  8 + super(leftCell, rightCell);
  9 + }
  10 +
  11 + public String getOperator() {
  12 + return "+";
  13 + }
  14 +
  15 + public double eval() {
  16 + return this.leftCell.getValue() + this.rightCell.getValue();
  17 + }
20 } 18 }
src/kernel/operation/BinaryOperation.java
@@ -8,46 +8,46 @@ import java.util.ArrayList; @@ -8,46 +8,46 @@ import java.util.ArrayList;
8 import java.util.List; 8 import java.util.List;
9 9
10 abstract public class BinaryOperation implements Formula, Serializable { 10 abstract public class BinaryOperation implements Formula, Serializable {
11 -  
12 - private static final long serialVersionUID = 1L;  
13 - protected Cell leftCell;  
14 - protected Cell rightCell;  
15 -  
16 - public BinaryOperation(Cell leftCell, Cell rightCell) {  
17 - this.leftCell = leftCell;  
18 - this.rightCell = rightCell;  
19 - }  
20 -  
21 - abstract public double eval();  
22 -  
23 - abstract public String getOperator();  
24 -  
25 - public String getDevelopedFormula() {  
26 - return "(" + this.leftCell.getDevelopedFormula() + this.getOperator() + this.rightCell.getDevelopedFormula() + ")";  
27 - }  
28 -  
29 - public String toString() {  
30 - return this.leftCell.getId() + this.getOperator() + this.rightCell.getId();  
31 - }  
32 -  
33 - public boolean createCycle(Cell cell) {  
34 - if (this.leftCell.containFormula() && !this.rightCell.containFormula())  
35 - return this.leftCell.getFormula().createCycle(cell);  
36 -  
37 - if (!this.leftCell.containFormula() && this.rightCell.containFormula())  
38 - return this.rightCell.getFormula().createCycle(cell);  
39 -  
40 - if (this.leftCell.containFormula() && this.rightCell.containFormula())  
41 - return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);  
42 -  
43 - return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));  
44 - }  
45 -  
46 - public List<Cell> getUtilisedCells() {  
47 - List<Cell> cells = new ArrayList<>();  
48 - cells.add(this.leftCell);  
49 - cells.add(this.rightCell);  
50 -  
51 - return cells;  
52 - } 11 +
  12 + private static final long serialVersionUID = 1L;
  13 + protected Cell leftCell;
  14 + protected Cell rightCell;
  15 +
  16 + public BinaryOperation(Cell leftCell, Cell rightCell) {
  17 + this.leftCell = leftCell;
  18 + this.rightCell = rightCell;
  19 + }
  20 +
  21 + abstract public double eval();
  22 +
  23 + abstract public String getOperator();
  24 +
  25 + public String getDevelopedFormula() {
  26 + return "(" + this.leftCell.getDevelopedFormula() + this.getOperator() + this.rightCell.getDevelopedFormula() + ")";
  27 + }
  28 +
  29 + public String toString() {
  30 + return "(" + this.leftCell.getId() + this.getOperator() + this.rightCell.getId() + ")";
  31 + }
  32 +
  33 + public boolean createCycle(Cell cell) {
  34 + if (this.leftCell.containFormula() && !this.rightCell.containFormula())
  35 + return this.leftCell.getFormula().createCycle(cell);
  36 +
  37 + if (!this.leftCell.containFormula() && this.rightCell.containFormula())
  38 + return this.rightCell.getFormula().createCycle(cell);
  39 +
  40 + if (this.leftCell.containFormula() && this.rightCell.containFormula())
  41 + return this.leftCell.getFormula().createCycle(cell) && this.rightCell.getFormula().createCycle(cell);
  42 +
  43 + return (cell.getId().equals(this.rightCell.getId()) || cell.getId().equals(this.leftCell.getId()));
  44 + }
  45 +
  46 + public List<Cell> getUtilisedCells() {
  47 + List<Cell> cells = new ArrayList<>();
  48 + cells.add(this.leftCell);
  49 + cells.add(this.rightCell);
  50 +
  51 + return cells;
  52 + }
53 } 53 }
src/kernel/operation/Division.java
@@ -3,18 +3,16 @@ package kernel.operation; @@ -3,18 +3,16 @@ package kernel.operation;
3 import kernel.Cell; 3 import kernel.Cell;
4 4
5 public class Division extends BinaryOperation { 5 public class Division extends BinaryOperation {
6 -  
7 - private static final long serialVersionUID = 1L;  
8 -  
9 - public Division(Cell leftCell, Cell rightCell) {  
10 - super(leftCell, rightCell);  
11 - }  
12 -  
13 - public String getOperator() {  
14 - return "/";  
15 - }  
16 -  
17 - public double eval() {  
18 - return this.leftCell.getValue() / this.rightCell.getValue();  
19 - } 6 +
  7 + public Division(Cell leftCell, Cell rightCell) {
  8 + super(leftCell, rightCell);
  9 + }
  10 +
  11 + public String getOperator() {
  12 + return "/";
  13 + }
  14 +
  15 + public double eval() {
  16 + return this.leftCell.getValue() / this.rightCell.getValue();
  17 + }
20 } 18 }
src/kernel/operation/Multiplication.java
@@ -3,18 +3,16 @@ package kernel.operation; @@ -3,18 +3,16 @@ package kernel.operation;
3 import kernel.Cell; 3 import kernel.Cell;
4 4
5 public class Multiplication extends BinaryOperation { 5 public class Multiplication extends BinaryOperation {
6 -  
7 - private static final long serialVersionUID = 1L;  
8 -  
9 - public Multiplication(Cell leftCell, Cell rightCell) {  
10 - super(leftCell, rightCell);  
11 - }  
12 -  
13 - public String getOperator() {  
14 - return "*";  
15 - }  
16 -  
17 - public double eval() {  
18 - return this.leftCell.getValue() * this.rightCell.getValue();  
19 - } 6 +
  7 + public Multiplication(Cell leftCell, Cell rightCell) {
  8 + super(leftCell, rightCell);
  9 + }
  10 +
  11 + public String getOperator() {
  12 + return "*";
  13 + }
  14 +
  15 + public double eval() {
  16 + return this.leftCell.getValue() * this.rightCell.getValue();
  17 + }
20 } 18 }
src/kernel/operation/Subtraction.java
@@ -3,19 +3,16 @@ package kernel.operation; @@ -3,19 +3,16 @@ package kernel.operation;
3 import kernel.Cell; 3 import kernel.Cell;
4 4
5 public class Subtraction extends BinaryOperation { 5 public class Subtraction extends BinaryOperation {
6 -  
7 - private static final long serialVersionUID = 1L;  
8 -  
9 - public Subtraction(Cell leftCell, Cell rightCell) {  
10 - super(leftCell, rightCell);  
11 - }  
12 -  
13 -  
14 - public String getOperator() {  
15 - return "-";  
16 - }  
17 -  
18 - public double eval() {  
19 - return this.leftCell.getValue() - this.rightCell.getValue();  
20 - } 6 +
  7 + public Subtraction(Cell leftCell, Cell rightCell) {
  8 + super(leftCell, rightCell);
  9 + }
  10 +
  11 + public String getOperator() {
  12 + return "-";
  13 + }
  14 +
  15 + public double eval() {
  16 + return this.leftCell.getValue() - this.rightCell.getValue();
  17 + }
21 } 18 }
src/kernel/test/BinaryOperationTest.java
@@ -4,7 +4,7 @@ import kernel.Cell; @@ -4,7 +4,7 @@ import kernel.Cell;
4 import kernel.Grid; 4 import kernel.Grid;
5 import kernel.LanguageEnum; 5 import kernel.LanguageEnum;
6 import kernel.exception.CreateCycleException; 6 import kernel.exception.CreateCycleException;
7 -import kernel.exception.InvalidIntervalLineColumnEception; 7 +import kernel.exception.InvalidIntervalException;
8 import kernel.function.Sum; 8 import kernel.function.Sum;
9 import kernel.operation.Addition; 9 import kernel.operation.Addition;
10 import kernel.operation.Division; 10 import kernel.operation.Division;
@@ -19,108 +19,108 @@ import java.util.List; @@ -19,108 +19,108 @@ import java.util.List;
19 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertEquals;
20 20
21 public class BinaryOperationTest { 21 public class BinaryOperationTest {
22 -  
23 - private List<Cell> cells;  
24 -  
25 - @Before  
26 - public void initData() throws CreateCycleException, InvalidIntervalLineColumnEception {  
27 - Grid.language = LanguageEnum.EN;  
28 - this.cells = new ArrayList<>();  
29 -  
30 - Cell a1 = new Cell("A", 1, 10.);  
31 - Cell a2 = new Cell("A", 2, 0.);  
32 - Cell a3 = new Cell("A", 3, 20.);  
33 -  
34 - List<Cell> sumList = new ArrayList<>();  
35 - sumList.add(a1);  
36 - sumList.add(a2);  
37 - sumList.add(a3);  
38 -  
39 - Cell b1 = new Cell("B", 1, new Sum(sumList));  
40 -  
41 - this.cells.add(a1);  
42 - this.cells.add(a2);  
43 - this.cells.add(a3);  
44 - this.cells.add(b1);  
45 - }  
46 -  
47 - @Test  
48 - public void testAddition() {  
49 - Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);  
50 - Cell a2 = this.cells.stream().filter(c -> c.getId().equals("A2")).findFirst().orElse(null);  
51 -  
52 - Addition addition = new Addition(a1, a2);  
53 -  
54 - assertEquals(10, addition.eval(), 0);  
55 - assertEquals("A1+A2", addition.toString());  
56 - assertEquals("A1+A2", addition.getDevelopedFormula());  
57 -  
58 - Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);  
59 -  
60 - addition = new Addition(a1, b1);  
61 -  
62 - assertEquals(40, addition.eval(), 0);  
63 - assertEquals("A1+B1", addition.toString());  
64 - assertEquals("A1+SUM(A1,A2,A3)", addition.getDevelopedFormula());  
65 - }  
66 -  
67 - @Test  
68 - public void testMultiplication() {  
69 - Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);  
70 - Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);  
71 -  
72 - Multiplication multiplication = new Multiplication(a1, a3);  
73 -  
74 - assertEquals(200, multiplication.eval(), 0);  
75 - assertEquals("A1*A3", multiplication.toString());  
76 - assertEquals("A1*A3", multiplication.getDevelopedFormula());  
77 -  
78 - Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);  
79 -  
80 - multiplication = new Multiplication(a1, b1);  
81 -  
82 - assertEquals(300, multiplication.eval(), 0);  
83 - assertEquals("A1*B1", multiplication.toString());  
84 - assertEquals("A1*SUM(A1,A2,A3)", multiplication.getDevelopedFormula());  
85 - }  
86 -  
87 - @Test  
88 - public void testSubtraction() {  
89 - Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);  
90 - Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);  
91 -  
92 - Subtraction subtraction = new Subtraction(a3, a1);  
93 -  
94 - assertEquals(10, subtraction.eval(), 0);  
95 - assertEquals("A3-A1", subtraction.toString());  
96 - assertEquals("A3-A1", subtraction.getDevelopedFormula());  
97 -  
98 - Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);  
99 -  
100 - subtraction = new Subtraction(a1, b1);  
101 -  
102 - assertEquals(-20, subtraction.eval(), 0);  
103 - assertEquals("A1-B1", subtraction.toString());  
104 - assertEquals("A1-SUM(A1,A2,A3)", subtraction.getDevelopedFormula());  
105 - }  
106 -  
107 - @Test  
108 - public void testDivision() {  
109 - Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);  
110 - Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);  
111 -  
112 - Division division = new Division(a3, a1);  
113 -  
114 - assertEquals(2, division.eval(), 0);  
115 - assertEquals("A3/A1", division.toString());  
116 - assertEquals("A3/A1", division.getDevelopedFormula());  
117 -  
118 - Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);  
119 -  
120 - division = new Division(b1, a1);  
121 -  
122 - assertEquals(3, division.eval(), 0);  
123 - assertEquals("B1/A1", division.toString());  
124 - assertEquals("SUM(A1,A2,A3)/A1", division.getDevelopedFormula());  
125 - } 22 +
  23 + private List<Cell> cells;
  24 +
  25 + @Before
  26 + public void initData() throws CreateCycleException, InvalidIntervalException {
  27 + Grid.language = LanguageEnum.EN;
  28 + this.cells = new ArrayList<>();
  29 +
  30 + Cell a1 = new Cell("A", 1, 10.);
  31 + Cell a2 = new Cell("A", 2, 0.);
  32 + Cell a3 = new Cell("A", 3, 20.);
  33 +
  34 + List<Cell> sumList = new ArrayList<>();
  35 + sumList.add(a1);
  36 + sumList.add(a2);
  37 + sumList.add(a3);
  38 +
  39 + Cell b1 = new Cell("B", 1, new Sum(sumList));
  40 +
  41 + this.cells.add(a1);
  42 + this.cells.add(a2);
  43 + this.cells.add(a3);
  44 + this.cells.add(b1);
  45 + }
  46 +
  47 + @Test
  48 + public void testAddition() {
  49 + Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);
  50 + Cell a2 = this.cells.stream().filter(c -> c.getId().equals("A2")).findFirst().orElse(null);
  51 +
  52 + Addition addition = new Addition(a1, a2);
  53 +
  54 + assertEquals(10, addition.eval(), 0);
  55 + assertEquals("(A1+A2)", addition.toString());
  56 + assertEquals("(A1+A2)", addition.getDevelopedFormula());
  57 +
  58 + Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);
  59 +
  60 + addition = new Addition(a1, b1);
  61 +
  62 + assertEquals(40, addition.eval(), 0);
  63 + assertEquals("(A1+B1)", addition.toString());
  64 + assertEquals("(A1+SUM(A1,A2,A3))", addition.getDevelopedFormula());
  65 + }
  66 +
  67 + @Test
  68 + public void testMultiplication() {
  69 + Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);
  70 + Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);
  71 +
  72 + Multiplication multiplication = new Multiplication(a1, a3);
  73 +
  74 + assertEquals(200, multiplication.eval(), 0);
  75 + assertEquals("(A1*A3)", multiplication.toString());
  76 + assertEquals("(A1*A3)", multiplication.getDevelopedFormula());
  77 +
  78 + Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);
  79 +
  80 + multiplication = new Multiplication(a1, b1);
  81 +
  82 + assertEquals(300, multiplication.eval(), 0);
  83 + assertEquals("(A1*B1)", multiplication.toString());
  84 + assertEquals("(A1*SUM(A1,A2,A3))", multiplication.getDevelopedFormula());
  85 + }
  86 +
  87 + @Test
  88 + public void testSubtraction() {
  89 + Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);
  90 + Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);
  91 +
  92 + Subtraction subtraction = new Subtraction(a3, a1);
  93 +
  94 + assertEquals(10, subtraction.eval(), 0);
  95 + assertEquals("(A3-A1)", subtraction.toString());
  96 + assertEquals("(A3-A1)", subtraction.getDevelopedFormula());
  97 +
  98 + Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);
  99 +
  100 + subtraction = new Subtraction(a1, b1);
  101 +
  102 + assertEquals(-20, subtraction.eval(), 0);
  103 + assertEquals("(A1-B1)", subtraction.toString());
  104 + assertEquals("(A1-SUM(A1,A2,A3))", subtraction.getDevelopedFormula());
  105 + }
  106 +
  107 + @Test
  108 + public void testDivision() {
  109 + Cell a1 = this.cells.stream().filter(c -> c.getId().equals("A1")).findFirst().orElse(null);
  110 + Cell a3 = this.cells.stream().filter(c -> c.getId().equals("A3")).findFirst().orElse(null);
  111 +
  112 + Division division = new Division(a3, a1);
  113 +
  114 + assertEquals(2, division.eval(), 0);
  115 + assertEquals("(A3/A1)", division.toString());
  116 + assertEquals("(A3/A1)", division.getDevelopedFormula());
  117 +
  118 + Cell b1 = this.cells.stream().filter(c -> c.getId().equals("B1")).findFirst().orElse(null);
  119 +
  120 + division = new Division(b1, a1);
  121 +
  122 + assertEquals(3, division.eval(), 0);
  123 + assertEquals("(B1/A1)", division.toString());
  124 + assertEquals("(SUM(A1,A2,A3)/A1)", division.getDevelopedFormula());
  125 + }
126 } 126 }
src/kernel/test/CellTest.java
@@ -7,7 +7,7 @@ import java.util.List; @@ -7,7 +7,7 @@ import java.util.List;
7 7
8 import kernel.Cell; 8 import kernel.Cell;
9 import kernel.exception.CreateCycleException; 9 import kernel.exception.CreateCycleException;
10 -import kernel.exception.InvalidIntervalLineColumnEception; 10 +import kernel.exception.InvalidIntervalException;
11 import kernel.function.Average; 11 import kernel.function.Average;
12 import kernel.function.Sum; 12 import kernel.function.Sum;
13 import kernel.operation.Addition; 13 import kernel.operation.Addition;
@@ -16,7 +16,7 @@ import kernel.operation.Addition; @@ -16,7 +16,7 @@ import kernel.operation.Addition;
16 public class CellTest { 16 public class CellTest {
17 17
18 @org.junit.Test 18 @org.junit.Test
19 - public void CreateCellValueTest() throws InvalidIntervalLineColumnEception { 19 + public void CreateCellValueTest() throws InvalidIntervalException {
20 Cell A1= new Cell("A",1,25.); 20 Cell A1= new Cell("A",1,25.);
21 assertEquals(A1.getValue(),25.,0); 21 assertEquals(A1.getValue(),25.,0);
22 assertEquals(A1.containFormula(),false); 22 assertEquals(A1.containFormula(),false);
@@ -26,7 +26,7 @@ public class CellTest { @@ -26,7 +26,7 @@ public class CellTest {
26 26
27 27
28 @org.junit.Test 28 @org.junit.Test
29 - public void CreateCellBinaryOperationTest() throws CreateCycleException, InvalidIntervalLineColumnEception { 29 + public void CreateCellBinaryOperationTest() throws CreateCycleException, InvalidIntervalException {
30 Cell A1= new Cell("A",1,25.); 30 Cell A1= new Cell("A",1,25.);
31 Cell A2= new Cell("A",2,35.); 31 Cell A2= new Cell("A",2,35.);
32 32
@@ -47,7 +47,7 @@ public class CellTest { @@ -47,7 +47,7 @@ public class CellTest {
47 47
48 48
49 @org.junit.Test 49 @org.junit.Test
50 - public void CreateCellFunctionTest() throws CreateCycleException, InvalidIntervalLineColumnEception { 50 + public void CreateCellFunctionTest() throws CreateCycleException, InvalidIntervalException {
51 Cell A1= new Cell("A",1,25.); 51 Cell A1= new Cell("A",1,25.);
52 Cell A2= new Cell("A",2,35.); 52 Cell A2= new Cell("A",2,35.);
53 Cell A3= new Cell("A",3,new Addition(A1,A2)); 53 Cell A3= new Cell("A",3,new Addition(A1,A2));
@@ -76,7 +76,7 @@ public class CellTest { @@ -76,7 +76,7 @@ public class CellTest {
76 76
77 77
78 @org.junit.Test 78 @org.junit.Test
79 - public void ModifyCellValueTest() throws CreateCycleException, InvalidIntervalLineColumnEception { 79 + public void ModifyCellValueTest() throws CreateCycleException, InvalidIntervalException {
80 Cell A1= new Cell("A",1,25.); 80 Cell A1= new Cell("A",1,25.);
81 Cell A2= new Cell("A",2,35.); 81 Cell A2= new Cell("A",2,35.);
82 Cell A3= new Cell("A",3,new Addition(A1,A2)); 82 Cell A3= new Cell("A",3,new Addition(A1,A2));
@@ -90,7 +90,7 @@ public class CellTest { @@ -90,7 +90,7 @@ public class CellTest {
90 } 90 }
91 91
92 @org.junit.Test 92 @org.junit.Test
93 - public void ModifyCellFormulaTest() throws CreateCycleException, InvalidIntervalLineColumnEception { 93 + public void ModifyCellFormulaTest() throws CreateCycleException, InvalidIntervalException {
94 Cell A1= new Cell("A",1,25.); 94 Cell A1= new Cell("A",1,25.);
95 Cell A2= new Cell("A",2,35.); 95 Cell A2= new Cell("A",2,35.);
96 Cell A3= new Cell("A",3,new Addition(A1,A2)); 96 Cell A3= new Cell("A",3,new Addition(A1,A2));
@@ -137,7 +137,7 @@ public class CellTest { @@ -137,7 +137,7 @@ public class CellTest {
137 } 137 }
138 138
139 @org.junit.Test(expected=CreateCycleException.class) 139 @org.junit.Test(expected=CreateCycleException.class)
140 - public void DirectCycleBynaryOperation() throws CreateCycleException, InvalidIntervalLineColumnEception { 140 + public void DirectCycleBynaryOperation() throws CreateCycleException, InvalidIntervalException {
141 Cell A1= new Cell("A",1,25.); 141 Cell A1= new Cell("A",1,25.);
142 Cell A2= new Cell("A",2,35.); 142 Cell A2= new Cell("A",2,35.);
143 try{ 143 try{
@@ -150,7 +150,7 @@ public class CellTest { @@ -150,7 +150,7 @@ public class CellTest {
150 150
151 151
152 @org.junit.Test(expected=CreateCycleException.class) 152 @org.junit.Test(expected=CreateCycleException.class)
153 - public void DirectCycleFunction() throws CreateCycleException, InvalidIntervalLineColumnEception { 153 + public void DirectCycleFunction() throws CreateCycleException, InvalidIntervalException {
154 Cell A2= new Cell("A",2,25.); 154 Cell A2= new Cell("A",2,25.);
155 Cell B2= new Cell("B",2,35.); 155 Cell B2= new Cell("B",2,35.);
156 Cell A3= new Cell("A",3,0.5); 156 Cell A3= new Cell("A",3,0.5);
@@ -168,7 +168,7 @@ public class CellTest { @@ -168,7 +168,7 @@ public class CellTest {
168 } 168 }
169 169
170 @org.junit.Test(expected=CreateCycleException.class) 170 @org.junit.Test(expected=CreateCycleException.class)
171 - public void IndirectCycle() throws CreateCycleException, InvalidIntervalLineColumnEception { 171 + public void IndirectCycle() throws CreateCycleException, InvalidIntervalException {
172 Cell A1= new Cell("A",1,25.); 172 Cell A1= new Cell("A",1,25.);
173 Cell A2= new Cell("A",2,5.); 173 Cell A2= new Cell("A",2,5.);
174 Cell B4= new Cell("B",4,new Addition(A1,A2)); 174 Cell B4= new Cell("B",4,new Addition(A1,A2));
src/kernel/test/FunctionTest.java
@@ -3,7 +3,7 @@ package kernel.test; @@ -3,7 +3,7 @@ package kernel.test;
3 import kernel.Cell; 3 import kernel.Cell;
4 import kernel.Grid; 4 import kernel.Grid;
5 import kernel.LanguageEnum; 5 import kernel.LanguageEnum;
6 -import kernel.exception.InvalidIntervalLineColumnEception; 6 +import kernel.exception.InvalidIntervalException;
7 import kernel.function.Sum; 7 import kernel.function.Sum;
8 import org.junit.Before; 8 import org.junit.Before;
9 import org.junit.Test; 9 import org.junit.Test;
@@ -11,27 +11,26 @@ import org.junit.Test; @@ -11,27 +11,26 @@ import org.junit.Test;
11 import java.util.ArrayList; 11 import java.util.ArrayList;
12 import java.util.List; 12 import java.util.List;
13 13
14 -  
15 public class FunctionTest { 14 public class FunctionTest {
16 -  
17 - private List<Cell> cells;  
18 -  
19 - @Before  
20 - public void initData() throws InvalidIntervalLineColumnEception {  
21 - Grid.language = LanguageEnum.EN;  
22 - this.cells = new ArrayList<>();  
23 -  
24 - Cell a1 = new Cell("A", 1, 10.);  
25 - Cell a2 = new Cell("A", 2, 0.);  
26 - Cell a3 = new Cell("A", 3, 20.);  
27 -  
28 - this.cells.add(a1);  
29 - this.cells.add(a2);  
30 - this.cells.add(a3);  
31 - }  
32 -  
33 - @Test  
34 - public void testSum() {  
35 - Sum sum = new Sum(this.cells);  
36 - } 15 +
  16 + private List<Cell> cells;
  17 +
  18 + @Before
  19 + public void initData() throws InvalidIntervalException {
  20 + Grid.language = LanguageEnum.EN;
  21 + this.cells = new ArrayList<>();
  22 +
  23 + Cell a1 = new Cell("A", 1, 10.);
  24 + Cell a2 = new Cell("A", 2, 0.);
  25 + Cell a3 = new Cell("A", 3, 20.);
  26 +
  27 + this.cells.add(a1);
  28 + this.cells.add(a2);
  29 + this.cells.add(a3);
  30 + }
  31 +
  32 + @Test
  33 + public void testSum() {
  34 + Sum sum = new Sum(this.cells);
  35 + }
37 } 36 }
src/kernel/test/GridTest.java
@@ -5,7 +5,7 @@ import kernel.Grid; @@ -5,7 +5,7 @@ import kernel.Grid;
5 import kernel.LanguageEnum; 5 import kernel.LanguageEnum;
6 import kernel.exception.CellNotFoundException; 6 import kernel.exception.CellNotFoundException;
7 import kernel.exception.CreateCycleException; 7 import kernel.exception.CreateCycleException;
8 -import kernel.exception.InvalidIntervalLineColumnEception; 8 +import kernel.exception.InvalidIntervalException;
9 import kernel.function.Average; 9 import kernel.function.Average;
10 import kernel.function.Sum; 10 import kernel.function.Sum;
11 import kernel.operation.Addition; 11 import kernel.operation.Addition;
@@ -16,190 +16,212 @@ import org.junit.Test; @@ -16,190 +16,212 @@ import org.junit.Test;
16 import java.util.ArrayList; 16 import java.util.ArrayList;
17 import java.util.List; 17 import java.util.List;
18 18
19 -import static org.junit.Assert.assertEquals;  
20 -import static org.junit.Assert.assertFalse; 19 +import static org.junit.Assert.*;
21 20
22 public class GridTest { 21 public class GridTest {
23 -  
24 - private Grid grid;  
25 -  
26 - @Before  
27 - public void initData() {  
28 - Grid.language = LanguageEnum.EN;  
29 - this.grid = new Grid();  
30 - }  
31 -  
32 - @Test  
33 - public void testCreateCellWithValue() throws InvalidIntervalLineColumnEception {  
34 - assertEquals(0, this.grid.getCells().size());  
35 -  
36 - this.grid.createCell("A", 1, 10.);  
37 -  
38 - assertEquals(1, this.grid.getCells().size());  
39 - }  
40 -  
41 - @Test  
42 - public void testCreateCellWithFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
43 - this.createCellsWithValue();  
44 - assertEquals(3, this.grid.getCells().size());  
45 -  
46 - List<Cell> cellsFormula = new ArrayList<>();  
47 - cellsFormula.add(this.grid.getCell("A", 1));  
48 - cellsFormula.add(this.grid.getCell("A", 2));  
49 -  
50 - this.grid.createCell("B", 1, new Sum(cellsFormula));  
51 -  
52 - assertEquals(4, this.grid.getCells().size());  
53 - }  
54 -  
55 - @Test  
56 - public void testGetValue() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
57 - this.createCellsWithFormula();  
58 -  
59 - assertEquals(10, this.grid.getValue("A", 1), 0);  
60 - assertEquals(0, this.grid.getValue("A", 2), 0);  
61 - assertEquals(2, this.grid.getValue("A", 3), 0);  
62 - assertEquals(10, this.grid.getValue("B", 1), 0);  
63 - assertEquals(12, this.grid.getValue("B", 2), 0);  
64 - assertEquals(24, this.grid.getValue("B", 3), 0);  
65 - }  
66 -  
67 - @Test  
68 - public void testGetFormulaAsString() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
69 - Grid.language = LanguageEnum.EN;  
70 - this.createCellsWithFormula();  
71 -  
72 - assertEquals("A1", this.grid.getFormulaAsString("A", 1));  
73 - assertEquals("A2", this.grid.getFormulaAsString("A", 2));  
74 - assertEquals("A3", this.grid.getFormulaAsString("A", 3));  
75 - assertEquals("A1+A2", this.grid.getFormulaAsString("B", 1));  
76 - assertEquals("SUM(A1,A2,A3)", this.grid.getFormulaAsString("B", 2));  
77 - assertEquals("A3*B2", this.grid.getFormulaAsString("B", 3));  
78 - }  
79 -  
80 - @Test  
81 - public void testGetDevelopedFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
82 - this.createCellsWithFormula();  
83 -  
84 - assertEquals("A3*SUM(A1,A2,A3)", this.grid.getDevelopedFormula("B", 3));  
85 - }  
86 -  
87 - @Test  
88 - public void testSetValue() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
89 - this.createCellsWithFormula();  
90 -  
91 - assertEquals(10, this.grid.getValue("A", 1), 0);  
92 - assertEquals(12, this.grid.getValue("B", 2), 0);  
93 - assertEquals(24, this.grid.getValue("B", 3), 0);  
94 -  
95 - this.grid.setValue("A", 1, 15.);  
96 -  
97 - assertEquals(15, this.grid.getValue("A", 1), 0);  
98 - assertEquals(17, this.grid.getValue("B", 2), 0);  
99 - assertEquals(34, this.grid.getValue("B", 3), 0);  
100 - assertEquals("A3*SUM(A1,A2,A3)", this.grid.getDevelopedFormula("B", 3));  
101 -  
102 - this.grid.setValue("B", 2, 20.);  
103 -  
104 - assertEquals(40, this.grid.getValue("B", 3), 0);  
105 - assertEquals("A3*B2", this.grid.getDevelopedFormula("B", 3));  
106 - }  
107 -  
108 - @Test  
109 - public void testSetFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
110 - this.createCellsWithFormula();  
111 -  
112 - assertEquals(12, this.grid.getValue("B", 2), 0);  
113 - assertEquals(24, this.grid.getValue("B", 3), 0);  
114 - assertEquals("SUM(A1,A2,A3)", this.grid.getDevelopedFormula("B", 2));  
115 - assertEquals("A3*SUM(A1,A2,A3)", this.grid.getDevelopedFormula("B", 3));  
116 -  
117 - List<Cell> sumList = new ArrayList<>();  
118 - sumList.add(this.grid.getCell("A", 1));  
119 - sumList.add(this.grid.getCell("A", 3));  
120 - sumList.add(this.grid.getCell("B", 1));  
121 -  
122 - this.grid.setFormula("B", 2, new Sum(sumList));  
123 -  
124 - // B2  
125 - assertEquals(22, this.grid.getValue("B", 2), 0);  
126 - assertEquals("SUM(A1,A3,B1)", this.grid.getFormulaAsString("B", 2));  
127 - assertEquals("SUM(A1,A3,A1+A2)", this.grid.getDevelopedFormula("B", 2));  
128 - // B3  
129 - assertEquals(44, this.grid.getValue("B", 3), 0);  
130 - assertEquals("A3*B2", this.grid.getFormulaAsString("B", 3));  
131 - assertEquals("A3*SUM(A1,A3,A1+A2)", this.grid.getDevelopedFormula("B", 3));  
132 -  
133 - this.grid.createCell("C", 1, 10.);  
134 - this.grid.createCell("C", 2, 20.);  
135 -  
136 - List<Cell> averageList = new ArrayList<>();  
137 - averageList.add(this.grid.getCell("C", 1));  
138 - averageList.add(this.grid.getCell("C", 2));  
139 -  
140 - this.grid.setFormula("A", 1, new Average(averageList));  
141 -  
142 - // A1  
143 - assertEquals(15, this.grid.getValue("A", 1), 0);  
144 - assertEquals("AVERAGE(C1,C2)", this.grid.getDevelopedFormula("A", 1));  
145 - // B1  
146 - assertEquals(15, this.grid.getValue("B", 1), 0);  
147 - assertEquals("A1+A2", this.grid.getFormulaAsString("B", 1));  
148 - assertEquals("AVERAGE(C1,C2)+A2", this.grid.getDevelopedFormula("B", 1));  
149 - // B2  
150 - assertEquals(32, this.grid.getValue("B", 2), 0);  
151 - assertEquals("SUM(A1,A3,B1)", this.grid.getFormulaAsString("B", 2));  
152 - assertEquals("SUM(AVERAGE(C1,C2),A3,AVERAGE(C1,C2)+A2)", this.grid.getDevelopedFormula("B", 2));  
153 - }  
154 -  
155 - @Test  
156 - public void testGetCell() throws CellNotFoundException, InvalidIntervalLineColumnEception {  
157 - this.createCellsWithValue();  
158 -  
159 - Cell cell = this.grid.getCell("A", 1);  
160 -  
161 - assertEquals("A1", cell.getId());  
162 - assertEquals(10, cell.getValue(), 0);  
163 - assertFalse(cell.containFormula());  
164 - }  
165 -  
166 - @Test(expected = CellNotFoundException.class)  
167 - public void testGetCellNotFound() throws CellNotFoundException {  
168 - Cell cell = this.grid.getCell("A", 1);  
169 - }  
170 -  
171 - @Test  
172 - public void testGetCells() throws InvalidIntervalLineColumnEception {  
173 - assertEquals(0, this.grid.getCells().size());  
174 -  
175 - this.createCellsWithValue();  
176 -  
177 - assertEquals(3, this.grid.getCells().size());  
178 - }  
179 -  
180 - private void createCellsWithValue() throws InvalidIntervalLineColumnEception {  
181 - this.grid.createCell("A", 1, 10.);  
182 - this.grid.createCell("A", 2, 0.);  
183 - this.grid.createCell("A", 3, 2.);  
184 - }  
185 -  
186 - private void createCellsWithFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalLineColumnEception {  
187 - this.createCellsWithValue();  
188 -  
189 - Cell a1 = this.grid.getCell("A", 1);  
190 - Cell a2 = this.grid.getCell("A", 2);  
191 - Cell a3 = this.grid.getCell("A", 3);  
192 -  
193 - List<Cell> sumList = new ArrayList<>();  
194 - sumList.add(a1);  
195 - sumList.add(a2);  
196 - sumList.add(a3);  
197 -  
198 - // A1+A2  
199 - this.grid.createCell("B", 1, new Addition(a1, a2));  
200 - // SUM(A1+A2+A3)  
201 - this.grid.createCell("B", 2, new Sum(sumList));  
202 - // A3*B2  
203 - this.grid.createCell("B", 3, new Multiplication(a3, this.grid.getCell("B", 2)));  
204 - } 22 +
  23 + private Grid grid;
  24 +
  25 + @Before
  26 + public void initData() {
  27 + Grid.language = LanguageEnum.EN;
  28 + this.grid = new Grid();
  29 + }
  30 +
  31 + @Test
  32 + public void testCreateCellWithValue() throws InvalidIntervalException {
  33 + assertEquals(0, this.grid.getCells().size());
  34 +
  35 + this.grid.createCell("A", 1, 10.);
  36 +
  37 + assertEquals(1, this.grid.getCells().size());
  38 + }
  39 +
  40 + @Test
  41 + public void testCreateCellWithFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  42 + this.createCellsWithValue();
  43 + assertEquals(3, this.grid.getCells().size());
  44 +
  45 + List<Cell> cellsFormula = new ArrayList<>();
  46 + cellsFormula.add(this.grid.getCell("A", 1));
  47 + cellsFormula.add(this.grid.getCell("A", 2));
  48 +
  49 + this.grid.createCell("B", 1, new Sum(cellsFormula));
  50 +
  51 + assertEquals(4, this.grid.getCells().size());
  52 + }
  53 +
  54 + @Test(expected = InvalidIntervalException.class)
  55 + public void testCreateCellWithInvalidInterval() throws InvalidIntervalException {
  56 + this.grid.createCell("AZ", 120, 0.);
  57 + }
  58 +
  59 + @Test
  60 + public void testGetValue() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  61 + this.createCellsWithFormula();
  62 +
  63 + assertEquals(10, this.grid.getValue("A", 1), 0);
  64 + assertEquals(0, this.grid.getValue("A", 2), 0);
  65 + assertEquals(2, this.grid.getValue("A", 3), 0);
  66 + assertEquals(10, this.grid.getValue("B", 1), 0);
  67 + assertEquals(12, this.grid.getValue("B", 2), 0);
  68 + assertEquals(24, this.grid.getValue("B", 3), 0);
  69 + }
  70 +
  71 + @Test
  72 + public void testGetFormulaAsString() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  73 + Grid.language = LanguageEnum.EN;
  74 + this.createCellsWithFormula();
  75 +
  76 + assertEquals("A1", this.grid.getFormulaAsString("A", 1));
  77 + assertEquals("A2", this.grid.getFormulaAsString("A", 2));
  78 + assertEquals("A3", this.grid.getFormulaAsString("A", 3));
  79 + assertEquals("(A1+A2)", this.grid.getFormulaAsString("B", 1));
  80 + assertEquals("SUM(A1,A2,A3)", this.grid.getFormulaAsString("B", 2));
  81 + assertEquals("(A3*B2)", this.grid.getFormulaAsString("B", 3));
  82 + }
  83 +
  84 + @Test
  85 + public void testGetDevelopedFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  86 + this.createCellsWithFormula();
  87 +
  88 + assertEquals("(A3*SUM(A1,A2,A3))", this.grid.getDevelopedFormula("B", 3));
  89 + }
  90 +
  91 + @Test
  92 + public void testSetValue() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  93 + this.createCellsWithFormula();
  94 +
  95 + assertEquals(10, this.grid.getValue("A", 1), 0);
  96 + assertEquals(12, this.grid.getValue("B", 2), 0);
  97 + assertEquals(24, this.grid.getValue("B", 3), 0);
  98 +
  99 + this.grid.setValue("A", 1, 15.);
  100 +
  101 + assertEquals(15, this.grid.getValue("A", 1), 0);
  102 + assertEquals(17, this.grid.getValue("B", 2), 0);
  103 + assertEquals(34, this.grid.getValue("B", 3), 0);
  104 + assertEquals("(A3*SUM(A1,A2,A3))", this.grid.getDevelopedFormula("B", 3));
  105 +
  106 + this.grid.setValue("B", 2, 20.);
  107 +
  108 + assertEquals(40, this.grid.getValue("B", 3), 0);
  109 + assertEquals("(A3*B2)", this.grid.getDevelopedFormula("B", 3));
  110 + }
  111 +
  112 + @Test
  113 + public void testSetFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  114 + this.createCellsWithFormula();
  115 +
  116 + assertEquals(12, this.grid.getValue("B", 2), 0);
  117 + assertEquals(24, this.grid.getValue("B", 3), 0);
  118 + assertEquals("SUM(A1,A2,A3)", this.grid.getDevelopedFormula("B", 2));
  119 + assertEquals("(A3*SUM(A1,A2,A3))", this.grid.getDevelopedFormula("B", 3));
  120 +
  121 + List<Cell> sumList = new ArrayList<>();
  122 + sumList.add(this.grid.getCell("A", 1));
  123 + sumList.add(this.grid.getCell("A", 3));
  124 + sumList.add(this.grid.getCell("B", 1));
  125 +
  126 + this.grid.setFormula("B", 2, new Sum(sumList));
  127 +
  128 + // B2
  129 + assertEquals(22, this.grid.getValue("B", 2), 0);
  130 + assertEquals("SUM(A1,A3,B1)", this.grid.getFormulaAsString("B", 2));
  131 + assertEquals("SUM(A1,A3,(A1+A2))", this.grid.getDevelopedFormula("B", 2));
  132 + // B3
  133 + assertEquals(44, this.grid.getValue("B", 3), 0);
  134 + assertEquals("(A3*B2)", this.grid.getFormulaAsString("B", 3));
  135 + assertEquals("(A3*SUM(A1,A3,(A1+A2)))", this.grid.getDevelopedFormula("B", 3));
  136 +
  137 + this.grid.createCell("C", 1, 10.);
  138 + this.grid.createCell("C", 2, 20.);
  139 +
  140 + List<Cell> averageList = new ArrayList<>();
  141 + averageList.add(this.grid.getCell("C", 1));
  142 + averageList.add(this.grid.getCell("C", 2));
  143 +
  144 + this.grid.setFormula("A", 1, new Average(averageList));
  145 +
  146 + // A1
  147 + assertEquals(15, this.grid.getValue("A", 1), 0);
  148 + assertEquals("AVERAGE(C1,C2)", this.grid.getDevelopedFormula("A", 1));
  149 + // B1
  150 + assertEquals(15, this.grid.getValue("B", 1), 0);
  151 + assertEquals("(A1+A2)", this.grid.getFormulaAsString("B", 1));
  152 + assertEquals("(AVERAGE(C1,C2)+A2)", this.grid.getDevelopedFormula("B", 1));
  153 + // B2
  154 + assertEquals(32, this.grid.getValue("B", 2), 0);
  155 + assertEquals("SUM(A1,A3,B1)", this.grid.getFormulaAsString("B", 2));
  156 + assertEquals("SUM(AVERAGE(C1,C2),A3,(AVERAGE(C1,C2)+A2))", this.grid.getDevelopedFormula("B", 2));
  157 + }
  158 +
  159 + @Test
  160 + public void testGetCell() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  161 + this.createCellsWithFormula();
  162 +
  163 + Cell cell = this.grid.getCell("A", 1);
  164 +
  165 + assertEquals("A1", cell.getId());
  166 + assertEquals(10, cell.getValue(), 0);
  167 + assertEquals("A1", cell.toString());
  168 + assertEquals("A1", cell.getDevelopedFormula());
  169 + assertFalse(cell.containFormula());
  170 +
  171 + cell = this.grid.getCell("B", 2);
  172 +
  173 + assertEquals("B2", cell.getId());
  174 + assertEquals(12, cell.getValue(), 0);
  175 + assertEquals("SUM(A1,A2,A3)", cell.toString());
  176 + assertEquals("SUM(A1,A2,A3)", cell.getDevelopedFormula());
  177 + assertTrue(cell.containFormula());
  178 +
  179 + cell = this.grid.getCell("B", 3);
  180 +
  181 + assertEquals("B3", cell.getId());
  182 + assertEquals(24, cell.getValue(), 0);
  183 + assertEquals("(A3*B2)", cell.toString());
  184 + assertEquals("(A3*SUM(A1,A2,A3))", cell.getDevelopedFormula());
  185 + assertTrue(cell.containFormula());
  186 + }
  187 +
  188 + @Test(expected = CellNotFoundException.class)
  189 + public void testGetCellNotFound() throws CellNotFoundException {
  190 + Cell cell = this.grid.getCell("A", 1);
  191 + }
  192 +
  193 + @Test
  194 + public void testGetCells() throws InvalidIntervalException {
  195 + assertEquals(0, this.grid.getCells().size());
  196 +
  197 + this.createCellsWithValue();
  198 +
  199 + assertEquals(3, this.grid.getCells().size());
  200 + }
  201 +
  202 + private void createCellsWithValue() throws InvalidIntervalException {
  203 + this.grid.createCell("A", 1, 10.);
  204 + this.grid.createCell("A", 2, 0.);
  205 + this.grid.createCell("A", 3, 2.);
  206 + }
  207 +
  208 + private void createCellsWithFormula() throws CellNotFoundException, CreateCycleException, InvalidIntervalException {
  209 + this.createCellsWithValue();
  210 +
  211 + Cell a1 = this.grid.getCell("A", 1);
  212 + Cell a2 = this.grid.getCell("A", 2);
  213 + Cell a3 = this.grid.getCell("A", 3);
  214 +
  215 + List<Cell> sumList = new ArrayList<>();
  216 + sumList.add(a1);
  217 + sumList.add(a2);
  218 + sumList.add(a3);
  219 +
  220 + // A1+A2
  221 + this.grid.createCell("B", 1, new Addition(a1, a2));
  222 + // SUM(A1+A2+A3)
  223 + this.grid.createCell("B", 2, new Sum(sumList));
  224 + // A3*B2
  225 + this.grid.createCell("B", 3, new Multiplication(a3, this.grid.getCell("B", 2)));
  226 + }
205 } 227 }