71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""Расчёт групп выгрузки — регрессия баготеста #2 (тип «Количество голов»)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from app.services.recipe_calculator import calculate_unloading_groups
|
|
|
|
|
|
class RecipeCalculatorUnloadingTests(unittest.TestCase):
|
|
def test_heads_distribution_recalculates_when_value_changes(self) -> None:
|
|
total_trip_weight = 3094.83
|
|
heads_count = 137
|
|
|
|
groups_v1, totals_v1 = calculate_unloading_groups(
|
|
[
|
|
{"distributionType": "heads", "value": 67},
|
|
{"distributionType": "heads", "value": 68},
|
|
],
|
|
total_trip_weight,
|
|
heads_count,
|
|
)
|
|
groups_v2, totals_v2 = calculate_unloading_groups(
|
|
[
|
|
{"distributionType": "heads", "value": 65},
|
|
{"distributionType": "heads", "value": 68},
|
|
],
|
|
total_trip_weight,
|
|
heads_count,
|
|
)
|
|
|
|
self.assertNotEqual(
|
|
groups_v1[0]["calculatedWeight"],
|
|
groups_v2[0]["calculatedWeight"],
|
|
"вес первой группы должен меняться при смене числа голов",
|
|
)
|
|
self.assertEqual(totals_v1["totalHeads"], 135)
|
|
self.assertEqual(totals_v2["totalHeads"], 133)
|
|
self.assertEqual(groups_v1[1]["calculatedWeight"], groups_v2[1]["calculatedWeight"])
|
|
|
|
def test_heads_weight_formula_matches_trip_share(self) -> None:
|
|
total_trip_weight = 2000.0
|
|
heads_count = 100
|
|
value = 25
|
|
|
|
groups, _ = calculate_unloading_groups(
|
|
[{"distributionType": "heads", "value": value}],
|
|
total_trip_weight,
|
|
heads_count,
|
|
)
|
|
|
|
expected = round((total_trip_weight / heads_count) * value / 5) * 5
|
|
self.assertEqual(groups[0]["calculatedWeight"], expected)
|
|
|
|
def test_percent_distribution_unchanged(self) -> None:
|
|
groups, totals = calculate_unloading_groups(
|
|
[
|
|
{"distributionType": "percent", "value": 60},
|
|
{"distributionType": "percent", "value": 40},
|
|
],
|
|
1590.0,
|
|
100,
|
|
)
|
|
self.assertEqual(groups[0]["calculatedWeight"], 955)
|
|
self.assertEqual(groups[1]["calculatedWeight"], 635)
|
|
self.assertEqual(totals["totalPercent"], 100.0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|