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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import os
import unittest
import pygame
from pathlib import Path
from sliceitoff.field import Field
from sliceitoff.field.field import FieldSprite, SliceSprite
from sliceitoff.display import Scaling
class TestFieldSprite(unittest.TestCase):
def test_can_create(self):
fs = FieldSprite((0,0,320_000,220_000), (0,0,0,0))
self.assertNotEqual(None, fs)
class TestSliceSprite(unittest.TestCase):
def test_can_create(self):
ss = SliceSprite((0,0,20_000,20_000))
self.assertNotEqual(None, ss)
def test_updating_and_selfkill_works(self):
ss = SliceSprite((0,0,320_000,220_000))
g = pygame.sprite.Group()
g.add(ss)
self.assertNotEqual(None, ss)
for _ in range(100):
ss.update(dt=100)
self.assertFalse(ss.alive())
class TestField(unittest.TestCase):
def setUp(self):
class MockStats:
def __init__(self):
self.field_count = 0
self.percent = 0
self.stats = MockStats()
def test_can_create(self):
field = Field()
self.assertNotEqual(None, field)
def test_calculate_current_area(self):
field = Field(stats = self.stats)
field.update_stats()
self.assertAlmostEqual(100, self.stats.percent, delta = 0.1)
def test_slicing_do_nothing_out_of_area(self):
field = Field(stats = self.stats)
self.assertEqual(None, field.slice((-10,-10), True, 0))
def test_slicing_does_something_on_the_area(self):
field = Field(stats = self.stats)
self.assertNotEqual(None, field.slice((10,10), True, 5))
def test_slicing_makes_areas(self):
field = Field(stats = self.stats)
field.slice((100_000,100_000), False, 8_000)
self.assertNotEqual(2, field.active_rects())
def test_killing_empty_areas_works(self):
field = Field(stats = self.stats)
field.kill_if_not_colliding([])
self.assertNotEqual(0, field.active_rects())
def test_killing_empty_areas_not_killing_areas_in_use(self):
field = Field(stats = self.stats)
ss = SliceSprite((20_000,20_000,20_000,20_000))
field.kill_if_not_colliding([ss])
self.assertNotEqual(1, field.active_rects())
def test_update_not_crashing_after_slicing(self):
field = Field(stats = self.stats)
field.slice((100_000,100_000), False, 16_000)
for _ in range(1000):
field.update(dt=10)
|