diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-02-05 18:13:07 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-02-05 18:13:07 +0200 |
commit | 5a37bf84dd851cda76d93e353586f0d786c4c9c6 (patch) | |
tree | eafc5a76244b60a349e0dbcc4b3fcc0ce029b9d9 | |
parent | 662e5185976653a7ac6c86b7d8d30d032756019a (diff) |
Adding tests that bots certain hints for mines and safes are correct.
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | testdata/beginner_3win.txt (renamed from tests/data/beginner_3win.txt) | 0 | ||||
-rw-r--r-- | testdata/dssp_win.txt (renamed from tests/data/dssp_win.txt) | 0 | ||||
-rw-r--r-- | testdata/not_solved.txt | 11 | ||||
-rw-r--r-- | tests/test_bot.py | 54 |
5 files changed, 66 insertions, 1 deletions
@@ -30,4 +30,4 @@ Miinaharava ratkaisijalla `python3 miinaharava -c 10` ### Pelaa kentät tiedostosta -`python3 miinaharava -f miinaharava/tests/data/beginner_3win.txt` +`python3 miinaharava -f miinaharava/testdata/beginner_3win.txt` diff --git a/tests/data/beginner_3win.txt b/testdata/beginner_3win.txt index 6eeb1a4..6eeb1a4 100644 --- a/tests/data/beginner_3win.txt +++ b/testdata/beginner_3win.txt diff --git a/tests/data/dssp_win.txt b/testdata/dssp_win.txt index 4a19dee..4a19dee 100644 --- a/tests/data/dssp_win.txt +++ b/testdata/dssp_win.txt diff --git a/testdata/not_solved.txt b/testdata/not_solved.txt new file mode 100644 index 0000000..4a031c8 --- /dev/null +++ b/testdata/not_solved.txt @@ -0,0 +1,11 @@ +# Lautoja joissa dssp-ratkaisijalla tulee ongelmia + +.@....... +@..@..... +@.@...... +......... +......... +......... +......... +......... +......... diff --git a/tests/test_bot.py b/tests/test_bot.py new file mode 100644 index 0000000..4dab148 --- /dev/null +++ b/tests/test_bot.py @@ -0,0 +1,54 @@ +""" tests/test_bot.py - Testaa botin toimintaa""" +# pylint: disable = missing-class-docstring, too-few-public-methods, protected-access + +import unittest + +from board import Board, Tile +from bots import DSSPBot, SimpleBot +from tui import Action + +class TestBotClass(unittest.TestCase): + """ botin testit""" + def test_init(self): + """ olioden luominen onnistuu """ + DSSPBot() + SimpleBot() + + def correctly_marking(self, open_free=False, bot_type=DSSPBot): + """ Testaa onko miinat miinoja ja vapaat vapaita alkuun avatusta """ + for _ in range(500): + brd = Board() + # jos ei aukea ylälaidasta otetaan seuraava + if not brd.guess(0,0): + continue + # vain varmat liikut + bot = bot_type(uncertain=False) + + tested = set() + while True: + action, x, y = bot.hint(brd.get_view(), 0, 0) + if (x,y) in tested: + break + tested.add((x,y)) + if action == Action.SAFE: + self.assertTrue( brd._Board__tiles[x][y] < Tile.MINE ) + if open_free: + brd.guess(x,y) + if action == Action.MINE: + self.assertTrue( brd._Board__tiles[x][y] == Tile.MINE ) + + def test_dssp_marks_correctly_with_open(self): + """ Testaa onko dssp:n miinat miinoja ja avaa vapaat """ + self.correctly_marking(True, DSSPBot) + + def test_simple_marks_correctly_with_open(self): + """ Testaa onko dssp:n miinat miinoja ja avaa vapaat """ + self.correctly_marking(True, SimpleBot) + + def test_dssp_marks_correctly(self): + """ Testaa onko dssp:n miinat miinoja ja vapaat vapaita """ + self.correctly_marking(False, DSSPBot) + + def test_simple_marks_correctly(self): + """ Testaa onko simple:n miinat miinoja ja vapaat vapaita """ + self.correctly_marking(False, SimpleBot) |