Example #1
0
 def test_clear(self):
     """Verifies that clear works as expected"""
     h = Assoc(_u.new_assoc(), freeit=True)
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     h[a] = a
     h.clear()
     self.assertFalse(a in h)
Example #2
0
 def test_copy(self):
     """Tests the copy behavior"""
     h = Assoc(_u.new_assoc(), freeit=True)
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     h[a] = a
     h2 = h.copy()
     self.assertTrue(a in h2)
Example #3
0
 def test_copy(self):
     """Tests the copy behavior"""
     h = Assoc(_u.new_assoc(), freeit=True)
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     h[a] = a
     h2= h.copy()
     self.assertTrue(a in h2)
Example #4
0
 def test_clear(self):
     """Verifies that clear works as expected"""
     h = Assoc(_u.new_assoc(), freeit=True)
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     h[a] = a
     h.clear()
     self.assertFalse(a in h) 
Example #5
0
    def test_empty(self):
        """Tests the empty factory"""
        a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
        h = Assoc.empty(freeit=True)
        self.assertFalse(a in h)

        hh = Assoc.empty(initial_capa=1, freeit=True)
        hh[a] = a
        self.assertTrue(a in hh)
Example #6
0
    def test_associative_array(self):
        """
        This function tests the basic functions of the associative array proto
        """
        h = Assoc(_u.new_assoc(), freeit=True)
        a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
        b = Node.from_ptr(parse_simple_expression("b.car = 3"), freeit=False)

        # __contains__
        self.assertFalse(a in h)
        # __setitem__
        h[a] = a
        self.assertTrue(a in h)
        # __getitem__
        self.assertEqual(h[a], a)
        with self.assertRaises(KeyError):
            h[b]
        # __delitem__
        del h[a]
        self.assertFalse(a in h)
Example #7
0
 def test_from_dict(self):
     """Tests the from_dict factory"""
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     d = {a: a}
     h = Assoc.from_dict(d)
     self.assertTrue(a in h)
Example #8
0
 def test_empty(self):
     """Tests the empty factory"""
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     h = Assoc.empty(freeit=True)
     self.assertFalse(a in h)
     
Example #9
0
 def test_from_dict(self):
     """Tests the from_dict factory"""
     a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False)
     d = {a: a}
     h = Assoc.from_dict(d)
     self.assertTrue(a in h)