nilshoehing commited on
Commit
38c2566
·
verified ·
1 Parent(s): 96e3e70

Fix puzzle UI and verifier normalization

Browse files
Files changed (2) hide show
  1. tests/test_core.py +50 -0
  2. tests/test_verification.py +26 -0
tests/test_core.py CHANGED
@@ -7,6 +7,7 @@ from pathlib import Path
7
  from space_app.dataset import DatasetStore
8
  from space_app.db import SessionStore
9
  from space_app.models import DatasetRow, normalize_player_name
 
10
 
11
 
12
  class CoreTests(unittest.TestCase):
@@ -63,3 +64,52 @@ class CoreTests(unittest.TestCase):
63
  self.assertEqual(updated["status"], "attempted")
64
  self.assertEqual(updated["submission_count"], 1)
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  from space_app.dataset import DatasetStore
8
  from space_app.db import SessionStore
9
  from space_app.models import DatasetRow, normalize_player_name
10
+ from space_app.board_utils import normalize_board_for_display, normalize_board_for_submission
11
 
12
 
13
  class CoreTests(unittest.TestCase):
 
64
  self.assertEqual(updated["status"], "attempted")
65
  self.assertEqual(updated["submission_count"], 1)
66
 
67
+ def test_loopy_normalization_marks_unclicked_edges_blocked(self) -> None:
68
+ problem = "\n".join(
69
+ [
70
+ "+++++++",
71
+ "+ +",
72
+ "+ 1 +",
73
+ "+ +",
74
+ "+ 2 +",
75
+ "+ +",
76
+ "+++++++",
77
+ ]
78
+ )
79
+ partial = "\n".join(
80
+ [
81
+ "+++++++",
82
+ "+ - +",
83
+ "+ 1 +",
84
+ "+ +",
85
+ "+ 2 +",
86
+ "+ +",
87
+ "+++++++",
88
+ ]
89
+ )
90
+ normalized = normalize_board_for_submission(
91
+ puzzle_type="loopy",
92
+ problem_ascii=problem,
93
+ board_ascii=partial,
94
+ )
95
+ self.assertIn("x", normalized)
96
+ self.assertIn("-", normalized)
97
+
98
+ def test_pattern_normalization_makes_unclicked_cells_white(self) -> None:
99
+ board = "\n".join(
100
+ [
101
+ " 1 ",
102
+ " +--+--+",
103
+ " 1| |##|",
104
+ " +--+--+",
105
+ " 1|##| |",
106
+ " +--+--+",
107
+ ]
108
+ )
109
+ normalized = normalize_board_for_display(
110
+ puzzle_type="pattern",
111
+ problem_ascii=board,
112
+ board_ascii=board,
113
+ )
114
+ self.assertIn("|..|##|", normalized)
115
+ self.assertIn("|##|..|", normalized)
tests/test_verification.py CHANGED
@@ -1,6 +1,8 @@
1
  from __future__ import annotations
2
 
 
3
  import unittest
 
4
 
5
  from space_app.verification import VerificationService
6
 
@@ -21,3 +23,27 @@ class VerificationTests(unittest.TestCase):
21
  self.skipTest(f"Native verifier unavailable locally: {caught}")
22
  return
23
  self.assertTrue(result["correct"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
 
3
+ import subprocess
4
  import unittest
5
+ from unittest.mock import patch
6
 
7
  from space_app.verification import VerificationService
8
 
 
23
  self.skipTest(f"Native verifier unavailable locally: {caught}")
24
  return
25
  self.assertTrue(result["correct"])
26
+
27
+ def test_undead_verification_timeout_returns_clean_error(self) -> None:
28
+ verifier = VerificationService()
29
+ board = "\n".join(
30
+ [
31
+ "G: 1 V: 1 Z: 1",
32
+ "",
33
+ " 1 1 1 1 ",
34
+ " 1 . . . . 1",
35
+ " 1 . . . . 1",
36
+ " 1 . . . . 1",
37
+ " 1 . . . . 1",
38
+ " 1 1 1 1 ",
39
+ ]
40
+ )
41
+ with patch("space_app.verification.subprocess.run", side_effect=subprocess.TimeoutExpired("cmd", 15)):
42
+ result = verifier.verify(
43
+ puzzle_type="undead",
44
+ problem_ascii=board,
45
+ board_ascii=board,
46
+ args="4x4de",
47
+ )
48
+ self.assertFalse(result["correct"])
49
+ self.assertEqual(result.get("error"), "Undead verification timed out.")