Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
92 lines (70 loc) · 2.63 KB

File metadata and controls

92 lines (70 loc) · 2.63 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
SIMPLEX: 0.6
DATA: Item
id: string
name: string
price: number
quantity: number
DATA: Cart
items: list of Item
total: number
FUNCTION: add_to_cart(cart, item) → Cart
RULES:
- [add.R1] if item already in cart, increase quantity
- [add.R2] otherwise add item to cart
- [add.R3] recalculate total
DONE_WHEN:
- [add.D1] item is in cart
- [add.D2] total reflects all items
EXAMPLES:
- [add.E1] value: (empty_cart, item_a) → { items: [item_a], total: 10.00 }
- [add.E2] value: (cart_with_a, item_a) → { items: [item_a(qty:2)], total: 20.00 }
- [add.E3] value: (cart_with_a, item_b) → { items: [item_a, item_b], total: 25.00 }
- [add.E4] error: (empty_cart, invalid_item) → "Item must have id, name, and price"
- [add.E5] error: (empty_cart, negative_quantity_item) → "Quantity cannot be negative"
ERRORS:
- [add.X1] invalid item → "Item must have id, name, and price"
- [add.X2] negative quantity → "Quantity cannot be negative"
- any unhandled condition → fail with descriptive message
COVERS:
- add.E1 → add.R2, add.R3, add.D1, add.D2
- add.E2 → add.R1, add.R3, add.D1, add.D2
- add.E3 → add.R2, add.R3, add.D1, add.D2
- add.E4 → add.X1
- add.E5 → add.X2
FUNCTION: remove_from_cart(cart, item_id) → Cart
RULES:
- [remove.R1] find item by id
- [remove.R2] remove it from cart
- [remove.R3] recalculate total
DONE_WHEN:
- [remove.D1] item no longer in cart
- [remove.D2] total is updated
EXAMPLES:
- [remove.E1] value: (cart_with_a_and_b, "a") → { items: [item_b], total: 15.00 }
- [remove.E2] value: (cart_with_a, "a") → { items: [], total: 0.00 }
- [remove.E3] value: (empty_cart, "a") → { items: [], total: 0.00 }
ERRORS:
- [remove.X1] item not found → return cart unchanged (not an error)
- any unhandled condition → fail with descriptive message
COVERS:
- remove.E1 → remove.R1, remove.R2, remove.R3, remove.D1, remove.D2
- remove.E2 → remove.R1, remove.R2, remove.R3, remove.D1, remove.D2
- remove.E3 → remove.R1, remove.R3, remove.D1, remove.D2, remove.X1
FUNCTION: calculate_total(cart) → number
RULES:
- [total.R1] sum price × quantity for all items
DONE_WHEN:
- [total.D1] total is accurate
EXAMPLES:
- [total.E1] value: (empty_cart) → 0.00
- [total.E2] value: (cart_with_a) → 10.00
- [total.E3] value: (cart_with_a_and_b) → 25.00
- [total.E4] value: (invalid_cart) → 0.00
ERRORS:
- [total.X1] invalid cart → 0.00
- any unhandled condition → fail with descriptive message
COVERS:
- total.E1 → total.R1, total.D1
- total.E2 → total.R1, total.D1
- total.E3 → total.R1, total.D1
- total.E4 → total.X1
Morty Proxy This is a proxified and sanitized view of the page, visit original site.