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_intersection():
    """
    Test intersection operation.
    """
    intersection_result = [["Number", "Surname", "Age"],
                           [7432, "O'Malley", 39],
                           [9824, "Darkes", 38]]

    graduates = [["Number", "Surname", "Age"],
                 [7274, "Robinson", 37],
                 [7432, "O'Malley", 39],
                 [9824, "Darkes", 38]]

    managers = [["Number", "Surname", "Age"],
                [9297, "O'Malley", 56],
                [7432, "O'Malley", 39],
                [9824, "Darkes", 38]]

    result_2 = [["Name", "Gender", "Age", "School"],
                ["Katie", "Female", 22, "University od Waterloo"],
                ["Stephen", "Male", 23, "University of Ottawa"]]

    assert is_equal(intersection_result, intersection(graduates, managers))
    assert is_equal(result_2, intersection(APPLICANT, CANDIDATE))

    try:
        assert intersection(GRADUATES, APPLICANT)
    except MismatchedAttributesException:
        pass
def test_intersection():
	"""
    Test intersection operation.
    """
	result = [["Number", "Surname", "Age"],
			  [7432, "O'Malley", 39],
			  [9824, "Darkes", 38]]

	assert is_equal(result, intersection(GRADUATES, MANAGERS))

	# intersection mismatch

	try:
		intersection(GRADS_WRONG, MNGRS_WRONG)
	except MismatchedAttributesException:
		assert True
	else:
		assert False

	try:
		intersection(MANAGERS, GRADS_WRONG)
	except MismatchedAttributesException:
		assert True
	else:
		assert False
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_intersection_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:
        intersection(MANAGERS, DOGS)
    except MismatchedAttributesException:
        assert True
def test_intersection_different_schema_1():
    """
    Test intersection operation. Scheme are not the same.
    """
    try:
        intersection(MANAGERS, STAFFS)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
def test_intersection_different_schema_2():
    """
    Test intersection operation. Scheme are not the same.Table2 is empty.
    """
    try:
        intersection(MANAGERS, NO_HEADER)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
def test_intersection_mismatch_schema():
    try:
        intersection(PETS, EMPLOYEES)
        assert False
    except:
        assert True
    try:
        intersection(OWNER, PETS)
        assert False
    except:
        assert True
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"], [7432, "O'Malley", 39], [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    # Test pets operation to include a table with various schema

    result = [["Color", "Name", "Weight"], ["white", "Gunner", 7], ["black", "Drake", 13]]

    assert is_equal(result, intersection(DOGS, CATS))
Example #10
0
def test_advanced_intersection():
    # Test the intersection function by comparing the additional tables generated.
    result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755]]

    assert is_equal(result, intersection(LIST1, LIST2))
    # A special situation where there are no intersection between two tables.
    result = []
    assert is_equal(result, intersection(LIST2, LIST5))

    # Test when two tables are identical
    result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755],
              ["Jessica", "Female", 8863], ["Frank", "Male", 1103]]
    assert is_equal(result, intersection(LIST1, LIST4))
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    result = [["Number", "Surname", "Age"]]

    assert is_equal(result, intersection(GRADUATES, ARTISTS))
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    try:
        assert intersection(GRADUATES,SCREWED_TABLE)
    except MismatchedAttributesException:
        pass
def test_advanced_intersection():
    # Test the intersection function by comparing the additional tables generated.
    result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755]]

    assert is_equal(result, intersection(LIST1, LIST2))
    # A special situation where there are no intersection between two tables.
    result = []
    assert is_equal(result, intersection(LIST2, LIST5))

    # Test when two tables are identical
    result = [["Name", "Sex", "ID"],
              ["Terry", "Male", 0755],
              ["Jessica", "Female", 8863],
              ["Frank","Male", 1103]]
    assert is_equal(result, intersection(LIST1, LIST4))
def test_intersection():
    """
    Test intersection function and show all unique rows from t1 and t2

    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    result2 = [['Number', 'Surname', 'Age'], [7274, 'Robinson', 37], [7432, "O'Malley", 39], [9824, 'Darkes', 38]]
    assert is_equal(result2, intersection(GRADUATES, STUDENTS))

    # test output when empty table expected
    assert intersection(GRADUATES, CLASSES) is None
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
Example #16
0
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_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"], [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))
def test_intersection_invalid_schema():
    """
    Test invalid schema for intersection operations
    """
    try:
        assert intersection(MANAGERS, MANAGERS_WITHOUT_AGE)
    except MismatchedAttributesException:
        return True
def test_intersection_invalid_schema():
    """
    Test invalid schema for intersection operations
    """
    try:
        assert intersection(MANAGERS, MANAGERS_WITHOUT_AGE)
    except MismatchedAttributesException:
        return True
def test_intersection():
    """
    Test intersection operation.
    """
    # Something of a table in common
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))
    assert is_equal(result, intersection(MANAGERS, GRADUATES))

    # All of one table in common
    result = [["Number", "Surname", "Age"],
              [9297, "O'Malley", 56],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(EMPLOYEES, MANAGERS))
    assert is_equal(result, intersection(MANAGERS, EMPLOYEES))

    #Exactly the same table
    assert is_equal(PETS, intersection(PETS, PETS))

    # Nothing intersecting
    assert is_equal(None, intersection(OWNER, MANAGERS))
    assert is_equal(None, intersection(MANAGERS, OWNER))
Example #21
0
def my_test_intersection():
    """
	Test intersection operation.
	"""
    result = [["Title", "Author_Last_Name", "Holdings"],
              ["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
              ["Practical Programming", "Gries, Campbell", "Robarts"]]

    assert result == intersection(LIBRARY_1, LIBRARY_2)
def test_intersection_students():
    """
    Testing intersection operation on students
    """
    result = [['First Name', 'Last Name', 'Student ID', 'Number of Courses'],
              ['John', 'Dylan', '999032222', 16],
              ['Sam', 'Smith', '99902312', 21]]

    assert is_equal(result, intersection(UOFT_STUDENTS, RY_STUDENTS))
def my_test_intersection():
	"""
	Test intersection operation.
	"""
	result = [["Title", "Author_Last_Name", "Holdings"],
			  ["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
			  ["Practical Programming", "Gries, Campbell", "Robarts"]]

	assert result == intersection(LIBRARY_1, LIBRARY_2)
def test_intersection_students():
    """
    Testing intersection operation on students
    """
    result = [['First Name', 'Last Name', 'Student ID', 'Number of Courses'],
              ['John', 'Dylan', '999032222', 16],
              ['Sam', 'Smith', '99902312', 21]]

    assert is_equal(result, intersection(UOFT_STUDENTS, RY_STUDENTS))
def test_intersection_advanced():
    """
    Test intersection operation.
    """
    result = [["Number", "Name", "Age"],
              [2222, "Joey", 39],
             [3333, "Ross", 38]]

    assert is_equal(result, intersection(FRIENDS1, FRIENDS2))
def test_my_intersection_test():
    """
    Test intersection operation.
    """
    result = [['Make', 'Color', 'Year', 'Works(y/n)'],
              ['Toyota', 'Yellow', 1989, 'y'],
              ['Dodge', 'Purple', 2000, 'y']]

    assert is_equal(result, intersection(CARS, TRUCKS))
def test_intersection_none():
    """
    Test intersection operation on identical tables.
    """
    result = [["ID Number", "Surname", "Age"],
              [9297, "O'Malley", 56],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(PROFESSORS, INSTRUCTORS))
def test_intersection():
    """
    Test intersection operation. If both tables are the same, function should return a new table
    that contains all the unique rows that appear in both tables.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, ALUMNI))

    assert intersection(GRADUATES, ACTORS) == None
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    result_2 = [['Name', 'Student No', 'Program', 'Course'],
                ['Ryan', 1002178216, 'ISD', 1341],
                ['Param', 1002178213, 'KMD', 1340]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))
    assert is_equal(result_2, intersection(STUDENTS, COURSES))
    # Test Case when the Schemas don't match
    try:
        assert intersection(GRADUATES, STUDENTS)
    except MismatchedAttributesException:
        pass
def test_intersection_negative():
    """
    Test error intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    if not is_equal(result, intersection(GRADUATES, MANAGERS)):
        assert True
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert result == intersection(GRADUATES, MANAGERS)

    result = [["Number", "Surname", "Age"],
              [9824, "Darkes", 38]]

    assert result == intersection(PROFESSORS, MANAGERS)

    assert intersection(GRADUATES, BLANK) is None

    try:
        assert result == intersection(GRADUATES, STAFF)
    except MismatchedAttributesException:
        assert True
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    result_unique_table = []

    assert is_equal(result_unique_table, intersection(UNIQUE_TABLE_1, UNIQUE_TABLE_2))

    # If schema is invalid MismatchedAttributesException raised
    is_invalid_schema = False
    try:
        assert is_equal(result, intersection(GRADUATES, INVALID_SCHEMA))
    except MismatchedAttributesException:
        is_invalid_schema = True

    assert is_invalid_schema == True
def test_intersection():
    """
    Test intersection operation.
    """

    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    result_extended = [["Number", "Surname", "Age"],
                       [7432, "O'Malley", 39],
                       [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    # test for MismatchedAttributesException
    try:
        intersection(GRADUATES, NON_IDENTICAL)
    except MismatchedAttributesException:
        assert True

    # test for different row lengths
    assert is_equal(result_extended, intersection(GRADUATES, ADDITIONAL_ROWS))
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    # Checked intersection with another table, results given in table below
    result1 = [["Number", "Surname", "Age"],
               [9824, "Darkes", 38]]

    assert is_equal(result1, intersection(GRADUATES, ADMIN))

    # Check if second table doesnt have same attributes, gives error
    try:
        intersection(GRADUATES, VENDORS)
    except MismatchedAttributesException:
        assert True
    else:
        assert MismatchedAttributesException
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    result2 = [["Number", "Surname", "Age"],
               [7432, "O'Malley", 39]]

    result3 = [["Name", "Age, Type"],
               ["Socks", 12, "Cat"]]

    result4 = [["Number", "Surname", "Age"],
                [9297, "O'Malley", 56],
                [7432, "O'Malley", 39],
                [9824, "Darkes", 38]]


# Test a regular intersection with matching schema.
    assert is_equal(result, intersection(GRADUATES, MANAGERS))

# Test a second regular intersection with matching schema, in case the first worked by coincidence.
    assert is_equal(result2, intersection(MANAGERS, STAFF))

# Test an intersection of two other tables with matching schema.
    assert is_equal(result3, intersection(PETS, LIVESTOCK))

# Test an intersection of a table with itself.
    assert is_equal(result4, union(MANAGERS, MANAGERS))

# Test an intersection of non-matching schema.
    try:
        intersection(MANAGERS, PETS)
    except MismatchedAttributesException:
        assert True
Example #36
0
def test_intersection():
    """
    Test intersection operation.
    """
    result = [["Number", "Surname", "Age"], [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    # intersection mismatch

    try:
        intersection(GRADS_WRONG, MNGRS_WRONG)
    except MismatchedAttributesException:
        assert True
    else:
        assert False

    try:
        intersection(MANAGERS, GRADS_WRONG)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
Example #37
0
def test_intersection():
    """
    Test intersection operation.
    """
    intersection_result = [["Number", "Surname", "Age"],
                           [7432, "O'Malley", 39], [9824, "Darkes", 38]]

    graduates = [["Number", "Surname", "Age"], [7274, "Robinson", 37],
                 [7432, "O'Malley", 39], [9824, "Darkes", 38]]

    managers = [["Number", "Surname", "Age"], [9297, "O'Malley", 56],
                [7432, "O'Malley", 39], [9824, "Darkes", 38]]

    result_2 = [["Name", "Gender", "Age", "School"],
                ["Katie", "Female", 22, "University od Waterloo"],
                ["Stephen", "Male", 23, "University of Ottawa"]]

    assert is_equal(intersection_result, intersection(graduates, managers))
    assert is_equal(result_2, intersection(APPLICANT, CANDIDATE))

    try:
        assert intersection(GRADUATES, APPLICANT)
    except MismatchedAttributesException:
        pass
def test_difference():
    """
    Test difference operation.
    """

    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))

    result = [['Number', 'Surname', 'Age'],
              [2899, 'Richards', 46], [4566, 'Jackson', 19],
              [5461, 'Marks', 32]]

    assert is_equal(result, intersection(ARTISTS, GRADUATES))
Example #39
0
def test_intersection():
    """
    Test intersection operation.
    """

    # Positive cases
    result = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

    assert is_equal(result, intersection(GRADUATES, MANAGERS))

    # STUDENTS list
    result2 = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]

    assert is_equal(result2, intersection(GRADUATES, STUDENTS))

    # BAD_SCHEMA intersection 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, intersection(BAD_SCHEMA, BAD_SCHEMA))

    # If no common rows exist
    result4 = []

    # assert is_equal(result4, intersection(MANAGERS, STUDENTS))
    assert intersection(MANAGERS, STUDENTS) == None

    # Errors
    # Exception handling - testing schemas not matching
    try:
        intersection(GRADUATES, BAD_SCHEMA)
    except MismatchedAttributesException:
        assert True