Beispiel #1
0
 def test_monoid_identity(self, a, b):
     hash = HashMap()
     hash_a = HashMap()
     from_list(hash_a, a)
     a_b = mconcat(mempty(hash), hash_a)  # {}
     b_a = mconcat(hash_a, mempty(hash))  # {}
     self.assertEqual(a_b, hash_a)
     self.assertEqual(a_b, b_a)
Beispiel #2
0
    def test_iter(self):
        x = [1, 2, 3]
        hash = HashMap()
        from_list(hash, x)
        tmp = []
        try:
            get_next = iterator(hash)
            while True:
                tmp.append(get_next())
        except StopIteration:
            pass
        self.assertEqual(x, tmp)
        self.assertEqual(to_list(hash), tmp)

        get_next = iterator(None)
        self.assertEqual(get_next(), False)
Beispiel #3
0
    def test_immutable(self, a, b, key, value):
        table = from_list(HashMap(), a)
        table_temp = table
        table1 = put(table, key, value)
        self.assertNotEqual(id(table), id(table1))
        self.assertEqual(to_dict(table), to_dict(table_temp))

        table3 = del_(table, key)
        table_temp = table1
        self.assertNotEqual(id(table1), id(table3))
        self.assertEqual(to_dict(table_temp), to_dict(table1))

        table4 = from_list(HashMap(), b)
        table3_temp = table3
        table4_temp = table4
        table5 = mconcat(table3, table4)
        table6 = mconcat(table4, table3)
        self.assertEqual(id(table5), id(table6))
        self.assertEqual(to_dict(table3_temp), to_dict(table3))
        self.assertEqual(to_dict(table4_temp), to_dict(table4))
Beispiel #4
0
 def test_monoid_associativity(self, a, b, c):
     hash_a = HashMap()
     hash_b = HashMap()
     hash_c = HashMap()
     from_list(hash_a, a)
     from_list(hash_b, b)
     from_list(hash_c, c)
     a_b = mconcat(hash_a, hash_b)
     b_c = mconcat(hash_b, hash_c)
     a_b__c = mconcat(a_b, hash_c)
     a__b_c = mconcat(hash_a, b_c)
     self.assertEqual(a_b__c, a__b_c)
Beispiel #5
0
 def test_from_list(self):
     lis = [1, 2]
     self.assertEqual(to_list(from_list([])), [])
     self.assertEqual(to_list(from_list(lis)), lis)
Beispiel #6
0
 def test_to_list(self, lst):
     hash = HashMap()
     from_list(hash, lst)
     self.assertEqual(to_list(hash), lst)
Beispiel #7
0
 def test_from_list(self, a):
     hash = HashMap()
     from_list(hash, a)
     self.assertEqual(to_list(hash), a)
Beispiel #8
0
 def test_monoid_identity(self, lst):
     hash = HashMap()
     a = from_list(hash, lst)
     self.assertEqual(mconcat(None, a), a)
     self.assertEqual(mconcat(a, None), a)
Beispiel #9
0
 def test_python_len_and_list_size_equality(self, lst):
     hash = HashMap()
     from_list(hash, lst)
     self.assertEqual(getSize(hash), len(lst))
Beispiel #10
0
 def test_from_list_to_list_equality(self, a):
     hash = HashMap()
     from_list(hash, a)
     b = to_list(hash)
     self.assertEqual(a, b)