Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test_interpreter.py → tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,26 @@ def test_let_pair(self):
let_pair = LetPair('x', 'y', Pair(Int(1), String("hello")), Var('x'))
self.assertEqual(interpret(let_pair), Int(1))

def test_let_pair_error(self):
let_pair = LetPair('x', 'y', Int(1), Var('x'))
with self.assertRaises(InterpError):
interpret(let_pair)

def test_inl_inr(self):
self.assertEqual(interpret(Inl(Int(1), TString())), Inl(Int(1), TString()))
self.assertEqual(interpret(Inr(String("hello"), TInt())), Inr(String("hello"), TInt()))

def test_case(self):
case_exp = Case(Inl(Int(1), TString()), 'x', Var('x'), 'y', Int(2))
self.assertEqual(interpret(case_exp), Int(1))
case_exp_inl = Case(Inl(Int(1), TString()), 'x', Var('x'), 'y', Int(2))
self.assertEqual(interpret(case_exp_inl), Int(1))

case_exp_inr = Case(Inr(String("hello"), TInt()), 'x', Int(2), 'y', Var('y'))
self.assertEqual(interpret(case_exp_inr), String("hello"))

def test_case_error(self):
case_exp = Case(Int(1), 'x', Var('x'), 'y', Int(2))
with self.assertRaises(InterpError):
interpret(case_exp)

def test_promote(self):
self.assertEqual(interpret(Promote(Int(1))), Int(1))
Expand Down
47 changes: 47 additions & 0 deletions tests/test_planning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest
from planning import *

class TestPlanning(unittest.TestCase):
def test_create_action(self):
action = create_action("move", ["at A"], ["at B", "not at A"])
self.assertIsInstance(action, Action)
self.assertEqual(action.name, "move")
self.assertEqual(action.preconditions, ["at A"])
self.assertEqual(action.effects, ["at B", "not at A"])

def test_create_goal(self):
goal = create_goal("at B", ["at B"])
self.assertIsInstance(goal, Goal)
self.assertEqual(goal.name, "at B")
self.assertEqual(goal.conditions, ["at B"])

def test_create_state(self):
state = create_state(["at A", "at C"])
self.assertIsInstance(state, State)
self.assertEqual(state.facts, {"at A", "at C"})

def test_apply_action_success(self):
state = create_state(["at A", "at C"])
action = create_action("move", ["at A"], ["at B", "not at A"])
new_state = apply_action(state, action)
self.assertIsNotNone(new_state)
self.assertEqual(new_state.facts, {"at B", "at C"})

def test_apply_action_fail(self):
state = create_state(["at C"])
action = create_action("move", ["at A"], ["at B", "not at A"])
new_state = apply_action(state, action)
self.assertIsNone(new_state)

def test_is_goal_success(self):
state = create_state(["at B", "at C"])
goal = create_goal("at B", ["at B"])
self.assertTrue(is_goal(state, goal))

def test_is_goal_fail(self):
state = create_state(["at C"])
goal = create_goal("at B", ["at B"])
self.assertFalse(is_goal(state, goal))

if __name__ == '__main__':
unittest.main()