summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-10 15:42:23 +0300
committerViljami Ilola <+@hix.fi>2024-04-10 15:42:23 +0300
commitc981a7a650285de46d10876fbe5586008643877a (patch)
tree6959ac82dbada6f3755bf9e485f4bba96c0b0c51
parent048f51c63c54ccc4ed95d82d9294819ab928cfff (diff)
tests for field
-rw-r--r--tests/test_field.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/test_field.py b/tests/test_field.py
new file mode 100644
index 0000000..ac56184
--- /dev/null
+++ b/tests/test_field.py
@@ -0,0 +1,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))
+ 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)