Skip to content

Commit c5ffbcf

Browse files
add test m1 022
1 parent 5a40198 commit c5ffbcf

File tree

4 files changed

+108
-8
lines changed

4 files changed

+108
-8
lines changed
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Admission Price
22

3-
A particular zoo determines the price of admission based on the age of the guest.
4-
Guests 2 years of age and less are admitted without charge.
5-
Children between 3 and 12 years of age cost $14.00. Seniors aged 65 years and over cost $18.00.
6-
Admission for all other guests is $23.00.
7-
Create a program that begins by reading the ages of all of the guests in a group from the user, with one age entered on each line.
8-
The user will enter a blank line to indicate that there are no more guests in the group.
9-
Then your program should display the admission cost for the group with an appropriate message.
10-
The cost should be displayed using two decimal places.
3+
A particular zoo determines the price of admission based on the age of the guest.
4+
- Guests 2 years of age and less are admitted without charge.
5+
- Children between 3 and 12 years of age cost $14.00.
6+
- Seniors aged 65 years and over cost $18.00.
7+
- Admission for all other guests is $23.00.
8+
9+
Create a program that begins by **reading the ages of all the guests in a group from the user**,
10+
with one age entered on each line.
11+
The user will enter a **blank lin**e (a newline character) to indicate that there are no more guests in the group.
12+
Then your program should display the admission cost for the group with an appropriate message.
13+
The cost should be displayed using **two decimal places**.
1114

1215
# Documentation
1316

@@ -18,6 +21,25 @@ For this project solution you may use:
1821
- Iteration
1922
- Strings
2023

24+
25+
# Test
26+
Execute the test to validate your solution.
27+
28+
**VSCODE**
29+
To run the test command from the README.md install the extension **runme**.
30+
Press Ctrl+Shift+x search and install the **runme** extension.
31+
32+
33+
**Python**
34+
35+
```sh
36+
python -m unittest python/test_admission_price.py
37+
```
38+
39+
or run the command from the terminal
40+
`python -m unittest projects/m1/022-admission-price/python/test_admission_price.py`
41+
42+
2143
# Deadline
2244

2345
This project requires to be completed in a maximum of **2 hours**

projects/m1/022-admission-price/__init__.py

Whitespace-only changes.

projects/m1/022-admission-price/python/__init__.py

Whitespace-only changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import importlib
2+
import io
3+
import os
4+
import re
5+
import sys
6+
from pathlib import Path
7+
from unittest import TestCase, skipIf
8+
from unittest.mock import patch
9+
10+
file_path = Path(__file__).absolute().parent / 'main.py'
11+
is_file_empty = os.stat(file_path).st_size == 0
12+
13+
14+
@skipIf(is_file_empty, 'Empty file. Test 022 Skipped')
15+
class TestNextDay(TestCase):
16+
17+
def setUp(self) -> None:
18+
self.module_name = 'projects.m1.022-admission-price.python.main'
19+
20+
@patch('builtins.input')
21+
def test_ok(self, mock_inputs):
22+
"""
23+
Check if return the correct result
24+
"""
25+
26+
mock_inputs.side_effect = [1.5, 2, 3, 50, '']
27+
28+
with patch('sys.stdout', new_callable=io.StringIO) as mock_print:
29+
sys.modules.pop(self.module_name, None)
30+
importlib.import_module(name=self.module_name, package='files')
31+
32+
result = re.findall(r'\d+\.\d+\d+', mock_print.getvalue())[-1]
33+
self.assertEqual('37.00', result, 'Total cost not correct')
34+
35+
@patch('builtins.input')
36+
def test_ok_2(self, mock_inputs):
37+
"""
38+
Check if return the correct result
39+
"""
40+
41+
mock_inputs.side_effect = [0, 78, 3, 45, '']
42+
43+
with patch('sys.stdout', new_callable=io.StringIO) as mock_print:
44+
sys.modules.pop(self.module_name, None)
45+
importlib.import_module(name=self.module_name, package='files')
46+
47+
result = re.findall(r'\d+\.\d+\d+', mock_print.getvalue())[-1]
48+
self.assertEqual('55.00', result, 'Total cost not correct')
49+
50+
@patch('builtins.input')
51+
def test_ok_3(self, mock_inputs):
52+
"""
53+
Check if return the correct result
54+
"""
55+
56+
mock_inputs.side_effect = [0, '']
57+
58+
with patch('sys.stdout', new_callable=io.StringIO) as mock_print:
59+
sys.modules.pop(self.module_name, None)
60+
importlib.import_module(name=self.module_name, package='files')
61+
62+
result = re.findall(r'\d+\.\d+\d+', mock_print.getvalue())[-1]
63+
self.assertEqual('0.00', result, 'Total cost not correct')
64+
65+
@patch('builtins.input')
66+
def test_ok_no_inputs(self, mock_inputs):
67+
"""
68+
Check if return the correct result
69+
"""
70+
71+
mock_inputs.side_effect = ['']
72+
73+
with patch('sys.stdout', new_callable=io.StringIO) as mock_print:
74+
sys.modules.pop(self.module_name, None)
75+
importlib.import_module(name=self.module_name, package='files')
76+
77+
result = re.findall(r'\d+\.\d+\d+', mock_print.getvalue())[-1]
78+
self.assertEqual('0.00', result, 'Total cost not correct')

0 commit comments

Comments
 (0)