예제 #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) 
예제 #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)
예제 #3
0
 def empty(key_conversion=NodeConversion(), value_conversion=NodeConversion(), initial_capa=0, freeit=False):
     """
     Creates an empty assoc
     
     :param key_conversion: the conversion for the key (object <--> pointer)
     :param value_conversion: the conversion of the value  (object <--> pointer)
     :param initial capa: the initial capacity of the associative array
     :param freeit: a flag indicating whether or not this object should be freed
                 upon garbage collection
     :return: a new empty Assoc
     """
     if initial_capa == 0:
         return Assoc(_utils.new_assoc(), key_conversion, value_conversion, freeit=freeit)
     else:
         return Assoc(_utils.new_assoc_with_size(initial_capa), key_conversion, value_conversion, freeit=freeit)
예제 #4
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)
     
     # __contains__
     self.assertFalse(a in h)
     # __setitem__
     h[a] = a
     self.assertTrue(a in h)
     # __getitem__
     self.assertEqual(h[a], a)
     # __delitem__
     del h[a]
     self.assertFalse(a in h)