Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterpieceElbow committed Jan 18, 2022
1 parent 13cf154 commit 08d54c1
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 9 deletions.
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,78 @@
# Python boilerplate for GitHub tasks
# Washing Station

- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start
- Implement the task described [here](app/main.py)

You own a car washing station. Washing cost calculation
takes a lot of time, and you decide to automate this
calculation. The washing cost will depend on car comfort
class, car cleanness degree, wash station average rating
and car wash distance from the center of the city.

Create class `Car`, its constructor takes and stores
3 arguments:
1. `comfort_class` - comfort class of a car, from 1 to 7
3. `clean_mark` - car cleanness mark, from very
dirty - 1 to absolute clean - 10
4. `brand` - brand of the car

Create class `CarWashStation`, its constructor takes and
stores 4 arguments:
1. `distance_from_cite_center` - how far station from
the city center, from 1.0 to 10.0
2. `clean_power` - `clean_mark` to which this car wash station
washes
3. `average_rating` - average rating of the station,
from 1.0 to 5.0, rounded to 1 decimal
4. `count_of_ratings` - number of people who rated

`CarWashStation` should have such methods:
1. `serve_cars` Method that takes a list of `Car`'s, washes only
cars with `clean_mark` < `clean_power` of wash station
and returns total wash cost, rounded to 1 decimal
2. `calculate_washing_price` Method that calculates cost for a
single car wash,
cost is calculated as: car's comfort class * difference of car's
clean mark and wash station's clean power * car wash station
rating / car wash station
distance to the center of the city, returns number rounded
to 1 decimal
3. `wash_single_car` Every car after wash is clean, so it should
have `clean_mark` equals wash station's `clean_power`,
make individual method for this.
4. `rate_service` Method to add a single rate.

You can add own methods if you need.

Example:
```python
bmw = Car(3, 3, 'BMW')
audi = Car(4, 9, 'Audi')
mercedes = Car(7, 1, 'Mercedes')

ws = CarWashingStation(6, 8, 3.9, 11)

income = ws.serve_cars([
bmw,
audi,
mercedes
])

income == 41.6

bmw.clean_mark == 8
audi.clean_mark == 9
mercedes.clean_mark == 8
# audi wasn't washed
# all other cars are washed to '8'

ford = Car(2, 1, 'Ford')
wash_cost = ws.calculate_washing_price(ford)
# only calculating cost, not washing
wash_cost == 11.7
ford.clean_mark == 1

ws.rate_service(5)

ws.count_of_ratings == 12
ws.average_rating == 4.0
```
11 changes: 8 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# TODO: add initial code
def hello_world():
return "Hello, world!"
class Car:
# write your code here
pass


class CarWashStation:
# write your code here
pass
101 changes: 97 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,99 @@
# TODO: add tests
from app.main import hello_world
import pytest

from app.main import Car, CarWashStation

def test_hello_world():
assert hello_world() == "Hello, world!"

def test_car():
bmw = Car(2, 3, "BMW")
assert bmw.comfort_class == 2, "Class Car should store 'comfort_class'"
assert bmw.clean_mark == 3, "Class Car should store 'clean_mark'"
assert bmw.brand == "BMW", "Class Car should store 'brand'"


@pytest.mark.parametrize(
"cars,washstation,total_cost",
[
([], CarWashStation(3, 9, 4.4, 144), 0),
([Car(2, 1, "Ford")], CarWashStation(3, 9, 4.2, 11), 22.4),
([Car(2, 9, "Ford")], CarWashStation(3, 8, 4.2, 11), 0),
(
[Car(3, 3, "BMW"), Car(4, 5, "Audi"), Car(7, 1, "Mercedes")],
CarWashStation(6, 7, 3.9, 11),
40.3,
),
(
[Car(3, 3, "BMW"), Car(4, 5, "Audi"), Car(7, 9, "Mercedes")],
CarWashStation(6, 7, 3.9, 11),
13.0,
),
(
[Car(3, 8, "BMW"), Car(4, 8, "Audi"), Car(7, 9, "Mercedes")],
CarWashStation(6, 7, 3.9, 11),
0,
),
],
)
def test_car_wash_station(cars, washstation, total_cost):
income = washstation.serve_cars(cars)
assert income == total_cost, f"Income should equal to {total_cost}"


@pytest.mark.parametrize(
"cars,washstation,cars_clean_marks",
[
([Car(2, 1, "Ford")], CarWashStation(3, 9, 4.2, 11), [9]),
([Car(2, 9, "Ford")], CarWashStation(3, 8, 4.2, 11), [9]),
(
[Car(3, 3, "BMW"), Car(4, 5, "Audi"), Car(7, 1, "Mercedes")],
CarWashStation(6, 7, 3.9, 11),
[7, 7, 7],
),
(
[Car(3, 3, "BMW"), Car(4, 5, "Audi"), Car(7, 9, "Mercedes")],
CarWashStation(2, 8, 4.8, 13),
[8, 8, 9],
),
],
)
def test_car_is_washed(cars, washstation, cars_clean_marks):
income = washstation.serve_cars(cars)
assert [car.clean_mark for car in cars] == cars_clean_marks, (
f"Car should keep his 'clear_mark' if it >= 'clear_power' of wash station, "
f"otherwise it should equal to 'clear_power'"
)


@pytest.mark.parametrize(
"car,washstation,mark",
[
(Car(2, 1, "Ford"), CarWashStation(3, 10, 4.2, 11), 1),
(Car(4, 5, "Audi"), CarWashStation(6, 8, 3.9, 11), 5),
(Car(3, 3, "BMW"), CarWashStation(2, 9, 4.8, 13), 3),
],
)
def test_car_cost_check_not_washed(car, washstation, mark):
cost = washstation.calculate_washing_price(car)
assert car.clean_mark == mark, (
f"Method 'calculate_washing_price' should not change" f"'car.clean_mark'"
)


@pytest.mark.parametrize(
"init_avg_rating,init_num_ratings,mark,result_avg_rating,result_num_ratings",
[
(2.2, 2, 5, 3.1, 3),
(2.4, 11, 5, 2.6, 12),
(3.8, 7, 2, 3.6, 8),
(4.4, 42, 4, 4.4, 43),
],
)
def test_rate_service(
init_avg_rating, init_num_ratings, mark, result_avg_rating, result_num_ratings
):
ws = CarWashStation(2, 9, init_avg_rating, init_num_ratings)
ws.rate_service(mark)
assert ws.average_rating == result_avg_rating, (
f"'average_rating' should equal to {result_avg_rating}, "
f"when initial 'average_rating' was {init_avg_rating}, "
f"and initial 'count_of_ratings' was {init_num_ratings}"
)

0 comments on commit 08d54c1

Please sign in to comment.