コード例 #1
0
    def test_can_check_on_subset_with_false_result(self):
        test_set_1 = Set([2, 7, 9])
        test_set_2 = Set([1, 2, 5, 9, 15])

        result = test_set_1.is_subset(test_set_2)

        self.assertFalse(result)
コード例 #2
0
 def __init__(self, logger=RealLogger()):
     self.set_A = Set()
     self.set_B = Set()
     self.result = None
     self.error_msg = None
     self.logger = logger
     self.logger.log('Welcome!')
コード例 #3
0
    def test_can_find_difference_with_diff_sets(self):
        test_set_1 = Set([1, 2, 4, 5])
        test_set_2 = Set([3, 7, 9, 15])
        true_result = Set([1, 2, 4, 5])

        result = test_set_1.difference(test_set_2)

        self.assertEqual(result, true_result)
コード例 #4
0
    def test_can_find_intersection_with_diff_sets(self):
        test_set_1 = Set([1, 2, 4, 5])
        test_set_2 = Set([3, 7, 9, 15])
        true_result = Set([])

        result = test_set_1.intersection(test_set_2)

        self.assertEqual(result, true_result)
コード例 #5
0
 def test_can_check_element_contain(self):
     test_set = Set([1, 2, 4, 5])
     element = 4
     result = element in test_set
     self.assertTrue(result)
コード例 #6
0
 def test_set_with_some_elements_is_not_empty(self):
     test_set = Set([1, 2, 4, 5])
     result = test_set.is_empty()
     self.assertFalse(result)
コード例 #7
0
 def test_can_union_with_list(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [7, 8, 10]
     test_set.union(test_list)
     self.assertEqual(test_set.get_size(), 7)
コード例 #8
0
 def __init__(self):
     self.set_A = Set()
     self.set_B = Set()
     self.result = None
     self.error_msg = None
コード例 #9
0
 def test_can_union_with_set(self):
     test_set = Set([1, 2, 4, 5])
     another_set = Set([6, 9, 14, 15])
     test_set.union(another_set)
     self.assertEqual(test_set.get_size(), 8)
コード例 #10
0
 def test_can_check_equalities_of_set_and_int(self):
     test_set = Set([1])
     test_int = 1
     result = (test_set == test_int)
     self.assertTrue(result)
コード例 #11
0
 def test_can_init_with_default_constructor(self):
     test_set = Set()
     self.assertTrue(isinstance(test_set, Set))
コード例 #12
0
 def test_cant_find_difference_with_non_set_object(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [2, 3, 5, 15]
     with self.assertRaises(TypeError):
         test_set.difference(test_list)
コード例 #13
0
 def test_cant_find_intersection_with_non_set_object(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [2, 3, 5, 15]
     with self.assertRaises(TypeError):
         test_set.intersection(test_list)
コード例 #14
0
 def test_can_init_with_init_constructor(self):
     test_list_of_elements = [1, 2, 3, 5, 7]
     test_set = Set(test_list_of_elements)
     self.assertEqual(test_set.get_size(), 5)
コード例 #15
0
 def test_can_union_with_one_element(self):
     test_set = Set([1, 2, 4, 5])
     test_set.union(7)
     self.assertEqual(test_set.get_size(), 5)
コード例 #16
0
 def test_can_union_with_set_contain_same_elements(self):
     test_set = Set([1, 2, 4, 5])
     another_set = Set([1, 5, 14, 15])
     test_set.union(another_set)
     self.assertEqual(test_set.get_size(), 6)
コード例 #17
0
 def test_can_check_element_not_contain(self):
     test_set = Set([1, 2, 4, 5])
     element = 7
     result = element in test_set
     self.assertFalse(result)
コード例 #18
0
 def test_can_init_with_default_constructor_one_elem_set(self):
     test_set = Set(5)
     self.assertEqual(test_set.get_size(), 1)
コード例 #19
0
 def test_can_check_equalities_of_uneqvivalent_sets(self):
     test_set_1 = Set([1, 2, 4, 5])
     test_set_2 = Set([1, 3, 4, 5])
     result = (test_set_1 == test_set_2)
     self.assertFalse(result)
コード例 #20
0
 def test_cant_eq_with_invalide_argument(self):
     test_set = Set([1, 2, 4, 5])
     with self.assertRaises(TypeError):
         test_set == "invalide argument"
コード例 #21
0
 def test_can_check_equalities_of_set_and_list(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [1, 2, 4, 5]
     result = (test_set == test_list)
     self.assertTrue(result)
コード例 #22
0
 def test_dont_add_ununic_element(self):
     test_set = Set([1, 2, 4, 5])
     element = 2
     test_set.add(element)
     self.assertEqual(test_set.get_size(), 4)
コード例 #23
0
 def test_can_check_equalities_of_no_one_element_set_and_int(self):
     test_set = Set([1, 3])
     test_int = 1
     result = (test_set == test_int)
     self.assertFalse(result)
コード例 #24
0
 def test_can_union_with_list_contain_same_elements(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [2, 5, 10]
     test_set.union(test_list)
     self.assertEqual(test_set.get_size(), 5)
コード例 #25
0
 def test_can_add_new_element(self):
     test_set = Set([1, 2, 4, 5])
     element = 7
     test_set.add(element)
     self.assertTrue(element in test_set)
コード例 #26
0
 def test_cant_check_on_subset_with_non_set_object(self):
     test_set = Set([1, 2, 4, 5])
     test_list = [2, 5]
     with self.assertRaises(TypeError):
         test_set.is_subset(test_list)
コード例 #27
0
 def test_can_delete_element(self):
     test_set = Set([1, 2, 4, 5])
     element = 1
     test_set.delete(element)
     self.assertFalse(element in test_set)
コード例 #28
0
 def test_cant_init_with_default_constructor_invalide_arg(self):
     with self.assertRaises(TypeError):
         Set("invalide argument")
コード例 #29
0
 def test_set_with_size_0_is_empty(self):
     test_set = Set()
     result = test_set.is_empty()
     self.assertTrue(result)
コード例 #30
0
 def test_cant_delete_uncontain_element(self):
     test_set = Set([1, 2, 4, 5])
     uncontain_element = 7
     with self.assertRaises(ValueError):
         test_set.delete(uncontain_element)