diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-10 17:27:43 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-10 17:27:43 +0300 |
commit | 7b312aab1af3b2c67bc29df1faf46e39947b51fe (patch) | |
tree | f751aea4b397a56d063950bb3ea7c4f6dd840f14 | |
parent | 43e1a7425e525a1da0c805db16a2c54b56fc1580 (diff) |
tests for player
-rw-r--r-- | tests/test_player.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_player.py b/tests/test_player.py new file mode 100644 index 0000000..56ed1cd --- /dev/null +++ b/tests/test_player.py @@ -0,0 +1,49 @@ +import os +from random import randrange + +from pathlib import Path + +import unittest +import pygame + +from sliceitoff.player import Player, Life +from sliceitoff.text import Fonts +from sliceitoff.display import Scaling + +class TestPlayer(unittest.TestCase): + def setUp(self): + self.player = Player() + + def test_can_create(self): + self.assertNotEqual(None, self.player) + + def test_update_is_not_crashing(self): + for _ in range(10000): + self.player.update( + pos= (randrange(-100,3000),randrange(-100,3000)), + direction = (randrange(0,2) == 0)) + + def test_direction_change_gives_different_sprites(self): + sprts = self.player.sprites() + self.player.direction = not self.player.direction + self.assertNotEqual(sprts, self.player.sprites()) + +class TestLife(unittest.TestCase): + def setUp(self): + Scaling.update_scaling((640,480)) + Fonts.load_fonts(os.path.join( + Path(__file__).parent.parent.resolve(), + "src", + "sliceitoff")) + self.life = Life() + + def test_can_create(self): + self.assertNotEqual(None, self.life) + + def test_empty_to_empty_group_with_update(self): + self.assertFalse(self.life.sprites()) + self.life.lose_life() + self.assertTrue(self.life.sprites()) + for _ in range(1000): + self.life.update(dt=100) + self.assertFalse(self.life.sprites()) |