コード例 #1
0
 def testUpdateState(self):
     matches = {}
     u = Vertex('u1')
     v = Vertex('v1')
     g = Graph()
     g._updateState(u, v, matches)
     self.assertEquals(len(g._matchHistory), 1)
     self.assertEquals(len(matches), 1)
     self.assertEquals(matches[u.id], 'v1')
コード例 #2
0
    def testRestoreState(self):
        # Save state with a couple calls to updateState() and then see that
        # they are undone.
        g = Graph()
        matches = {}
        u1 = Vertex('u1')
        v1 = Vertex('v1')
        g._updateState(u1, v1, matches)  # u1 matched with v1
        u2 = Vertex('u2')
        v2 = Vertex('v2')
        g._updateState(u2, v2, matches)  # u2 matched with v2

        # Now we should get the dictionary with only the original set of
        # matches.
        matches = g._restoreState(matches)
        self.assertEquals(len(matches), 1)
        self.assertTrue('u1' in matches)
        self.assertTrue(matches['u1'], 'v1')

        # Now we should have an empty dictionary.
        matches = g._restoreState(matches)
        self.assertEquals(len(matches), 0)