Exemplo n.º 1
0
 def test_init(self):
     st = Sets([1, 2, 3, 4])
     assert st.size == 4
     assert len(st.items.keys()) == 4
     st_two = Sets()
     assert st_two.size == 0
     assert len(st_two.items.keys()) == 0
Exemplo n.º 2
0
 def test_union(self):
     first_set = Sets([1, 2, 3, 4])
     second_set = Sets([1, 2, 3])
     union_set = second_set.union(first_set)
     assert union_set.size == 4
     assert union_set.contains(1) == True
     assert union_set.contains(2) == True
     assert union_set.contains(3) == True
     assert union_set.contains(4) == True
Exemplo n.º 3
0
 def test_is_subset(self):
     first_set = Sets([1, 2, 3, 4, 5, 6])
     second_set = Sets([1, 2, 3, 4])
     assert first_set.is_subset(second_set) == True
     third_set = Sets([11, 12, 13, 14])
     assert first_set.is_subset(third_set) == False
     fourth_set = Sets([2, 2, 2, 2])
     assert first_set.is_subset(fourth_set) == True
     fifth_set = Sets([4, 5, 6, 7, 8])
     assert first_set.is_subset(fifth_set) == False
Exemplo n.º 4
0
 def test_difference(self):
     first_set = Sets([2, 3, 4, 5, 6])
     second_set = Sets([1, 2, 3, 4])
     difference_set = first_set.difference(second_set)
     assert difference_set.size == 2
     assert difference_set.contains(5) == True
     assert difference_set.contains(6) == True
     assert difference_set.contains(1) == False
     assert difference_set.contains(2) == False
     assert difference_set.contains(3) == False
     assert difference_set.contains(4) == False
Exemplo n.º 5
0
 def test_intersection(self):
     first_set = Sets([1, 2, 3, 6])
     second_set = Sets([1, 2, 3, 4, 5, 7])
     intersection_set = first_set.intersection(second_set)
     assert intersection_set.size == 3
     assert intersection_set.contains(1) == True
     assert intersection_set.contains(2) == True
     assert intersection_set.contains(3) == True
     assert intersection_set.contains(4) == False
     assert intersection_set.contains(5) == False
     assert intersection_set.contains(6) == False
     assert intersection_set.contains(7) == False
Exemplo n.º 6
0
 def test_delete(self):
     st = Sets()
     st.add(1)
     st.add(3)
     st.add("hello")
     assert st.size == 3
     st.delete(3)
     assert st.size == 2
     assert st.contains(3) == False
Exemplo n.º 7
0
 def test_add_strings_and_contains(self):
     st = Sets()
     st.add("Hello")
     assert st.size == 1
     st.add("Noah")
     assert st.size == 2
     assert st.contains("Hello") == True
     assert st.contains("Noah") == True
     assert st.contains("Woodward") == False
Exemplo n.º 8
0
    def test_remove(self):

        # Adding elements
        set = Sets()
        set.add('A')
        set.add('B')

        # Deleting elements
        set.remove('A')
        assert set.size == 1
        set.remove('B')
        assert set.size == 0

        with self.assertRaises(KeyError):
            set.remove('B')
Exemplo n.º 9
0
 def test_size(self):
     s = Sets()
     assert s.set_struct.size == 0
     s.add('A')
     assert s.set_struct.size == 1
     s.add('B')
     assert s.set_struct.size == 2
     s.add('C')
     assert s.set_struct.size == 3
Exemplo n.º 10
0
 def test_size(self):
     set = Sets()
     assert set.size == 0
     set.add('A')
     set.add('B')
     set.add('C')
     set.add('D')
     set.add('F')
     assert set.size == 5
Exemplo n.º 11
0
 def test_add_and_contains(self):
     st = Sets()
     st.add(5)
     assert st.size == 1
     st.add(2)
     assert st.size == 2
     assert st.contains(5) == True
     assert st.contains(2) == True
     assert st.contains(7) == False
Exemplo n.º 12
0
    def test_is_subSets(self):
        set1 = Sets(['A', 'B', 'C'])
        set2 = Sets(['A', 'B'])
        is_a_subset = set1.is_subset(set2)
        assert is_a_subset == True

        set1 = Sets(['A', 'B', 'C', 'D'])
        set2 = Sets(['A', 'B', 'C', 'D', 'E'])
        is_a_subset = set1.is_subset(set2)
        assert is_a_subset == False
Exemplo n.º 13
0
    def test_union(self):
        s1 = Sets(['A', 'B', 'C'])
        s2 = Sets(['D', 'E'])
        union_set = s1.union(s2)
        self.assertCountEqual(union_set.set_struct.keys(),
                              ['A', 'B', 'C', 'D', 'E'])

        s1 = Sets(['A', 'A', 'B', 'C'])
        s2 = Sets(['E', 'F', 'G'])
        union_set = s1.union(s2)
        assert (union_set.set_struct.size == 7) == False
Exemplo n.º 14
0
    def test_contains(self):
        set = Sets()
        set.add('A')
        set.add('B')

        # Assert True
        assert set.contains('A') == True
        assert set.contains('B') == True

        # Assert False
        assert set.contains('E') == False
        assert set.contains('F') == False
Exemplo n.º 15
0
    def test_remove(self):
        s = Sets(['A', 'B', 'C'])
        assert s.set_struct.size == 3
        assert s.contains('A')
        assert s.contains('B')
        assert s.contains('C')

        s.remove('A')
        assert s.set_struct.size == 2
        assert s.contains('B')
        assert s.contains('C')

        s.remove('B')
        assert s.set_struct.size == 1
        assert s.contains('C')

        with self.assertRaises(KeyError):
            s.remove('A')
Exemplo n.º 16
0
 def test_init(self):
     s = Sets()
     assert s.set_struct.size == 0
Exemplo n.º 17
0
 def test_intersection(self):
     s1 = Sets(['A', 'B', 'C'])
     s2 = Sets(['A', 'B', 'D'])
     intersection_set = s1.intersection(s2)
     self.assertCountEqual(intersection_set.set_struct.keys(), ['A', 'B'])
Exemplo n.º 18
0
    def test_difference(self):
        s1 = Sets(['A', 'B', 'C', 'D'])
        s2 = Sets(['A', 'B', 'C', 'D', 'E'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), [])

        s1 = Sets(['A', 'B', 'C', 'D'])
        s2 = Sets(['A', 'B', 'C', 'D', 'E'])
        new_set = s2.difference(s1)
        self.assertCountEqual(new_set.set_struct.keys(), ['E'])

        s1 = Sets(['A', 'B', 'C'])
        s2 = Sets(['B', 'C', 'D'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), ['A'])

        s1 = Sets(['A', 'B', 'C'])
        s2 = Sets(['D', 'E', 'F'])
        new_set = s1.difference(s2)
        self.assertCountEqual(new_set.set_struct.keys(), ['A', 'B', 'C'])
Exemplo n.º 19
0
    def test_is_subset(self):
        set_A = Sets()
        set_B = Sets()

        set_A.add('Ronaldo')
        set_A.add('Mbappe')
        set_A.add('Neymar')
        set_A.add('Messi')

        set_B.add('Mbappe')
        set_B.add('Neymar')

        is_subset_result = set_A.is_subset(set_B)
        assert type(is_subset_result) == bool  # should return a list
        assert set_A.size == 4  # set A should retain its original size
        assert set_B.size == 2  # set B should retain its original size
        assert set_B.is_subset(
            set_A) == True  # SET B's elements are all in SET A

        set_B.add('Pele')  # Added an element in SET B that is not in set A
        assert set_B.is_subset(
            set_A) == False  #  SET B's elements are not all in SET A
Exemplo n.º 20
0
 def test_add(self):
     set = Sets()
     assert set.size == 0
     set.add('A')
     set.add('B')
     assert set.size == 2
Exemplo n.º 21
0
    def test_intersection(self):
        set_A = Sets()
        set_B = Sets()

        set_A.add('Ronaldo')
        set_A.add('Mbappe')
        set_A.add('Neymar')
        set_A.add('Messi')

        set_B.add('Rashford')
        set_B.add('Mbappe')
        set_B.add('Neymar')
        set_B.add('DeBruyne')

        assert type(set_A.intersection(set_B)) == list  # should return a list
        assert len(
            set_A.intersection(set_B)) == 2  # Only two element are interscted
        assert set_A.size == 4  # set A should retain its original size
        assert set_B.size == 4  # set B should retain its original size

        # Testing elements in return list to be True
        intersection_result = set_A.intersection(set_B)
        assert 'Neymar' in intersection_result
        assert 'Mbappe' in intersection_result

        # Testing elements not in return list to be True
        assert 'Rashford' not in intersection_result
        assert 'Ronaldo' not in intersection_result
        assert 'Deybrune' not in intersection_result
        assert 'Messi' not in intersection_result
Exemplo n.º 22
0
    def test_union(self):
        set_A = Sets()
        set_B = Sets()

        set_A.add('Medi')
        set_A.add('Mace')
        set_B.add('Yves')
        set_B.add('Sarin')

        assert type(set_A.union(set_B)) == list  # should return a list
        assert set_A.size == 2  # set A should retain its original size
        assert set_B.size == 2  # set B should retain its original size

        union_result = set_A.union(set_B)
        assert len(
            union_result
        ) == 4  # the result of the union should have a size of set A+B
Exemplo n.º 23
0
 def test_init_with_no_element(self):
     set = Sets()
     assert set.size == 0
Exemplo n.º 24
0
 def test_contains(self):
     s = Sets(['A', 'B', 'C'])
     assert s.contains('A') == True
     assert s.contains('B') == True
     assert s.contains('C') == True
     assert s.contains('X') == False
Exemplo n.º 25
0
    def test_add(self):
        s = Sets()
        s.add('A')
        assert s.set_struct.size == 1
        assert s.contains('A')
        s.add('A')
        assert s.set_struct.size == 1

        s.add('B')
        assert s.set_struct.size == 2
        assert s.contains('B')
        s.add('B')
        assert s.set_struct.size == 2
    group.add_argument(
        '--json',
        type=str,
        help='If given file does not exist, fall back to environment variable')
    group.add_argument('--lists',
                       nargs='+',
                       type=argparse.FileType('rb'),
                       help='Single column lists')

    parser.add_argument('--output',
                        type=str,
                        required=True,
                        help='Destination directory')

    return parser


if __name__ == '__main__':
    parser = arg_parser()
    args = parser.parse_args()
    if args.json:
        lists = read_json(args.json)
    elif args.lists:
        lists = read_files(args.lists)
    else:
        raise Exception('argparse validation should have failed earlier')
    sets = Sets(lists)
    pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)
    sets.print_columns(os.path.join(args.output, 'columns.txt'))
    sets.print_ratio_matrix(os.path.join(args.output, 'ratio_matrix.txt'))
Exemplo n.º 27
0
    def test_difference(self):
        set_A = Sets()
        set_B = Sets()

        set_A.add('Ronaldo')
        set_A.add('Mbappe')
        set_A.add('Neymar')
        set_A.add('Messi')

        set_B.add('Rashford')
        set_B.add('Mbappe')
        set_B.add('Neymar')
        set_B.add('DeBruyne')

        difference_result = set_A.difference(set_B)
        assert type(difference_result) == list  # should return a list
        assert set_A.size == 4  # set A should retain its original size
        assert set_B.size == 4  # set B should retain its original size

        # Testing for Element in SET A not in SET B
        assert 'Ronaldo' in difference_result
        assert 'Messi' in difference_result

        # Testing intersecting elements are not in the difference
        assert 'Neymar' not in difference_result
        assert 'Mbappe' not in difference_result

        # Testing for Element in SET B not in SET A
        difference_result = set_B.difference(set_A)
        assert 'DeBruyne' in difference_result
        assert 'Rashford' in difference_result