-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_spreadsheet.py
More file actions
59 lines (47 loc) · 1.46 KB
/
test_spreadsheet.py
File metadata and controls
59 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from spreadsheet import Spreadsheet
import pytest
def test_writes_expected_values():
"""Can write basic values successfully"""
s = Spreadsheet()
s.put("A1", "1")
s.put("A2", "2")
s.put("A3", "3")
assert s.cells == {"A1": "1", "A2": "2", "A3": "3"}
def test_writes_equations_successfully():
"""Can write equations successfully"""
s = Spreadsheet()
s.put("B1", "=A1+A2")
s.put("B2", "=B1+2")
s.put("B3", "=B1+B2+5")
assert s.cells == {"B1": "=A1+A2", "B2": "=B1+2", "B3": "=B1+B2+5"}
def test_gets_correct_values():
"""Can get the correct value from the spreadsheet"""
s = Spreadsheet()
s.put("A1", "1")
assert s.get("A1") == 1
def test_gets_correct_equations_value():
"""Fetches the correct value for equations"""
s = Spreadsheet()
s.put("A1", "1")
s.put("A2", "2")
s.put("B1", "=A1+A2")
assert s.get("B1") == 3
def test_overwrites_caches_with_update_values():
"""Can overwrite the cached value when new key-value is put in"""
s = Spreadsheet()
s.put("A1", "1")
s.put("A2", "2")
s.put("A3", "3")
s.put("B1", "=A1+A2")
s.put("B2", "=B1+2")
s.put("B3", "=B1+B2+5")
assert s.get("B3") == 13
s.put("B2", "=4+5+A1")
assert s.get("B3") == 18
def test_raises_error_for_cycle_detection():
"""Raises an error for cycle detection"""
s = Spreadsheet()
s.put("A1", "=A2")
s.put("A2", "=A1")
with pytest.raises(ValueError):
s.get("A1")