def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) # Tested with another table for correct results result1 = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38], [9297, "Rodriguez", 56], [7432, "O'Mealy", 39]] assert is_equal(result1, union(GRADUATES, ADMIN)) # test if tables are not the same attributes, will give error try: union(GRADUATES, VENDORS) except MismatchedAttributesException: assert True else: assert MismatchedAttributesException
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38], [7274, "Robinson", 37]] assert result == union(MANAGERS, GRADUATES) result = [["Number", "Surname", "Age"], [7434, "Silva", 33], [8374, "Cray", 40], [9824, "Darkes", 38], [7274, "Robinson", 37], [7432, "O'Malley", 39]] assert result == union(PROFESSORS, GRADUATES) result = [['Number', 'Surname', 'Age'], [7274, 'Robinson', 37], [7432, "O'Malley", 39], [9824, 'Darkes', 38], [9297, "O'Malley", 56]] assert result == union(GRADUATES,MANAGERS) try: assert result == union(GRADUATES, STAFF) except MismatchedAttributesException: assert True
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] result_extended = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38], [1346, "Shannan", 24], [2954, "Ericson", 36], [1425, "Tester", 82]] assert is_equal(result, union(GRADUATES, MANAGERS)) # test for MismatchedAttributesException try: union(GRADUATES, NON_IDENTICAL) except MismatchedAttributesException: assert True # test for different row lengths assert is_equal(result_extended, union(GRADUATES, ADDITIONAL_ROWS))
def test_schemas(): """ Established a function to test whether the schemas of both tables are the same. If they are not the program raises a MismatchedAttributesException error. """ with pytest.raises(Exception): union(GRADUATES,BEATLES)
def test_schema_columns(): """ Test to make sure an error is thrown if the amount of columns of the table do not match """ try: schema_check(GRADUATES, MANAGERS_WRONG) except MismatchedAttributesException: assert True else: assert False try: union(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False try: intersection(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False try: difference(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False
def test_schema_titles(): """ Tests to make sure an error is thrown if the schema titles to not match """ try: schema_check(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False try: union(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False try: intersection(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False try: difference(GRADUATES_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) result_unique_table = [["Number", "Name", "Age"], [1111, "Adam", 40], [2222, "Bob", 41], [3333, "Jack", 42], [4444, "George", 31], [5555, "Steve", 32], [6666, "Ron", 33]] assert is_equal(result_unique_table, union(UNIQUE_TABLE_1, UNIQUE_TABLE_2)) # If schema is invalid MismatchedAttributesException raised is_invalid_schema = False try: assert is_equal(result, union(GRADUATES, INVALID_SCHEMA)) except MismatchedAttributesException: is_invalid_schema = True assert is_invalid_schema == True
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] result_2 =[["Name", "Gender", "Age", "School"], ["Matt", "Male", 21, "McMaster University"], ["Katie", "Female", 22, "University od Waterloo"], ["Claire", "Female", 24, "University of Toronto"], ["Stephen", "Male", 23, "University of Ottawa"], ["Ryan", "Male", 19, "SFU"], ["Michael", "Male", 22, "Queens University"]] assert is_equal(result, union(GRADUATES, MANAGERS)) assert is_equal(result_2,union(APPLICANT,CANDIDATE)) # When schemas in lists do not match try: assert union(GRADUATES, APPLICANT) except MismatchedAttributesException: pass
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] result_2 = [["Name", "Gender", "Age", "School"], ["Matt", "Male", 21, "McMaster University"], ["Katie", "Female", 22, "University od Waterloo"], ["Claire", "Female", 24, "University of Toronto"], ["Stephen", "Male", 23, "University of Ottawa"], ["Ryan", "Male", 19, "SFU"], ["Michael", "Male", 22, "Queens University"]] assert is_equal(result, union(GRADUATES, MANAGERS)) assert is_equal(result_2, union(APPLICANT, CANDIDATE)) # When schemas in lists do not match try: assert union(GRADUATES, APPLICANT) except MismatchedAttributesException: pass
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] result_2 = [["Name", "Student No", "Program", "Course"], ["Ryan", 1002178216, "ISD", 1341], ["Param", 1002178213, "KMD", 1340], ["Michael", 100218765, "LIS", 1234], ["Mibin", 1002176123, "KMIM", 2176], ["Steph", 1002154321, "LIS", 8712], ["John", 1002123442, "CRO", 1276]] assert is_equal(result, union(GRADUATES, MANAGERS)) assert is_equal(result_2, union(STUDENTS, COURSES)) # Test Case when the Schemas don't match try: assert union(GRADUATES, STUDENTS) except MismatchedAttributesException: pass
def test_union(): """ Test union operation. If both tables have the same schema the function will return a new table that contains all unique rows that appear in either table. Tested three comparisons, one where two tables were semi-similar, one where they were the same and one where they were completely different. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, ALUMNI)) result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38], [5400, "Bernard", 40], [7302, "Markham", 34], [8776, "Shingle", 52]] assert is_equal(result, union(GRADUATES, ACTORS))
def test_union_unexpected(): """ Test that raises MismatchedAttributesException This is when schema do not have same number of columns or columns do not have same names in the same order """ try: union(GRADUATES, CATS) except MismatchedAttributesException: assert True
def test_union_different_schema_1(): """ Test union operation.Scheme are not the same """ try: union(MANAGERS, STAFFS) except MismatchedAttributesException: assert True else: assert False
def test_union_different_schema_2(): """ Test union operation.Scheme are not the same. Table2 only has a header. """ try: union(MANAGERS, NO_HEADER) except MismatchedAttributesException: assert True else: assert False
def test_number_columns_not_equal(): """ Test schema, if number of columns aren't the same. """ try: union(STUDENTS, TEACHERS) except MismatchedAttributesException: assert True else: assert False
def test_union_mismatch_schema(): try: union(PETS, EMPLOYEES) assert False except: assert True try: union(MANAGERS, PETS) assert False except: assert True
def test_advanced_union(): # Test the union function by comparing the additional tables generated. result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755], ["Jessica", "Female", 8863], ["Frank", "Male", 1103], ["Nana", "Female", 7766], ["Jowell", "Male", 6688]] assert is_equal(result, union(LIST1, LIST2)) # A special situation where two table are completely identical. result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755], ["Jessica", "Female", 8863], ["Frank", "Male", 1103]] assert is_equal(result, union(LIST1, LIST4))
def test_union(): """ Test union operation and checks for duplicates. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) result2 = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result2, union(GRADUATES, STUDENTS))
def test_advanced_union(): # Test the union function by comparing the additional tables generated. result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755], ["Jessica", "Female", 8863], ["Frank","Male", 1103], ["Nana", "Female", 7766], ["Jowell", "Male", 6688]] assert is_equal(result, union(LIST1, LIST2)) # A special situation where two table are completely identical. result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755], ["Jessica", "Female", 8863], ["Frank","Male", 1103]] assert is_equal(result, union(LIST1, LIST4))
def test_MismatchedAttributesException(): # Test if the function union will capture the error when the schemas are not identical. try: union(LIST1, LIST3) except MismatchedAttributesException: assert True #Test if the function intersection will capture the error when the schemas are not identical try: intersection(LIST1, LIST3) except MismatchedAttributesException: assert True #Test if the function difference will capture the error when the schemas are not identical try: difference(LIST1, LIST3) except MismatchedAttributesException: assert True
def test_union_works(): result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(MANAGERS, GRADUATES))
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) try: assert union(MANAGERS,SCREWED_TABLE) except MismatchedAttributesException: pass
def test_union_invalid_schema(): """ Test invalid schema for union operations """ try: assert union(MANAGERS, MANAGERS_WITHOUT_AGE) except MismatchedAttributesException: return True
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS))
def test_union_none(): """ Test union operation on identical tables. """ result = [["ID Number", "Surname", "Age"], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(PROFESSORS, INSTRUCTORS))
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) result = [["Number", "Surname", "Age"], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(MANAGERS, WORKERS))
def test_union_graduates_header(): """ Test union operation. Table1 is the GRADUATES table; Table2 only has header, does not contain any record. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, HEADER_ONLY))
def test_union(): """ Test union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) # test for MismatchedAttributesException try: union(GRADS_WRONG, MANAGERS) except MismatchedAttributesException: assert True else: assert False
def test_union_advanced(): """ Test union operation. """ result = [["Number", "Name", "Age"], [1111, "Rachel", 37], [4444, "Monica", 56], [2222, "Joey", 39], [3333, "Ross", 38]] assert is_equal(result, union(FRIENDS1, FRIENDS2))
def test_union_students(): """ Test union operation on students of enrolled in classes at ryerson and toronto """ result = [['First Name', 'Last Name', 'Student ID', 'Number of Courses'], ['Albert', 'Tai', '99902312', 5], ['James', 'Falcon', '99502312', 12], ['John', 'Dylan', '999032222', 16], ['Sam', 'Smith', '99902312', 21], ['Why', 'Me', '999034422', 21], ['Ilike', 'Work', '99902312', 25]] assert is_equal(result, union(UOFT_STUDENTS, RY_STUDENTS))
def test_union_negative(): """ Test error union operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] if not is_equal(result, union(GRADUATES, MANAGERS)): assert True
def test_difference_negative(): """ Tests to make sure that our difference function raises the MismatchedAttributesException if the two tables column numbers or values are different """ # Tables have different number of columns try: union(GRADUATES, STUDENTS) except MismatchedAttributesException: assert True else: assert False # Tables have different column values try: union(GRADUATES, PROFESSORS) except MismatchedAttributesException: assert True else: assert False # Tables have different number of columns and values try: union(PROFESSORS, STUDENTS) except MismatchedAttributesException: assert True else: assert False
def my_test_union(): """ Test union operation. """ result = [["Title", "Author_Last_Name", "Holdings"], ["Hitcher's Guide to the Galaxy", "Adams", "Robarts"], ["Suite Venitienne", "Calle", "Robarts"], ["Practical Programming", "Gries, Campbell", "Robarts"], ["Illuminations", "Benjamin", "Pratt"], ["Restaurant at the End of the Universe", "Adams", "Pratt"], ["Arcades Project", "Benjamin", "Robarts"]] assert result == union(LIBRARY_1, LIBRARY_2)
def test_difference(): """ Test difference operation. """ result = [["Number", "Surname", "Age"], [7274, "Robinson", 37]] assert is_equal(result, difference(GRADUATES, MANAGERS)) try: assert union(MANAGERS,SCREWED_TABLE) except MismatchedAttributesException: pass
def test_union(): """ Test union operation. """ # Positive cases result = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [9297, "O'Malley", 56], [7432, "O'Malley", 39], [9824, "Darkes", 38]] assert is_equal(result, union(GRADUATES, MANAGERS)) # STUDENTS list result2 = [["Number", "Surname", "Age"], [7274, "Robinson", 37], [7432, "O'Malley", 39], [9824, "Darkes", 38], [1234, "Test student", 56], [7890, "New student", 01]] assert is_equal(result2, union(GRADUATES, STUDENTS)) # BAD_SCHEMA union with itself; works since schemas do match. result3 = [["Number", "Surname", "First Name", "Age"], [7274, "Robinson", "Tom", 37], [7432, "O'Malley", "Bob", 39]] assert is_equal(result3, union(BAD_SCHEMA, BAD_SCHEMA)) # Not any union assert union(BLANK, BLANK) == None # Errors # Exception handling - testing schemas not matching try: union(GRADUATES, BAD_SCHEMA) except MismatchedAttributesException: assert True