Fix tests expecting Maybe return types

Tests were not updated when the "returns" dependency was removed.
This commit is contained in:
Correl Roush 2022-01-22 01:29:36 -05:00
parent b78a87e88e
commit 4b9537c9b9
2 changed files with 32 additions and 29 deletions

View file

@ -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]

View file

@ -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]