spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Adding edge case tests for Sheet.ts
author
Ben Vogt <[email protected]>
date
2017-01-05 23:48:00
stats
2 file(s) changed, 23 insertions(+), 4 deletions(-)
files
README.md
tests/SheetTest.ts
 1diff --git a/README.md b/README.md
 2index 89ab3ac..584aca0 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -6,9 +6,5 @@ Things I should do.
 6 
 7 ### Write tests for supported formulas.
 8 
 9-### Write tests for Sheet.ts edge cases
10-* If I set a cell with a formula, update a dependency, the value of that cell should change.
11-* If I set a cell with a formula, update it, the value of that cell should change.
12-
13 ### Parsing interesting values
14 * Expand tests greatly.
15\ No newline at end of file
16diff --git a/tests/SheetTest.ts b/tests/SheetTest.ts
17index 8f87f39..1a0d53a 100644
18--- a/tests/SheetTest.ts
19+++ b/tests/SheetTest.ts
20@@ -122,4 +122,26 @@ var A4 = sheet.getCell("A4");
21 assertEquals("99.8", A4.getValue());
22 assertEquals("SUM(A1:A3, MAX(A1, A3))", A4.getFormula());
23 assertEquals(null, A4.getError());
24-assertArrayEquals(['A1', 'A2', 'A3'], A4.getDependencies());
25\ No newline at end of file
26+assertArrayEquals(['A1', 'A2', 'A3'], A4.getDependencies());
27+
28+// Test dependency calculation propagation
29+var sheet  = new Sheet();
30+sheet.setCell("A1", "1");
31+sheet.setCell("A2", "=SUM(A1, 100)");
32+var A2 = sheet.getCell("A2");
33+assertEquals(101, A2.getValue());
34+assertArrayEquals(['A1'], A2.getDependencies());
35+sheet.setCell("A1", "2");
36+assertEquals(102, A2.getValue());
37+assertArrayEquals(['A1'], A2.getDependencies());
38+
39+// Test cell formula update
40+var sheet  = new Sheet();
41+sheet.setCell("A1", "1");
42+sheet.setCell("A2", "=SUM(A1, 100)");
43+var A2 = sheet.getCell("A2");
44+assertEquals(101, A2.getValue());
45+assertArrayEquals(['A1'], A2.getDependencies());
46+sheet.setCell("A2", "=MAX(A1, 100)");
47+assertEquals(100, A2.getValue());
48+assertArrayEquals(['A1'], A2.getDependencies());
49\ No newline at end of file