From 7b312aab1af3b2c67bc29df1faf46e39947b51fe Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Wed, 10 Apr 2024 17:27:43 +0300 Subject: tests for player --- tests/test_player.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_player.py (limited to 'tests') 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()) -- cgit v1.2.3