summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-27 02:20:46 +0300
committerViljami Ilola <+@hix.fi>2024-04-27 02:20:46 +0300
commitd73fe4bb20e544443476ebb4c9fc593fa0a8ad4a (patch)
tree9a0669819d4f18cf1a118f0755d78dd95959dc7c /tests
parentdb5967a52d9409842581276154a6fa9763a57a24 (diff)
fix tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_field.py2
-rw-r--r--tests/test_highscores.py45
-rw-r--r--tests/test_sfx.py24
3 files changed, 54 insertions, 17 deletions
diff --git a/tests/test_field.py b/tests/test_field.py
index ac56184..e84c3fd 100644
--- a/tests/test_field.py
+++ b/tests/test_field.py
@@ -10,7 +10,7 @@ from sliceitoff.display import Scaling
class TestFieldSprite(unittest.TestCase):
def test_can_create(self):
- fs = FieldSprite((0,0,320_000,220_000))
+ fs = FieldSprite((0,0,320_000,220_000), (0,0,0,0))
self.assertNotEqual(None, fs)
diff --git a/tests/test_highscores.py b/tests/test_highscores.py
index 048a42c..366d60f 100644
--- a/tests/test_highscores.py
+++ b/tests/test_highscores.py
@@ -1,37 +1,50 @@
+import os
from pathlib import Path
import unittest
import pygame
-from sliceitoff.hiscores import HiScores
+os.environ["TEST_CONFIG_FILE"] = "/tmp/sliceitoff-hiscores-test"
+
+from sliceitoff.settings import settings
+from sliceitoff.hiscores import hi_scores
+
class TestHiScores(unittest.TestCase):
def setUp(self):
self.filename = Path("/tmp/sliceitoff-hiscores-test")
if self.filename.is_file():
self.filename.unlink()
- self.hiscores = HiScores(filename = self.filename)
def tearDown(self):
- try:
- del self.hiscores
- except AttributeError:
- pass
if self.filename.is_file():
self.filename.unlink()
def test_can_create(self):
- self.assertNotEqual(None, self.hiscores)
+ self.assertNotEqual(None, hi_scores)
- def test_config_file_is_created_on_exit(self):
- del self.hiscores
- self.assertTrue(self.filename.is_file())
+ def test_config_save_can_run(self):
+ hi_scores.save()
def test_scores_can_be_added(self):
- self.hiscores.add(500_000,"HUH")
+ hi_scores.add(500_000,"HUH")
def test_scores_can_be_saved(self):
- self.hiscores.add(230_000,"HAH")
- old_scores = str(self.hiscores)
- del self.hiscores
- self.hiscores = HiScores(filename = self.filename)
- self.assertEqual(old_scores, str(self.hiscores))
+ hi_scores.add(230_000,"ZAP")
+ hi_scores.save()
+ settings.save()
+ with open(self.filename, "r", encoding="utf-8") as cfile:
+ for line in cfile:
+ if line == "hiscore=230000!ZAP\n":
+ break
+ else:
+ self.fail("Problem saving hiscores.")
+
+ def test_high_enough(self):
+ for _ in range(20):
+ hi_scores.add(100_000,"LOL")
+ self.assertFalse( hi_scores.high_enough(99_999) )
+ self.assertFalse( hi_scores.high_enough(100_000) )
+ self.assertTrue( hi_scores.high_enough(100_001) )
+
+ def test_str_can_run(self):
+ str(hi_scores)
diff --git a/tests/test_sfx.py b/tests/test_sfx.py
index 1aaf53e..35483a5 100644
--- a/tests/test_sfx.py
+++ b/tests/test_sfx.py
@@ -18,3 +18,27 @@ class TestSfx(unittest.TestCase):
def test_play(self):
sfx.play("laser")
+
+ def test_music(self):
+ sfx.music("baby")
+ sfx.music("baby")
+ sfx.music("glass")
+ sfx.music(None)
+
+ def test_sfx_volume_control(self):
+ old_vol = sfx.sfx_volume
+ sfx.sfx_up()
+ self.assertNotEqual(old_vol, sfx.sfx_volume)
+ for _ in range(10):
+ sfx.sfx_up()
+ self.assertEqual(old_vol, sfx.sfx_volume)
+
+ def test_music_volume_control(self):
+ old_vol = sfx.music_volume
+ sfx.music(None)
+ sfx.music_up()
+ sfx.music("glass")
+ self.assertNotEqual(old_vol, sfx.music_volume)
+ for _ in range(10):
+ sfx.music_up()
+ self.assertEqual(old_vol, sfx.music_volume)