Skip to content

Commit

Permalink
add depth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vncntt committed Mar 2, 2025
1 parent 8911aa7 commit c03832e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_knights_knaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_items():
assert "question" in item
assert "answer" in item
assert "metadata" in item
assert "solution" in item["metadata"]


def test_solution():
Expand Down Expand Up @@ -185,3 +186,52 @@ def test_satisfiability():
assert not KnightsKnavesDataset.test_satisfiability(
("<=>", ("telling-truth", 0), ("telling-truth", 1)), (True, False)
)


def test_depth_constraint():
config = KnightsKnavesConfig(
n_people=2,
depth_constraint=4,
width_constraint=2,
size=5,
seed=42,
)
dataset = KnightsKnavesDataset(config)
assert len(dataset) == 5
for i in range(len(dataset)):
# make sure there's a unique solution
assert len(dataset[i]["metadata"]["solution"]) == len(dataset[i]["metadata"]["names"])


def test_depth_constraint_specific_problem():
test_statements = (
(
"or",
("not", ("and", ("telling-truth", 0), ("telling-truth", 1), ("lying", 1))),
(
"and",
("not", ("telling-truth", 0)),
("->", ("telling-truth", 0), ("lying", 1)),
("<=>", ("telling-truth", 1), ("lying", 2)),
),
(
"and",
("or", ("lying", 2), ("lying", 1), ("telling-truth", 0)),
("or", ("telling-truth", 0), ("lying", 2)),
("or", ("telling-truth", 2), ("telling-truth", 0)),
),
),
(
"not",
(
"or",
("and", ("telling-truth", 1), ("telling-truth", 2), ("telling-truth", 0)),
("or", ("telling-truth", 2), ("telling-truth", 1), ("telling-truth", 0)),
),
),
("not", ("telling-truth", 0)),
)

solutions = KnightsKnavesDataset.find_solution(test_statements)
assert len(solutions) == 1, "Should have exactly one solution"
assert solutions[0] == (True, False, False)

0 comments on commit c03832e

Please sign in to comment.