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( Path(__file__).parent.parent.resolve() .joinpath('src').joinpath('sliceitoff').joinpath('assets')) 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())