Skip to content

Commit c6865ca

Browse files
committed
pytest parking slots
1 parent 0232091 commit c6865ca

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

exercises/14.1-Parking_lot_check/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parking_state = [
1414
```
1515

1616
# 📝Instructions
17-
1. Create a function getParkingLotState() that returns an object with totalSlots, availableSlots and occupiedSlots like the following:
17+
1. Create a function get_parking_lot_state() that returns an object with total_slots, available_slots and occupied_slots like the following:
1818
const state = {
1919
totalSlots: 12,
2020
availableSlots: 3,

exercises/14.1-Parking_lot_check/app.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,21 @@
44
[1,1,2]
55
]
66

7-
8-
#Your code go here:
9-
10-
total_slots = []
11-
available_slots = []
12-
occupied_slots = []
13-
not_parking_slots = []
14-
new_dict = {}
15-
16-
17-
for x in parking_state:
18-
for j in x:
19-
if j == 1:
20-
occupied_slots.append(j)
21-
22-
for numb in parking_state:
23-
for n in numb:
24-
if n ==2:
25-
available_slots.append(n)
26-
27-
for number in parking_state:
28-
for o in number:
29-
total_slots.append(o)
30-
31-
for h in parking_state:
32-
for k in h:
33-
if k == 0:
34-
not_parking_slots.append(k)
35-
36-
new_dict.update({"total_slots" : len(total_slots), "occupied_slots":len(occupied_slots), "available_slots": len(available_slots), "not_parking_slots": len(not_parking_slots)})
37-
print(new_dict)
7+
total = []
8+
occupied = []
9+
available = []
10+
not_parking = []
11+
parking_slots = {}
12+
for numbs in parking_state:
13+
for digit in numbs:
14+
total.append(digit)
15+
if digit ==1:
16+
occupied.append(digit)
17+
elif digit == 2:
18+
available.append(digit)
19+
elif digit == 0:
20+
not_parking.append(digit)
21+
22+
parking_slots.update({"total": len(total), "occupied": len(occupied), "available": len(available), "not_parking": len(not_parking)})
23+
print(parking_slots)
3824

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import io
2+
import os
3+
import sys
4+
sys.stdout = buffer = io.StringIO()
5+
6+
import app
7+
import pytest
8+
9+
@pytest.mark.it("Print the object")
10+
def test_output():
11+
captured = buffer.getvalue()
12+
assert "\n" in captured
13+
14+
@pytest.mark.it("Have make a for loop")
15+
def test_for():
16+
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
17+
content = f.read()
18+
assert content.find("for") > 0
19+
20+
21+
22+
@pytest.mark.it("Using conditional statements")
23+
def test_conditional():
24+
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
25+
content = f.read()
26+
assert content.find('if')>0
27+
assert content.find('elif')
28+
29+

0 commit comments

Comments
 (0)