blob: bf3647a66f82d459cbcb827a33806073c8a3341e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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())
|