From c75093304fb09dcdee61ea36169074828b1e210d Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Fri, 29 Mar 2024 14:29:45 +0200 Subject: scaling and display tests --- tests/test_display.py | 23 +++++++++++++++++++++++ tests/test_enemies.py | 7 ++++++- tests/test_scaling.py | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/test_display.py create mode 100644 tests/test_scaling.py diff --git a/tests/test_display.py b/tests/test_display.py new file mode 100644 index 0000000..5e01038 --- /dev/null +++ b/tests/test_display.py @@ -0,0 +1,23 @@ +import unittest + +import pygame + +from display import Display + +class TestDisplay(unittest.TestCase): + def test_can_create(self): + d = Display() + self.assertNotEqual(d, None) + + def test_can_update(self): + d = Display() + surf = pygame.Surface((300,300)) + sprite = pygame.sprite.Sprite() + sprite.image = surf + sprite.rect = pygame.Rect((0,0),(300,300)) + group = pygame.sprite.Group() + group.add(sprite) + d.update([group]) + + + \ No newline at end of file diff --git a/tests/test_enemies.py b/tests/test_enemies.py index aaf2b0c..315de88 100644 --- a/tests/test_enemies.py +++ b/tests/test_enemies.py @@ -25,4 +25,9 @@ class TestEnemies(unittest.TestCase): def test_right_amount_of_enemies(self): enemies = Enemies(count = 6) - self.assertEqual(6, len(enemies.sprites())) \ No newline at end of file + self.assertEqual(6, len(enemies.sprites())) + + def test_update_notcrashing(self): + enemies = Enemies(count = 6) + for _ in range(10000): + enemies.update(dt=100) diff --git a/tests/test_scaling.py b/tests/test_scaling.py new file mode 100644 index 0000000..170dbab --- /dev/null +++ b/tests/test_scaling.py @@ -0,0 +1,24 @@ +import unittest + +from display import Scaling, INTERNAL_HEIGHT, INTERNAL_WIDTH + +class TestScaling(unittest.TestCase): + def test_update_scaling(self): + Scaling.update_scaling((100,400)) + self.assertEqual((100,400), Scaling.resolution) + self.assertEqual((100//2,400//2), Scaling.center) + self.assertEqual((100/INTERNAL_WIDTH), Scaling.factor) + self.assertEqual(0, Scaling.left) + Scaling.update_scaling((400,100)) + self.assertEqual((100/INTERNAL_HEIGHT), Scaling.factor) + self.assertEqual(0, Scaling.top) + + def test_scale_functions(self): + Scaling.update_scaling((1000,1000)) + s = Scaling.scale_to_display(Scaling.scale_to_internal((400,500))) + self.assertAlmostEqual(400, s[0], delta = 0.1) + self.assertAlmostEqual(500, s[1], delta = 0.1) + + + + \ No newline at end of file -- cgit v1.2.3