-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle_test.py
118 lines (93 loc) · 4.32 KB
/
puzzle_test.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from puzzle import *
# <A knowledge0----------------------------------------------------------------->
# XOR = exclusive or
# Only a Knight or a Knave, not both or neither
# InitialKnowledge0 = And(
# Or(AKnight, AKnave), # must be one of these
# Not(And(AKnight, AKnave)), # but not both
# )
def test_a_initial_knowledge():
# Cant have both a Knight and a Knave
model1 = {'A is a Knight': True, 'A is a Knave': True}
assert InitialKnowledge0.evaluate(model1) == False
# Must have at least a knight or a knave
model2 = {'A is a Knight': False, 'A is a Knave': False}
assert InitialKnowledge0.evaluate(model2) == False
# Only a Knight and not a Knave
model3 = {'A is a Knight': True, 'A is a Knave': False}
assert InitialKnowledge0.evaluate(model3) == True
# Only a Knave and not a Knight
model4 = {'A is a Knight': False, 'A is a Knave': True}
assert InitialKnowledge0.evaluate(model4) == True
# InitialStatement = And(AKnight, AKnave)
def test_a_initial_statement():
# And(True, True)
model1 = {'A is a Knight': True, 'A is a Knave': True}
assert InitialStatment0.evaluate(model1) == True
# And(False, False)
model2 = {'A is a Knight': False, 'A is a Knave': False}
assert InitialStatment0.evaluate(model2) == False
# And(True, False)
model3 = {'A is a Knight': True, 'A is a Knave': False}
assert InitialStatment0.evaluate(model3) == False
# And(False, True)
model4 = {'A is a Knight': False, 'A is a Knave': True}
assert InitialStatment0.evaluate(model4) == False
# KnightTruth0 = Implication(AKnight, InitialStatment0)
# InitialStatment0 = And(AKnight, AKnave)
# Goal: implication(True, True)
def test_a_knight_truth():
# implication(True, (True && True)) =>
# implication(True, True)
model1 = {'A is a Knight': True, 'A is a Knave': True}
assert KnightTruth0.evaluate(model1) == True
# A knight is false, so implication doesnt apply
model2 = {'A is a Knight': False, 'A is a Knave': False}
assert KnightTruth0.evaluate(model2) == True
# A knight is false, so implication doesnt apply
model4 = {'A is a Knight': False, 'A is a Knave': True}
assert KnightTruth0.evaluate(model4) == True
# implication(True, (True && False))
# implication(True, False)
model3 = {'A is a Knight': True, 'A is a Knave': False}
assert KnightTruth0.evaluate(model3) == False
# KnaveLie0 = Implication(AKnave, Not(InitialStatment0))
# InitialStatment0 = And(AKnight, AKnave)
# Goal: implication(True, True)
def test_a_knight_truth():
# implication(True, !(False && True))
# implication(True, True)
model4 = {'A is a Knight': False, 'A is a Knave': True}
assert KnaveLie0.evaluate(model4) == True
# A Knave is false, so implication doesnt apply
model2 = {'A is a Knight': False, 'A is a Knave': False}
assert KnaveLie0.evaluate(model2) == True
# A Knave is false, so implication doesnt apply
model3 = {'A is a Knight': True, 'A is a Knave': False}
assert KnaveLie0.evaluate(model3) == True
# implication(True, !(True && True))
# implication(True, False)
model1 = {'A is a Knight': True, 'A is a Knave': True}
assert KnaveLie0.evaluate(model1) == False
def test_knowledge_0():
# should fail because not only a knave
model1 = {'A is a Knight': True, 'A is a Knave': True}
assert knowledge0.evaluate(model1) == False
model2 = {'A is a Knight': False, 'A is a Knave': False}
assert knowledge0.evaluate(model2) == False
model3 = {'A is a Knight': True, 'A is a Knave': False}
assert knowledge0.evaluate(model3) == False
# should be the only one to pass as its only a knave
model4 = {'A is a Knight': False, 'A is a Knave': True}
assert knowledge0.evaluate(model4) == True
# def test_knowledge_1():
# # should fail because not only a knave
# model1 = {' is a Knight': True, ' is a Knave': True}
# assert knowledge1.evaluate(model1) == False
# model2 = {' is a Knight': False, ' is a Knave': False}
# assert knowledge1.evaluate(model2) == False
# model3 = {' is a Knight': True, ' is a Knave': False}
# assert knowledge0.evaluate(model3) == False
# # should be the only one to pass as its only a knave
# model4 = {'A is a Knight': False, 'A is a Knave': True}
# assert knowledge1.evaluate(model4) == True