diff --git a/tests/test_materials.py b/tests/test_materials.py index 858d540..af728f6 100644 --- a/tests/test_materials.py +++ b/tests/test_materials.py @@ -1,11 +1,14 @@ import fractions +import typing import unittest from elite_engineering import materials class TradeCalculationTests(unittest.TestCase): - def format_ratio(self, ratio: fractions.Fraction) -> str: + def format_ratio(self, ratio: typing.Optional[fractions.Fraction]) -> str: + if not ratio: + return "-" return "{} → {}".format(ratio.numerator, ratio.denominator) def test_same_category_exchange(self) -> None: @@ -19,16 +22,15 @@ class TradeCalculationTests(unittest.TestCase): actual = [ [ - materials.Material( - "name", materials.MaterialType.raw, "category", grade_in - ) - .trade_ratio( + self.format_ratio( materials.Material( - "name", materials.MaterialType.raw, "category", grade_out + "name", materials.MaterialType.raw, "category", grade_in + ).trade_ratio( + materials.Material( + "name", materials.MaterialType.raw, "category", grade_out + ) ) ) - .map(self.format_ratio) - .value_or("-") for grade_in in [1, 2, 3, 4, 5] ] for grade_out in [1, 2, 3, 4, 5] @@ -47,16 +49,15 @@ class TradeCalculationTests(unittest.TestCase): actual = [ [ - materials.Material( - "name", materials.MaterialType.raw, "category", grade_in - ) - .trade_ratio( + self.format_ratio( materials.Material( - "name", materials.MaterialType.raw, "other", grade_out + "name", materials.MaterialType.raw, "category", grade_in + ).trade_ratio( + materials.Material( + "name", materials.MaterialType.raw, "other", grade_out + ) ) ) - .map(self.format_ratio) - .value_or("-") for grade_in in [1, 2, 3, 4, 5] ] for grade_out in [1, 2, 3, 4, 5] @@ -75,16 +76,15 @@ class TradeCalculationTests(unittest.TestCase): actual = [ [ - materials.Material( - "name", materials.MaterialType.raw, "category", grade_in - ) - .trade_ratio( + self.format_ratio( materials.Material( - "name", materials.MaterialType.encoded, "other", grade_out + "name", materials.MaterialType.raw, "category", grade_in + ).trade_ratio( + materials.Material( + "name", materials.MaterialType.encoded, "other", grade_out + ) ) ) - .map(self.format_ratio) - .value_or("-") for grade_in in [1, 2, 3, 4, 5] ] for grade_out in [1, 2, 3, 4, 5] diff --git a/tests/test_trade.py b/tests/test_trade.py index 6851789..c44ae39 100644 --- a/tests/test_trade.py +++ b/tests/test_trade.py @@ -1,11 +1,14 @@ import fractions +import typing import unittest from elite_engineering import trade class TradeCalculationTests(unittest.TestCase): - def format_ratio(self, ratio: fractions.Fraction) -> str: + def format_ratio(self, ratio: typing.Optional[fractions.Fraction]) -> str: + if not ratio: + return "-" return "{} → {}".format(ratio.numerator, ratio.denominator) def test_same_category_exchange(self) -> None: @@ -19,9 +22,9 @@ class TradeCalculationTests(unittest.TestCase): actual = [ [ - trade.ratio(grade_in, grade_out, across_categories=False) - .map(self.format_ratio) - .value_or("-") + self.format_ratio( + trade.ratio(grade_in, grade_out, across_categories=False) + ) for grade_in in [1, 2, 3, 4, 5] ] for grade_out in [1, 2, 3, 4, 5] @@ -40,9 +43,9 @@ class TradeCalculationTests(unittest.TestCase): actual = [ [ - trade.ratio(grade_in, grade_out, across_categories=True) - .map(self.format_ratio) - .value_or("-") + self.format_ratio( + trade.ratio(grade_in, grade_out, across_categories=True) + ) for grade_in in [1, 2, 3, 4, 5] ] for grade_out in [1, 2, 3, 4, 5]