Skip to content

Commit 095bbca

Browse files
committed
tests
1 parent 3a0f665 commit 095bbca

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/test_order.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import pytest
2+
from grocery_store.order import Order
3+
from grocery_store.product import Product
4+
5+
def test_order_creation():
6+
# Arrange
7+
product_one = Product("Trombone", 478.95)
8+
product_two = Product("Guitar", 327.99)
9+
product_three = Product("Triangle", 2)
10+
products = [product_one, product_two, product_three]
11+
12+
# Act
13+
sample_order = Order(products, "Shona Frederick")
14+
15+
# Assert
16+
assert len(sample_order.products) == 3
17+
assert sample_order.customer_name == "Shona Frederick"
18+
for product in products:
19+
assert product in sample_order.products
20+
21+
def test_order_creation_with_no_products():
22+
# Arrange
23+
products = []
24+
25+
# Act
26+
sample_order = Order(products, "Shona Frederick")
27+
28+
# Assert
29+
assert len(sample_order.products) == 0
30+
assert sample_order.customer_name == "Shona Frederick"
31+
32+
def test_add_product():
33+
# Arrange
34+
product_one = Product("Trombone", 478.95)
35+
product_two = Product("Guitar", 327.99)
36+
product_three = Product("Triangle", 2)
37+
products = [product_one, product_two, product_three]
38+
sample_order = Order(products, "Shona Frederick")
39+
40+
new_product = Product("Bass", 115)
41+
42+
# Act
43+
sample_order.add_product(new_product)
44+
45+
# Assert
46+
assert len(sample_order.products) == 4
47+
assert new_product in sample_order.products
48+
49+
def test_calculate_total_with_no_products():
50+
# Arrange
51+
order = Order([], "Shona Frederick")
52+
53+
# Act
54+
total = order.calculate_total()
55+
56+
# Assert
57+
assert total == 0
58+
59+
def test_calculate_total_with_multiple_products():
60+
# Arrange
61+
product_one = Product("Trombone", 478.95)
62+
product_two = Product("Guitar", 327.99)
63+
product_three = Product("Triangle", 2)
64+
products = [product_one, product_two, product_three]
65+
66+
order = Order(products, "Shona Frederick")
67+
68+
69+
# Act
70+
total = order.calculate_total()
71+
72+
# Assert
73+
assert total == pytest.approx(478.95 + 327.99 + 2)

0 commit comments

Comments
 (0)