elite-engineering/tests/test_trade.py

56 lines
1.9 KiB
Python
Raw Normal View History

2022-01-20 16:04:54 +00:00
import fractions
import unittest
from elite_engineering import trade
class TradeCalculationTests(unittest.TestCase):
def format_ratio(self, ratio: fractions.Fraction) -> str:
return "{}{}".format(ratio.numerator, ratio.denominator)
def test_same_category_exchange(self):
expected = [
["1 → 1", "1 → 3", "1 → 9", "1 → 27", "1 → 81"],
["6 → 1", "1 → 1", "1 → 3", "1 → 9", "1 → 27"],
["36 → 1", "6 → 1", "1 → 1", "1 → 3", "1 → 9"],
["216 → 1", "36 → 1", "6 → 1", "1 → 1", "1 → 3"],
["1296 → 1", "216 → 1", "36 → 1", "6 → 1", "1 → 1"],
]
actual = [
[
self.format_ratio(
trade.Material("name", "category", grade_in).trade_ratio(
trade.Material("name", "category", grade_out)
)
)
for grade_out in [1, 2, 3, 4, 5]
]
for grade_in in [1, 2, 3, 4, 5]
]
self.assertEqual(expected, actual)
def test_different_category_exchange(self):
expected = [
["6 → 1", "2 → 1", "2 → 3", "2 → 9", "2 → 27"],
["36 → 1", "6 → 1", "2 → 1", "2 → 3", "2 → 9"],
["216 → 1", "36 → 1", "6 → 1", "2 → 1", "2 → 3"],
["1296 → 1", "216 → 1", "36 → 1", "6 → 1", "2 → 1"],
["7776 → 1", "1296 → 1", "216 → 1", "36 → 1", "6 → 1"],
]
actual = [
[
self.format_ratio(
trade.Material("name", "category", grade_in).trade_ratio(
trade.Material("name", "other", grade_out)
)
)
for grade_out in [1, 2, 3, 4, 5]
]
for grade_in in [1, 2, 3, 4, 5]
]
self.assertEqual(expected, actual)