commit
message
Adding TODOs and tests.
author
Ben Vogt <[email protected]>
date
2016-12-31 20:53:58
stats
4 file(s) changed,
45 insertions(+),
11 deletions(-)
files
README.md
src/Main.ts
src/Sheet.ts
tests/SheetTest.ts
1diff --git a/README.md b/README.md
2index 2c58574..08c560b 100644
3--- a/README.md
4+++ b/README.md
5@@ -8,4 +8,12 @@ Things I should do.
6
7 ### `setValue()`, `getValue()` on a sheet
8
9-## `load()` array of array of values for a sheet
10+### Remove A1CellKey. It is unnecessary.
11+
12+### Write documentation for A1CellKey
13+
14+### Write documentation for Cell
15+
16+### Write documentation for Sheet
17+
18+### Write documentation for Matrix
19\ No newline at end of file
20diff --git a/src/Main.ts b/src/Main.ts
21index c8b141b..9aa00fa 100644
22--- a/src/Main.ts
23+++ b/src/Main.ts
24@@ -1,5 +1,13 @@
25 import { Sheet } from "./Sheet"
26
27+var input = [
28+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "SUM(A1:D1, H1)"],
29+ [-1, -10, 2, 4, 100, 1, 50, 20, 200, -100, "MAX(A2:J2)"],
30+ [-1, -40, -53, 1, 10, 30, 10, 301, -1, -20, "MIN(A3:J3)"],
31+ [20, 50, 100, 20, 1, 5, 15, 25, 45, 23, "AVERAGE(A4:J4)"],
32+ [0, 10, 1, 10, 2, 10, 3, 10, 4, 10, "SUMIF(A5:J5,'>5')"],
33+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "SUM(K1, K2, K3, K4)"]
34+];
35 var sheet = new Sheet();
36-sheet.load();
37+sheet.load(input);
38 console.log(sheet.toString());
39diff --git a/src/Sheet.ts b/src/Sheet.ts
40index 139931f..313f340 100644
41--- a/src/Sheet.ts
42+++ b/src/Sheet.ts
43@@ -530,18 +530,18 @@ var Sheet = (function () {
44 };
45
46 var setCell = function (cellKeyString: string, value: string) {
47- instance.matrix.setCell(cellKeyString, value);
48+ instance.matrix.setCell(cellKeyString, value.toString());
49 };
50
51- this.load = function () {
52- var input = [
53- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "SUM(A1:D1, H1)"],
54- [-1, -10, 2, 4, 100, 1, 50, 20, 200, -100, "MAX(A2:J2)"],
55- [-1, -40, -53, 1, 10, 30, 10, 301, -1, -20, "MIN(A3:J3)"],
56- [20, 50, 100, 20, 1, 5, 15, 25, 45, 23, "AVERAGE(A4:J4)"],
57- [0, 10, 1, 10, 2, 10, 3, 10, 4, 10, "SUMIF(A5:J5,'>5')"],
58- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "SUM(K1, K2, K3, K4)"]
59- ];
60+ var getCell = function (cellKeyString: string) : Cell {
61+ var cell = instance.matrix.getItem(new A1CellKey(cellKeyString));
62+ if (cell === undefined) {
63+ return null;
64+ }
65+ return cell;
66+ };
67+
68+ this.load = function (input: Array<Array<any>>) {
69 for (var y = 0; y < input.length; y++) {
70 for (var x = 0; x < input[0].length; x++) {
71 // set the cell here
72@@ -565,6 +565,7 @@ var Sheet = (function () {
73 this.helper = helper;
74 this.parse = parse;
75 this.setCell = setCell;
76+ this.getCell = getCell;
77 });
78
79 export {
80diff --git a/tests/SheetTest.ts b/tests/SheetTest.ts
81new file mode 100644
82index 0000000..b802c97
83--- /dev/null
84+++ b/tests/SheetTest.ts
85@@ -0,0 +1,16 @@
86+import { Sheet } from "../src/Sheet"
87+import { assertEquals } from "./utils/Asserts"
88+
89+// Test setCell, getCell, valid
90+var sheet = new Sheet();
91+sheet.setCell("A2", "22");
92+var cell = sheet.getCell("A2");
93+assertEquals("22", cell.formula);
94+assertEquals(22, cell.value);
95+assertEquals("A2", cell.id);
96+assertEquals(1, cell.row);
97+assertEquals(0, cell.col);
98+
99+// Test getCell, null value
100+var nullCell = sheet.getCell("N1");
101+assertEquals(null, nullCell);