From acfb0ab8f54b7a5ea10203d2cfa1834772781855 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Thu, 20 Jan 2022 11:04:54 -0500 Subject: [PATCH] Add tests --- trade.py => elite_engineering/trade.py | 0 pyproject.toml | 17 ++++++++ tests/test_trade.py | 55 ++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) rename trade.py => elite_engineering/trade.py (100%) create mode 100644 pyproject.toml create mode 100644 tests/test_trade.py diff --git a/trade.py b/elite_engineering/trade.py similarity index 100% rename from trade.py rename to elite_engineering/trade.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..36909da --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "elite-engineering" +version = "0.1.0" +description = "Tools for engineering in Elite Dangerous" +authors = ["Correl Roush "] +license = "MIT" + +[tool.poetry.dependencies] +python = "^3.9" + +[tool.poetry.dev-dependencies] +black = "^21.12b0" +pytest = "^6.2.5" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" diff --git a/tests/test_trade.py b/tests/test_trade.py new file mode 100644 index 0000000..115dbb0 --- /dev/null +++ b/tests/test_trade.py @@ -0,0 +1,55 @@ +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)