-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bmi_calculator.py
84 lines (65 loc) · 3.24 KB
/
test_bmi_calculator.py
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
import pytest
from bmi_calculator import calculate_bmi, weight_status, get_height, get_weight, system_of_units
def mock_get_weight_kg(system_units):
return 88
def mock_get_height_meters(system_units):
return 1.92
def mock_get_weight_lbs(system_units):
return 150
def mock_get_height_inches(system_units):
return 65
def test_system_of_units(monkeypatch):
# Mock the input function to always return 'metric'
monkeypatch.setattr('builtins.input', lambda _: 'Metric')
assert system_of_units() == 'metric'
# Mock the input function to always return 'imperial'
monkeypatch.setattr('builtins.input', lambda _: 'Imperial')
assert system_of_units() == 'imperial'
def test_get_height(monkeypatch):
# Mock the input function to check if height for metric is a float
monkeypatch.setattr('builtins.input', mock_get_height_meters)
system_units = 'metric'
assert type(get_height(system_units)) is float
# Mock get_height function and return height
assert get_height(system_units) == 1.92
# Mock the input function to check if height for imperial is a float
monkeypatch.setattr('builtins.input', mock_get_height_inches)
system_units = 'imperial'
assert type(get_height(system_units)) is float
# Mock get_height function and return height
assert get_height(system_units) == 65
def test_get_weight(monkeypatch):
# Mock the input function to check if weight for metric is a float
monkeypatch.setattr('builtins.input', mock_get_weight_kg)
system_units = 'metric'
assert type(get_height(system_units)) is float
# Mock get_weight function and return weight
assert get_weight(system_units) == 88
# Mock the input function to check if weight for imperial is a float
monkeypatch.setattr('builtins.input', mock_get_weight_lbs)
system_units = 'imperial'
assert type(get_weight(system_units)) is float
# Mock get_weight function and return weight
assert get_weight(system_units) == 150
def test_calculate_bmi(monkeypatch):
# Mock the metric return values of get_weight and get_height
monkeypatch.setattr('bmi_calculator.get_weight', mock_get_weight_kg)
monkeypatch.setattr('bmi_calculator.get_height', mock_get_height_meters)
system_units = 'metric'
assert round(calculate_bmi(system_units), 2) == 23.87
# Mock the imperial return values of get_weight and get_height
monkeypatch.setattr('bmi_calculator.get_weight', mock_get_weight_lbs)
monkeypatch.setattr('bmi_calculator.get_height', mock_get_height_inches)
system_units = 'imperial'
assert round(calculate_bmi(system_units), 2) == 24.96
def test_weight_status(monkeypatch):
# Mock the metric return values of get_weight and get_height
monkeypatch.setattr('bmi_calculator.get_weight', mock_get_weight_kg)
monkeypatch.setattr('bmi_calculator.get_height', mock_get_height_meters)
system_units = 'metric'
assert weight_status(system_units) == (23.87, 'healthy 😍')
# Mock the imperial return values of get_weight and get_height
monkeypatch.setattr('bmi_calculator.get_weight', mock_get_weight_lbs)
monkeypatch.setattr('bmi_calculator.get_height', mock_get_height_inches)
system_units = 'imperial'
assert weight_status(system_units) == (24.96, 'obese 😭')