name:
src/test/java/io/protobase/f7/spreadsheet/GeneralDivisionTest.java
-rw-r--r--
3368
1package io.protobase.f7.spreadsheet;
2
3import io.protobase.f7.errors.DivException;
4import io.protobase.f7.errors.NAException;
5import io.protobase.f7.errors.NameException;
6import io.protobase.f7.errors.NullException;
7import io.protobase.f7.errors.NumException;
8import io.protobase.f7.errors.ParseException;
9import io.protobase.f7.errors.RefException;
10import io.protobase.f7.errors.ValueException;
11import io.protobase.f7.testutils.TestExecution;
12import org.junit.Test;
13
14public class GeneralDivisionTest extends TestExecution {
15 @Test
16 public void test_Numbers() {
17 runner().addCell("Alpha", "A1", "= 10 / 5").addExpectedValue("Alpha", "A1", 2.0).run();
18 runner().addCell("Alpha", "A1", "= 1 / 1").addExpectedValue("Alpha", "A1", 1.0).run();
19 runner().addCell("Alpha", "A1", "= 10 / -10").addExpectedValue("Alpha", "A1", -1.0).run();
20 runner().addCell("Alpha", "A1", "= -10 / -2").addExpectedValue("Alpha", "A1", 5.0).run();
21 runner().addCell("Alpha", "A1", "= 1e10 / 1.1").addExpectedValue("Alpha", "A1", 9.09090909090909E9).run();
22 }
23
24 @Test
25 public void test_Boolean() {
26 runner().addCell("Alpha", "A1", "= 9 / TRUE").addExpectedValue("Alpha", "A1", 9.0).run();
27 runner().addCell("Alpha", "A1", "= 9 / FALSE").addExpectedValue("Alpha", "A1", new DivException()).run();
28 }
29
30 @Test
31 public void test_String() {
32 runner().addCell("Alpha", "A1", "= 12 / \"3\"").addExpectedValue("Alpha", "A1", 4.0).run();
33 runner().addCell("Alpha", "A1", "= 12 / \"3e1\"").addExpectedValue("Alpha", "A1", 0.4).run();
34 runner().addCell("Alpha", "A1", "= 12 / \"2\"").addExpectedValue("Alpha", "A1", 6.0).run();
35 }
36
37 @Test
38 public void test_String_NotNumber() {
39 runner().addCell("Alpha", "A1", "= 9 / \"No good.\"").addExpectedValue("Alpha", "A1", new ValueException()).run();
40 runner().addCell("Alpha", "A1", "= 9 / \"10 10\"").addExpectedValue("Alpha", "A1", new ValueException()).run();
41 }
42
43 @Test
44 public void test_Array() {
45 runner().addCell("Alpha", "A1", "= 12 / {2}").addExpectedValue("Alpha", "A1", 6.0).run();
46 runner().addCell("Alpha", "A1", "= 12 / {2, 44}").addExpectedValue("Alpha", "A1", 6.0).run();
47 runner().addCell("Alpha", "A1", "= 12 / -{2, \"Ignore me.\"}").addExpectedValue("Alpha", "A1", -6.0).run();
48 }
49
50 @Test
51 public void test_Blank() {
52 runner().addCell("Alpha", "A1", "= 2 / M44").addExpectedValue("Alpha", "A1", new DivException()).run();
53 }
54
55 @Test
56 public void test_Errors() {
57 runner()
58 .addCell("Alpha", "A1", "= 3 / #NULL!")
59 .addCell("Alpha", "A2", "= 3 / #DIV/0!")
60 .addCell("Alpha", "A3", "= 3 / #VALUE!")
61 .addCell("Alpha", "A4", "= 3 / #REF!")
62 .addCell("Alpha", "A5", "= 3 / #NAME?")
63 .addCell("Alpha", "A6", "= 3 / #NUM!")
64 .addCell("Alpha", "A7", "= 3 / #N/A")
65 .addCell("Alpha", "A8", "= 3 / #ERROR!")
66 .addExpectedValue("Alpha", "A1", new NullException())
67 .addExpectedValue("Alpha", "A2", new DivException())
68 .addExpectedValue("Alpha", "A3", new ValueException())
69 .addExpectedValue("Alpha", "A4", new RefException())
70 .addExpectedValue("Alpha", "A5", new NameException())
71 .addExpectedValue("Alpha", "A6", new NumException())
72 .addExpectedValue("Alpha", "A7", new NAException())
73 .addExpectedValue("Alpha", "A8", new ParseException())
74 .run();
75 }
76}