Ejemplo n.º 1
0
 def test_state_hash(self):
     from models import NodeState
     name = 'A'
     n = NodeState(name)
     # print(n)
     # print(hash(n))
     self.assertEqual(n.id, hash(n))
Ejemplo n.º 2
0
    def test_dfs_nodeState_1_success(self):
        from search_algorithms import dfs_recursive as dfs_r
        from models import NodeState
        S = NodeState("start")
        A = NodeState("a")
        B = NodeState("b")
        C = NodeState("c")
        D = NodeState("d")
        G = NodeState("goal")

        states = {
            S: [A, B, D],
            A: [S, C],
            B: [S, D],
            C: [D, A, G],
            D: [S, A, C, G, B],
            G: [A, G],
        }

        start_state = S  # Initial state
        goal_state = G

        res = dfs_r(states=states, start=start_state, goal=goal_state)
        print([str(r) for r in res])
        # print(res)
        # print([S, A, C, G])
        # print([str(r) for r in [S, A, C, G]])
        self.assertListEqual(res, [S, A, C, D, G])
Ejemplo n.º 3
0
    def test_dfs_nodeState_1_failure(self):
        from search_algorithms import dfs_recursive
        from models import NodeState
        S = NodeState("start")
        A = NodeState("a")
        B = NodeState("b")
        C = NodeState("c")
        D = NodeState("d")
        G = NodeState("goal")
        states = {
            S.name: [A, B, D],
            A.name: [S, C],
            B.name: [S, D],
            C.name: [D, A, G],
            D.name: [B, S, A, C, G],
            G.name: [A, G],
        }
        start_state = S  # Initial state
        goal_state = G

        # res = dfs_recursive(states=states, start=start_state, goal=goal_state)
        self.assertRaises(Exception, dfs_recursive, states, start_state,
                          goal_state)
Ejemplo n.º 4
0
 def test_node_eq_failure(self):
     from models import NodeState
     self.assertFalse(NodeState("s") == NodeState('S1'))
     self.assertNotEqual(NodeState("s"), NodeState('S1'))
Ejemplo n.º 5
0
 def test_node_eq_success(self):
     from models import NodeState
     self.assertEqual(NodeState("s"), NodeState('S'))
Ejemplo n.º 6
0
 def test_create_node_failure(self):
     from models import NodeState
     name = 's'
     n = NodeState(name)
     print(n)
     self.assertNotEqual(n.name, name)
Ejemplo n.º 7
0
 def test_create3_node_success(self):
     from models import NodeState
     name = 1
     n = NodeState(name)
     print(n)
     self.assertEqual(n.name, '1')
Ejemplo n.º 8
0
 def test_create2_node_success(self):
     from models import NodeState
     name = 's'
     n = NodeState(name)
     print(n)
     self.assertEqual(n.name, name.upper())