示例#1
0
 def test_monoid_add(self, list_1, list_2, list_3):
     set_1 = from_list(list_1)
     set_2 = from_list(list_2)
     set_3 = from_list(list_3)
     self.assertEqual(
         monoid_add(monoid_add(set_1, set_2), set_3).data,
         monoid_add(set_1, monoid_add(set_2, set_3)).data,
     )
示例#2
0
 def test_from_list_equals_to_list(self, alist):
     new_list = []
     for i in alist:
         if not i in new_list:
             new_list.append(i)
     note(f"Shuffle:{alist!r}")
     self.set = from_list(alist)
     self.assertEqual(to_list(self.set), new_list)
示例#3
0
    def test_map(self):
        alist = [0, 1, 2, 3, 4, 11]
        self.set = from_list(alist)

        def mapPlusOne(value):
            return value + 1

        res = set_map(self.set, mapPlusOne)
        self.assertEqual(res, [1, 2, 3, 4, 5, 12])
示例#4
0
    def test_reduce(self):
        alist = [0, 1, 2, 3, 4, 11]
        self.set = from_list(alist)

        def reduceSum(accumulator, curr):
            return accumulator + curr

        res = set_reduce(self.set, reduceSum, 0)
        self.assertEqual(res, 21)
示例#5
0
 def test_from_list(self):
     alist = [0, 1, 2, 3, 4, 11]
     self.set = from_list(alist)
     self.assertEqual(has(self.set, 0), True)
     self.assertEqual(has(self.set, 1), True)
     self.assertEqual(has(self.set, 2), True)
     self.assertEqual(has(self.set, 3), True)
     self.assertEqual(has(self.set, 4), True)
     self.assertEqual(has(self.set, 5), False)
     self.assertEqual(has(self.set, 11), True)
示例#6
0
 def test_iter(self, alist):
     new_list = []
     for i in alist:
         if not i in new_list:
             new_list.append(i)
     self.set = from_list(alist)
     equal_new_list = []
     for i in self.set:
         equal_new_list.append(i)
     self.assertEqual(new_list, equal_new_list)
示例#7
0
    def test_filter(self):
        alist = [0, 1, 2, 3, 4, 11]
        self.set = from_list(alist)

        def filterOdd(value):
            if value % 2 == 0:
                return True
            else:
                return False

        res = set_filter(self.set, filterOdd)
        self.assertEqual(res, [0, 2, 4])
示例#8
0
 def test_has(self):
     alist = [0, 1, 2, 3, 4, 11]
     self.set = from_list(alist)
     self.assertEqual(has(self.set, 11), True)
     self.assertEqual(has(self.set, 9), False)
示例#9
0
 def test_to_list(self):
     alist = [0, 1, 2, 3, 4, 11]
     self.set = from_list(alist)
     self.assertEqual(to_list(self.set), alist)
     self.assertEqual(size(self.set), 6)
示例#10
0
 def test_moid_identity(self, alist):
     identity_set = Set()
     self.set = from_list(alist)
     new_set = monoid_add(self.set, identity_set)
     self.assertEqual(new_set.data, self.set.data)