12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import calc.Calc;
- import calc.Operator;
- import calc.Container;
- import csv.CSVWriter;
- import java.io.IOException;
- class Main {
- public static void main(String[] args) throws IOException {
- // few simple tests
- assert Calc.calculate(20f, Operator.ADD).getValue() == 20f;
- Container temp = new Container(30f, Operator.SUBTRACT, null);
- assert Calc.calculate(20f, Operator.ADD, temp).getValue() == -10f;
- float result = Calc.finalize(20f, Operator.ADD);
- assert result == 20f;
- result = Calc.finalize(20f, Operator.ADD, temp);
- assert result == -10f;
- System.out.println("AAAAA simple tests passed\n");
- // more complex tests
- // doing (4 / (4 * 4)) * 4 is the same as 10 + 2 - 8
- // first operation
- Container basis1 = new Container(4f, Operator.ADD, null);
- Container first1 = Calc.calculate(4f, Operator.MULTIPLY, basis1);
- //Container first2 = Calc.calculate(first1.getValue(), Operator.DIVIDE, basis1);
- Container first2 = Calc.calculate(
- Calc.finalize(Calc.finalize(first1), Operator.DIVIDE, new Container(1f, Operator.ADD, null))
- , Operator.MULTIPLY, first1);
- float result1 = Calc.finalize(4f, Operator.MULTIPLY, first2);
- // second operation
- float result2 = Calc.finalize(8f, Operator.SUBTRACT,
- new Container(2f, Operator.ADD,
- new Container(10f, Operator.ADD, null)
- )
- );
- // finally, assert
- assert result1 == result2;
- System.out.println("AAAAAA complex tests passed\n");
- // csv output for (4 / (4 * 4)) * 4
- CSVWriter writer = new CSVWriter("./output.csv", ';');
- writer.write("input");
- writer.write("result");
- writer.writeln();
- writer.write(basis1.getOP().repr() + String.valueOf(basis1.getValue()));
- writer.write(String.valueOf(Calc.finalize(basis1)));
- writer.writeln();
- writer.write(first1.getOP().repr() + String.valueOf(first1.getValue()));
- writer.write(String.valueOf(Calc.finalize(first1)));
- writer.writeln();
- writer.write(first2.getOP().repr() + String.valueOf(first2.getValue()));
- writer.write(String.valueOf(Calc.finalize(first2)));
- writer.writeln();
- temp = new Container(4f, Operator.MULTIPLY, first2);
- writer.write(temp.getOP().repr() + String.valueOf(temp.getValue()));
- writer.write(String.valueOf(Calc.finalize(temp)));
- writer.writeln();
- // programmatically reset to 0
- temp = new Container(temp.getValue(), Operator.SUBTRACT, temp);
- writer.write(temp.getOP().repr() + String.valueOf(temp.getValue()));
- writer.write(String.valueOf(Calc.finalize(temp)));
- writer.writeln();
- writer.close();
- }
- }
|