summaryrefslogtreecommitdiff
path: root/tests/test_highscores.py
blob: 366d60f0cf7f4ca16d7df32a57cac3de2262952a (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
48
49
50
import os
from pathlib import Path
import unittest
import pygame

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()
    
    def tearDown(self):
        if self.filename.is_file():
            self.filename.unlink()
        
    def test_can_create(self):
        self.assertNotEqual(None, hi_scores)

    def test_config_save_can_run(self):
        hi_scores.save()

    def test_scores_can_be_added(self):
        hi_scores.add(500_000,"HUH")

    def test_scores_can_be_saved(self):
        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)