Skip to content

Commit

Permalink
Merge pull request mate-academy#151 from mate-academy/add-checklist
Browse files Browse the repository at this point in the history
checklist and test
  • Loading branch information
DmytroSvirsa authored Sep 19, 2022
2 parents b53c403 + a07cd98 commit 5eca31a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ ws.rate_service(5)

ws.count_of_ratings == 12
ws.average_rating == 4.0
```
```

### Note: Check your code using this [checklist](checklist.md) before pushing your solution.
80 changes: 80 additions & 0 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Check Your Code Against the Following Points

## Code Style

1. If you have some long math, you can split it onto additional variables,
or break after binary operations (not before - it cause the W504 errors)

Good example:

```python
fuel_consumption = max_fuel_consumption * height_fuel_consumption_coeficient
estimated_speed = plan_max_speed - wind_awerage_speed * wind_angle_coefisient
estimated_time = distance_to_the_destinatoin / estimated_speed
how_much_fuel_needed = fuel_consumption * estimated_time * overlap_coeficient
```

Good example:

```python
how_much_fuel_needed = (max_fuel_consumption
* height_fuel_consumption_coeficient
* distance_to_the_destinatoin
/ (plan_max_speed
- wind_awerage_speed
* wind_angle_coefisient)
* overlap_coeficient)
```

Bad example:

```python
how_much_fuel_needed = max_fuel_consumption \
* height_fuel_consumption_coeficient \
* distance_to_the_destinatoin / (
plan_max_speed
- wind_awerage_speed
* wind_angle_coefisient
) * overlap_coeficient
```

2. Use descriptive and correct variable names.

Good example:

```python
def get_full_name(first_name: str, last_name: str) -> str:
return f"{first_name} {last_name}"
```

Bad example:
```python
def get_full_name(x: str, y: str) -> str:
return f"{x} {y}"
```

## Clean Code

1. You can avoid else when have return statement.

Good example:

```python
def is_adult(age: int) -> str:
if age >= 18:
return "adult"
return "not an adult"
```

Bad example:

```python
def is_adult(age: int) -> str:
if age >= 18:
return "adult"
else:
return "not an adult"
```

2. Add comments, prints, and functions to check your solution when you write your code.
Don't forget to delete them when you are ready to commit and push your code.
22 changes: 22 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest

from app.main import Car, CarWashStation
Expand Down Expand Up @@ -37,6 +39,12 @@ def test_car_wash_station(cars, wash_station, total_cost):
income = wash_station.serve_cars(cars)
assert income == total_cost, f"Income should equal to {total_cost}"

def test_wash_single_car_is_called():
with patch.object(CarWashStation, 'wash_single_car') as mock_method:
CarWashStation(3, 9, 4, 11).serve_cars([Car(2, 1, "Ford")])
assert mock_method.called, "Expected 'wash_single_car' to have " \
"been called inside 'serve_cars' method"


@pytest.mark.parametrize(
"cars,wash_station,cars_clean_marks",
Expand Down Expand Up @@ -101,3 +109,17 @@ def test_rate_service(
f"'count_of_ratings' should equal to {result_num_ratings}, "
f"when initial 'count_of_ratings' was {init_num_ratings}"
)


def test_unnecessary_comment():
if os.path.exists(os.path.join(os.pardir, "app", "main.py")):
main_path = os.path.join(os.pardir, "app", "main.py")
else:
main_path = os.path.join("app", "main.py")

with open(main_path, "r") as main:
main_content = main.read()

assert (
"# write your code here" not in main_content
), "Remove unnecessary comment"

0 comments on commit 5eca31a

Please sign in to comment.