Files
Test-task/tests/test_economics.py

42 lines
1.7 KiB
Python

import unittest
from src.economics import calculate, estimate_request_usd
class EconomicsTests(unittest.TestCase):
def test_weekly_and_monthly_capacity(self):
result = calculate()
self.assertEqual((result.before_hours, result.after_hours), (8, 3))
self.assertEqual(result.saved_hours, 5)
self.assertAlmostEqual(result.monthly_saved_hours, 21.65)
self.assertEqual(result.weekly_value_rub, 2500)
self.assertAlmostEqual(result.monthly_value_rub, 10825)
def test_costs_and_net_capacity(self):
result = calculate()
self.assertAlmostEqual(result.request_usd, 0.00065)
self.assertAlmostEqual(result.weekly_api_usd, 0.078)
self.assertAlmostEqual(result.monthly_api_usd, 0.33774)
self.assertAlmostEqual(result.weekly_net_rub, 2492.98)
self.assertAlmostEqual(result.monthly_net_rub, 10794.6034)
def test_discount_only_for_cached_input(self):
price = estimate_request_usd("gpt-5-mini-2025-08-07", 1200, 100, 1024)
self.assertAlmostEqual(price, (176 * 0.25 + 1024 * 0.025 + 100 * 2) / 1e6)
def test_unknown_tariff_or_missing_usage(self):
self.assertIsNone(estimate_request_usd("another-model", 100, 200))
self.assertIsNone(estimate_request_usd("gpt-5-mini", None, 200))
def test_invalid_usage(self):
with self.assertRaises(ValueError):
estimate_request_usd("gpt-5-mini", 100, 200, 101)
def test_slow_review_can_give_negative_effect(self):
self.assertLess(calculate(review_minutes=5).weekly_net_rub, 0)
self.assertEqual(calculate(leads=0).weekly_net_rub, 0)
def test_invalid_assumption(self):
with self.assertRaises(ValueError):
calculate(manual_minutes=-1)