elite-engineering/tests/test_trade.py

89 lines
2.9 KiB
Python
Raw Normal View History

2022-01-20 16:04:54 +00:00
import fractions
import unittest
2022-01-22 04:37:58 +00:00
from returns.curry import partial
2022-01-20 16:57:53 +00:00
from returns.maybe import Maybe
2022-01-20 16:04:54 +00:00
from elite_engineering import trade
class TradeCalculationTests(unittest.TestCase):
def format_ratio(self, ratio: fractions.Fraction) -> str:
return "{}{}".format(ratio.numerator, ratio.denominator)
2022-01-20 16:57:53 +00:00
def test_same_category_exchange(self) -> None:
2022-01-20 16:04:54 +00:00
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"],
2022-01-20 16:57:53 +00:00
["-", "216 → 1", "36 → 1", "6 → 1", "1 → 1"],
2022-01-20 16:04:54 +00:00
]
2022-01-22 04:37:58 +00:00
material = partial(
trade.Material,
"name",
trade.MaterialType.raw,
"category",
)
2022-01-20 16:04:54 +00:00
actual = [
[
2022-01-22 04:37:58 +00:00
material(grade_in)
.trade_ratio(material(grade_out))
2022-01-20 16:57:53 +00:00
.map(self.format_ratio)
.value_or("-")
2022-01-20 16:04:54 +00:00
for grade_out in [1, 2, 3, 4, 5]
]
for grade_in in [1, 2, 3, 4, 5]
]
self.assertEqual(expected, actual)
2022-01-20 16:57:53 +00:00
def test_different_category_exchange(self) -> None:
2022-01-20 16:04:54 +00:00
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"],
2022-01-20 16:57:53 +00:00
["-", "216 → 1", "36 → 1", "6 → 1", "2 → 1"],
["-", "-", "216 → 1", "36 → 1", "6 → 1"],
2022-01-20 16:04:54 +00:00
]
2022-01-22 04:37:58 +00:00
type_ = trade.MaterialType.raw
material = partial(trade.Material, "name", trade.MaterialType.raw)
2022-01-20 16:04:54 +00:00
actual = [
[
2022-01-22 04:37:58 +00:00
material("category", grade_in)
.trade_ratio(material("other", grade_out))
.map(self.format_ratio)
.value_or("-")
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_type_exchange(self) -> None:
expected = [
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
]
type_ = trade.MaterialType.raw
material = partial(trade.Material, "name")
actual = [
[
material(trade.MaterialType.raw, "category", grade_in)
.trade_ratio(material(trade.MaterialType.encoded, "other", grade_out))
2022-01-20 16:57:53 +00:00
.map(self.format_ratio)
.value_or("-")
2022-01-20 16:04:54 +00:00
for grade_out in [1, 2, 3, 4, 5]
]
for grade_in in [1, 2, 3, 4, 5]
]
self.assertEqual(expected, actual)