2022-01-22 05:21:09 +00:00
|
|
|
import fractions
|
2022-01-22 06:29:36 +00:00
|
|
|
import typing
|
2022-01-22 05:21:09 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from elite_engineering import materials
|
|
|
|
|
|
|
|
|
|
|
|
class TradeCalculationTests(unittest.TestCase):
|
2022-01-22 06:29:36 +00:00
|
|
|
def format_ratio(self, ratio: typing.Optional[fractions.Fraction]) -> str:
|
|
|
|
if not ratio:
|
|
|
|
return "-"
|
2022-01-22 05:21:09 +00:00
|
|
|
return "{} → {}".format(ratio.numerator, ratio.denominator)
|
|
|
|
|
|
|
|
def test_same_category_exchange(self) -> None:
|
|
|
|
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"],
|
|
|
|
["-", "216 → 1", "36 → 1", "6 → 1", "1 → 1"],
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = [
|
|
|
|
[
|
2022-01-22 06:29:36 +00:00
|
|
|
self.format_ratio(
|
2022-01-22 05:21:09 +00:00
|
|
|
materials.Material(
|
2022-01-22 06:29:36 +00:00
|
|
|
"name", materials.MaterialType.raw, "category", grade_in
|
|
|
|
).trade_ratio(
|
|
|
|
materials.Material(
|
|
|
|
"name", materials.MaterialType.raw, "category", grade_out
|
|
|
|
)
|
2022-01-22 05:21:09 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
for grade_in in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
for grade_out in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_different_category_exchange(self) -> None:
|
|
|
|
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"],
|
|
|
|
["-", "216 → 1", "36 → 1", "6 → 1", "2 → 1"],
|
|
|
|
["-", "-", "216 → 1", "36 → 1", "6 → 1"],
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = [
|
|
|
|
[
|
2022-01-22 06:29:36 +00:00
|
|
|
self.format_ratio(
|
2022-01-22 05:21:09 +00:00
|
|
|
materials.Material(
|
2022-01-22 06:29:36 +00:00
|
|
|
"name", materials.MaterialType.raw, "category", grade_in
|
|
|
|
).trade_ratio(
|
|
|
|
materials.Material(
|
|
|
|
"name", materials.MaterialType.raw, "other", grade_out
|
|
|
|
)
|
2022-01-22 05:21:09 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
for grade_in in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
for grade_out in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
def test_different_type_exchange(self) -> None:
|
|
|
|
expected = [
|
|
|
|
["-", "-", "-", "-", "-"],
|
|
|
|
["-", "-", "-", "-", "-"],
|
|
|
|
["-", "-", "-", "-", "-"],
|
|
|
|
["-", "-", "-", "-", "-"],
|
|
|
|
["-", "-", "-", "-", "-"],
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = [
|
|
|
|
[
|
2022-01-22 06:29:36 +00:00
|
|
|
self.format_ratio(
|
2022-01-22 05:21:09 +00:00
|
|
|
materials.Material(
|
2022-01-22 06:29:36 +00:00
|
|
|
"name", materials.MaterialType.raw, "category", grade_in
|
|
|
|
).trade_ratio(
|
|
|
|
materials.Material(
|
|
|
|
"name", materials.MaterialType.encoded, "other", grade_out
|
|
|
|
)
|
2022-01-22 05:21:09 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
for grade_in in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
for grade_out in [1, 2, 3, 4, 5]
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(expected, actual)
|