diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-10 16:42:30 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-10 16:42:30 +0300 |
commit | a6aadcc36295ae8bf09b630f02171dd2843db2e4 (patch) | |
tree | e51d563079413b972fab7b396e8b6998b9f0c050 | |
parent | c981a7a650285de46d10876fbe5586008643877a (diff) |
tests for stats
-rw-r--r-- | pyproject.toml | 1 | ||||
-rw-r--r-- | tests/test_stats.py | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/pyproject.toml b/pyproject.toml index 7fed447..42ca912 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ build-backend = "poetry.core.masonry.api" [tool.coverage.run] branch = true source = ["src/sliceitoff/"] +omit = ["src/sliceitoff/game/*"] # Game logic and input-needing parts [tool.pylint.main] diff --git a/tests/test_stats.py b/tests/test_stats.py new file mode 100644 index 0000000..f3fc7c7 --- /dev/null +++ b/tests/test_stats.py @@ -0,0 +1,39 @@ +import os +import unittest +import pygame + +from pathlib import Path + +from sliceitoff.stats import Stats + +class TestStats(unittest.TestCase): + def setUp(self): + self.stats0 = Stats() + self.stats = Stats() + + def test_can_create(self): + self.assertNotEqual(None, self.stats) + + def test_lose_lives(self): + self.stats.lose_life() + self.assertEqual(self.stats.lives + 1, self.stats0.lives) + + def test_lose_lives_return_true_when_dead(self): + for _ in range(self.stats.lives-1): + self.assertFalse(self.stats.lose_life()) + self.assertTrue(self.stats.lose_life()) + + def test_levelup_levels_up(self): + self.stats.level_up() + self.assertEqual(self.stats.level + 1, self.stats0.lives) + + def test_add_score_works(self): + self.stats.score=500 + self.stats.add_score(400) + self.assertEqual(self.stats.score, 900) + self.stats.add_score(-600) + self.assertEqual(self.stats.score, 300) + self.stats.add_score(-300) + self.assertEqual(self.stats.score, 0) + self.stats.add_score(-300) + self.assertEqual(self.stats.score, 0) |