@@ -0,0 +1,60 @@
|
||||
"""Доп. тесты calc engine (пустой рацион, compound)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.lab.calc.engine import calculate_ration
|
||||
|
||||
|
||||
class LabCalcEngineTests(unittest.TestCase):
|
||||
def test_empty_lines_returns_errors_or_totals(self) -> None:
|
||||
result = calculate_ration("BEEF", [], {})
|
||||
self.assertIn("totals", result)
|
||||
self.assertIn("indicators", result)
|
||||
|
||||
def test_dairy_ration_type(self) -> None:
|
||||
result = calculate_ration(
|
||||
"DAIRY",
|
||||
[
|
||||
{
|
||||
"daily_kg": 50,
|
||||
"in_ration": True,
|
||||
"in_compound": True,
|
||||
"dry_matter": 850,
|
||||
"nutrients": {"Сыр. Протеин": 100},
|
||||
}
|
||||
],
|
||||
{},
|
||||
)
|
||||
total = next(t["value"] for t in result["totals"] if t["key"] == "total_kg")
|
||||
self.assertEqual(total, 50)
|
||||
|
||||
def test_bra_derived_from_protein_and_usp(self) -> None:
|
||||
result = calculate_ration(
|
||||
"DAIRY",
|
||||
[
|
||||
{
|
||||
"daily_kg": 10,
|
||||
"in_ration": True,
|
||||
"in_compound": False,
|
||||
"dry_matter": 850,
|
||||
"nutrients": {"Сыр. Протеин": 100, "уСП": 80},
|
||||
},
|
||||
{
|
||||
"daily_kg": 5,
|
||||
"in_ration": True,
|
||||
"in_compound": False,
|
||||
"dry_matter": 880,
|
||||
"nutrients": {"Сыр. Протеин": 200, "уСП": 160},
|
||||
},
|
||||
],
|
||||
{},
|
||||
heads_per_trip=1,
|
||||
)
|
||||
cp = next(i["content"] for i in result["indicators"] if i["key"] == "crude_protein")
|
||||
usp = next(i["content"] for i in result["indicators"] if i["key"] == "usp")
|
||||
rnb = next(i["content"] for i in result["indicators"] if i["key"] == "rnb")
|
||||
self.assertAlmostEqual(cp, 10 * 100 + 5 * 200)
|
||||
self.assertAlmostEqual(usp, 10 * 80 + 5 * 160)
|
||||
self.assertAlmostEqual(rnb, (cp - usp) / 6.25)
|
||||
Reference in New Issue
Block a user