Compare commits

...

4 Commits

Author SHA1 Message Date
Maxim Matantsev 5a4c3146ed Update README.md 2024-03-10 22:29:32 +03:00
Maxim Matantsev c68c1b3e9d Update test_innodrive.py 2024-03-10 22:29:00 +03:00
github-classroom[bot] 66ad45007e add deadline 2024-03-07 07:37:21 +00:00
github-classroom[bot] feed190fe6 Setting up GitHub Classroom Feedback 2024-03-07 07:37:19 +00:00
2 changed files with 269 additions and 23 deletions
+6 -18
View File
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/k6Gf4phB)
# InnoDrive - Problem # InnoDrive - Problem
The InnoDrive is a hypothetical autonomous driving car-sharing service that provides transportation means in the Kazan region created by the SQR graduates from Innopolis. The service proposes two types of cars __budget__ and __luxury__. The service offers flexible two tariff plans. With the “Minute” plan, the service charges its client by time per minute of use. The Service also proposes a “Fixed price” plan where the price is fixed at the reservation time when the route is chosen. If the driver deviates from the planned route for more than 10%, the tariff plan automatically switches to the “Minute” plan. The deviation is calculated as the difference in the distance or duration from the initially planned route. The “Fixed price” plan is available for budget cars only. The Innopolis city sponsors the mobility and offers a 10% discount to Innopolis residents. The InnoDrive is a hypothetical autonomous driving car-sharing service that provides transportation means in the Kazan region created by the SQR graduates from Innopolis. The service proposes two types of cars __budget__ and __luxury__. The service offers flexible two tariff plans. With the “Minute” plan, the service charges its client by time per minute of use. The Service also proposes a “Fixed price” plan where the price is fixed at the reservation time when the route is chosen. If the driver deviates from the planned route for more than 10%, the tariff plan automatically switches to the “Minute” plan. The deviation is calculated as the difference in the distance or duration from the initially planned route. The “Fixed price” plan is available for budget cars only. The Innopolis city sponsors the mobility and offers a 10% discount to Innopolis residents.
@@ -49,15 +50,15 @@ Please replace each `no` with a `yes` for each parameter if it passes domain tes
* **Ride Type:** no * **Ride Type:** no
* **Ride Plan:** no * **Ride Plan:** yes
* **Distance:** no * **Distance:** yes
* **Inno Discount:** no * **Inno Discount:** no
* **Type Plan:** no * **Type Plan:** no
* **Time:** no * **Time:** yes
> **Note:** Type Plan here refers to checking the compatibility of ride type and ride plan > **Note:** Type Plan here refers to checking the compatibility of ride type and ride plan
@@ -71,9 +72,9 @@ Please replace each `no` with a `yes` for each parameter if it passes computatio
* **Discount Calc:** no * **Discount Calc:** no
* **Budget Min:** no * **Budget Min:** yes
* **Budget Km:** no * **Budget Km:** yes
* **Luxury Min:** no * **Luxury Min:** no
@@ -106,16 +107,3 @@ The effectiveness of your test suite will be assessed based on its ability to de
### Example. Error indication. (-1 for the price) ### Example. Error indication. (-1 for the price)
![image](https://github.com/QualityInUse/project-innodrive/assets/2123188/c1a56de0-9229-4686-8057-bac8402a5f67) ![image](https://github.com/QualityInUse/project-innodrive/assets/2123188/c1a56de0-9229-4686-8057-bac8402a5f67)
+263 -5
View File
@@ -1,16 +1,274 @@
# This is the template for the InnoDrive e2e and domain and computation test cases. # This is the template for the InnoDrive e2e and domain and computation test cases.
import pytest import pytest
import json
from httpx import Client from httpx import Client
my_spec = {
"budget_minute_price": 17,
"luxury_minute_price": 37,
"budget_km_price": 11,
"deviation": 0.14,
"inno_discount": 0.06
}
type_cases = ['budget', 'luxury', 'string']
plan_cases = ['fixed_price', 'minute', 'string']
distance_cases = [-1, 0, 10]
inno_discount = ['yes', 'no', 'string']
time_cases = [-1, 0, 10]
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def test_app(): def test_app():
client = Client(base_url="https://innodrive.containers.cloud.ru") client = Client(base_url="https://instructors.pg.innopolis.university/innodrive")
yield client # testing happens here yield client
@pytest.mark.parametrize("email", ["i.ivanov@innopolis.university"])
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_spec(test_app, email): def test_spec(test_app, email):
response = test_app.get("/spec/"+email) response = test_app.get("/spec/" + email)
assert response.status_code == 200 assert response.status_code == 200
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"type, plan, distance, time, inno_discount, expected_code",
[
# Test case 1: Budget, fixed_price, distance = 10, time = 10, with discount
(type_cases[0], plan_cases[0], distance_cases[2], time_cases[2], inno_discount[0], 200),
# Test case 2: Budget, minute, distance = 10, time = 10, with discount
(type_cases[0], plan_cases[1], distance_cases[2], time_cases[2], inno_discount[0], 200),
# Test case 3: Budget, minute, distance = -1, time = 10, with discount
(type_cases[0], plan_cases[1], distance_cases[0], time_cases[2], inno_discount[0], 406),
# Test case 4: Luxury, minute, distance = 10, time = 10, with discount
(type_cases[1], plan_cases[1], distance_cases[2], time_cases[2], inno_discount[0], 200),
# Test case 5: Budget, fixed_price, distance = 0, time = 10, with discount
(type_cases[0], plan_cases[0], distance_cases[1], time_cases[2], inno_discount[0], 406),
]
)
def test_distance(test_app, email, type, plan, distance, time, inno_discount, expected_code):
data = {
"type": type,
"plan": plan,
"distance": distance,
"planned_distance": distance,
"time": time,
"planned_time": time,
"inno_discount": inno_discount
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_code
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"ride_type, expected_output",
[
# Test case 1: Budget
(type_cases[0], 200),
# Test case 2: Luxury
(type_cases[1], 200),
# Test case 3: nonsense
(type_cases[2], 406),
]
)
def test_ride_type(test_app, email, ride_type, expected_output):
# gives 200 on nonsense for ride type
data = {
"type": ride_type,
"plan": "fixed_price",
"distance": 10,
"planned_distance": 10,
"time": 10,
"planned_time": 10,
"inno_discount": "no"
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_output
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"plan_type, expected_output",
[
# Test case 1: Minute
(plan_cases[0], 200),
# Test case 2: Fixed
(plan_cases[1], 200),
# Test case 3: nonsense
(plan_cases[2], 406),
]
)
def test_ride_plan(test_app, email, plan_type, expected_output):
data = {
"type": "budget",
"plan": plan_type,
"distance": 10,
"planned_distance": 10,
"time": 10,
"planned_time": 10,
"inno_discount": "no"
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_output
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"discount, expected_output",
[
# Test case 1: Minute
(inno_discount[0], 200),
# Test case 2: Fixed
(inno_discount[1], 200),
# Test case 3: nonsense
(inno_discount[2], 406),
]
)
def test_discount(test_app, email, discount, expected_output):
# gives 200 on nonsense for discount
data = {
"type": "budget",
"plan": "minute",
"distance": 10,
"planned_distance": 10,
"time": 10,
"planned_time": 10,
"inno_discount": discount
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_output
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"time, expected_output",
[
# Test case 1: Minute
(time_cases[0], 406),
# Test case 2: Fixed
(time_cases[1], 406),
# Test case 3: nonsense
(time_cases[2], 200),
]
)
def test_time(test_app, email, time, expected_output):
data = {
"type": "budget",
"plan": "minute",
"distance": 10,
"planned_distance": 10,
"time": time,
"planned_time": time,
"inno_discount": "no"
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_output
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
@pytest.mark.parametrize(
"ride_type, plan_type, expected_output",
[
# Test case 1: Budget + minute
(type_cases[0], plan_cases[1], 200),
# Test case 2: Budget + fixed
(type_cases[0], plan_cases[0], 200),
# Test case 3: Luxury + minute
(type_cases[1], plan_cases[1], 200),
# Test case 4: Luxury + fixed
(type_cases[1], plan_cases[0], 406),
]
)
def test_type_plan(test_app, email, ride_type, plan_type, expected_output):
#Luxury + fixed gives 200 - error
data = {
"type": ride_type,
"plan": plan_type,
"distance": 10,
"planned_distance": 10,
"time": 10,
"planned_time": 10,
"inno_discount": "no"
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.status_code == expected_output
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_type_budget_min_computational_ok(test_app, email):
data = {
"type": type_cases[0],
"plan": plan_cases[1],
"distance": distance_cases[2],
"planned_distance": distance_cases[2],
"time": time_cases[2],
"planned_time": time_cases[2],
"inno_discount": inno_discount[1]
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.json()['price'] == my_spec["budget_minute_price"] * time_cases[2]
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_type_budget_km_computational_ok(test_app, email):
data = {
"type": type_cases[0],
"plan": plan_cases[0],
"distance": distance_cases[2],
"planned_distance": distance_cases[2],
"time": time_cases[2],
"planned_time": time_cases[2],
"inno_discount": inno_discount[1]
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.json()['price'] == my_spec["budget_km_price"] * distance_cases[2]
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_type_luxury_min_computational_err(test_app, email):
# computational Error => 481 got, but require 370
data = {
"type": type_cases[1],
"plan": plan_cases[1],
"distance": distance_cases[2],
"planned_distance": distance_cases[2],
"time": time_cases[2],
"planned_time": time_cases[2],
"inno_discount": inno_discount[1]
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.json()['price'] == my_spec["luxury_minute_price"] * time_cases[2]
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_type_luxury_min_deviation_err(test_app, email):
# computational Error => 481 got, but max price with deviation is 421.8
data = {
"type": type_cases[1],
"plan": plan_cases[1],
"distance": distance_cases[2],
"planned_distance": distance_cases[2],
"time": time_cases[2],
"planned_time": time_cases[2],
"inno_discount": inno_discount[1]
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.json()['price'] == my_spec["luxury_minute_price"] * time_cases[2] * (1+my_spec["deviation"])
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
def test_type_luxury_discount_err(test_app, email):
# discount is not being applied - unreal to calculate it
data = {
"type": type_cases[0],
"plan": plan_cases[0],
"distance": distance_cases[2],
"planned_distance": distance_cases[2],
"time": time_cases[2],
"planned_time": time_cases[2],
"inno_discount": inno_discount[0]
}
response = test_app.post("/price/" + email, content=json.dumps(data))
assert response.json()['price'] == my_spec["budget_km_price"] * distance_cases[2] * (1 - my_spec["inno_discount"])