示例#1
0
def test_difference():
    """
    Test difference operation.
    """

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

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

    # STUDENTS list
    result2 = [["Number", "Surname", "Age"],
              [7432, "O'Malley", 39],
              [9824, "Darkes", 38]]

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

    # If no common rows exist
    # BAD_SCHEMA difference with itself; works since schemas do match.
    # Result only has the header because there are
    # no "unique rows that appear in the first table but not the second."
    # result3 = [["Number", "Surname", "First Name", "Age"]]  # Updated 2015-11-06

    # assert is_equal(result3, difference(BAD_SCHEMA, BAD_SCHEMA))  # Updated 2015-11-06
    assert difference(BAD_SCHEMA, BAD_SCHEMA) == None


    # Errors
    # Exception handling - testing schemas not matching
    try:
        difference(GRADUATES, BAD_SCHEMA)
    except MismatchedAttributesException:
        assert True
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_difference():
	"""
    Test difference operation.
    """

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

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

	# mismatched tables

	try:
		difference(GRADS_WRONG, MANAGERS)
	except MismatchedAttributesException:
		assert True
	else:
		assert False

	try:
		difference(MNGRS_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_difference():
    """
    Test difference operation.
    """

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

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

    result_unique_table = [["Number", "Name", "Age"],
                           [1111, "Adam", 40],
                            [2222, "Bob", 41],
                            [3333, "Jack", 42]]


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

    result_same_table = []

    # If tables are the same the difference should return an empty list
    assert is_equal(result_same_table, difference(GRADUATES, GRADUATES))

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

    assert is_invalid_schema == True
def test_difference_works():
    result = [["Number", "Surname", "Age"],
              [9297, "O'Malley", 56]]
    assert is_equal(result, difference(MANAGERS, GRADUATES))

    result2 = [["Number", "Surname", "Age"],
               [7274, "Robinson", 37]]
    assert is_equal(result2, difference(GRADUATES, MANAGERS))
def test_difference_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:
        difference(MANAGERS, CATS)
    except MismatchedAttributesException:
        assert True
def test_difference_different_schema_1():
    """
    Test difference operation. Scheme are not the same.
    """
    try:
        difference(MANAGERS, STAFFS)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
def test_difference_different_schema_2():
    """
    Test difference operation. Scheme are not the same.Table2 is empty.
    """
    try:
        difference(MANAGERS, NO_HEADER)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
def test_column_names_not_equal():
    """
    Test schema, if names in column aren't the same.
    """

    try:
        difference(PRINCIPLES, TEACHERS)
    except MismatchedAttributesException:
        assert True
    else:
        assert False
def test_difference_mismatch_schema():
    try:
        difference(PETS, EMPLOYEES)
        assert False
    except:
        assert True
    try:
        difference(GRADUATES, PETS)
        assert False
    except:
        assert True
def test_difference():
    """
    Test difference operation and shows all unique rows in Graduates
    """

    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]
    assert is_equal(result, difference(GRADUATES, MANAGERS))

    # test output when empty table expected
    assert difference(GRADUATES, STUDENTS) is None
def test_difference():
    """
    Test difference operation.
    """

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

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

    # Test pets operation to include a table with various schema

    result = [["Color", "Name", "Weight"], ["brown", "Barker", 32]]

    assert is_equal(result, difference(DOGS, CATS))
示例#14
0
def test_advanced_difference():
    # Test the difference function by comparing the additional tables generated.
    result = [["Name", "Sex", "ID"], ["Jessica", "Female", 8863],
              ["Frank", "Male", 1103]]

    assert is_equal(result, difference(LIST1, LIST2))

    # A special situation where two tables are completely identical.
    result = []
    assert is_equal(result, difference(LIST1, LIST4))

    # A special situation where there are no intersection between two tables.
    result = [["Name", "Sex", "ID"], ["Terry", "Male", 0755],
              ["Nana", "Female", 7766], ["Jowell", "Male", 6688]]
    assert is_equal(result, difference(LIST2, LIST5))
def test_difference_none():
    """
    Test difference operation on identical tables.
    """
    result = [['ID Number', 'Surname', 'Age']]

    assert is_equal(result, difference(PROFESSORS, INSTRUCTORS))
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
示例#17
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
示例#18
0
def test_difference():
    """
    Test difference operation.
    """
    result = [["Number", "Surname", "Age"], [7274, "Robinson", 37]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))
def test_difference_invalid_schema():
    """
    Test invalid schema for difference operations
    """
    try:
        assert difference(MANAGERS, MANAGERS_WITHOUT_AGE)
    except MismatchedAttributesException:
        return True
示例#20
0
def test_difference():
    """
    Test difference operation.
    """
    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))
示例#21
0
def test_difference_advanced():
    """
    Test difference operation.
    """
    result = [["Number", "Name", "Age"],
              [1111, "Rachel", 37]]

    assert is_equal(result, difference(FRIENDS1, FRIENDS2))
def test_difference_invalid_schema():
    """
    Test invalid schema for difference operations
    """
    try:
        assert difference(MANAGERS, MANAGERS_WITHOUT_AGE)
    except MismatchedAttributesException:
        return True
def test_difference():
    """
    Test difference operation.
    """
    # Something of a table in common
    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]
    assert is_equal(result, difference(GRADUATES, MANAGERS))

    result = [["Number", "Surname", "Age"],
            [9297, "O'Malley", 56]]
    assert is_equal(result, difference(MANAGERS, GRADUATES))

    # All of one table in common
    result = [["Number", "Surname", "Age"],
              [0001, "Grey", 45],
              [0002, "Locke", 40],
              [0003, "Hughes", 59]]
    assert is_equal(result, difference(EMPLOYEES, MANAGERS))

    assert is_equal(None, difference(MANAGERS, EMPLOYEES))

    #Exactly the same table
    assert is_equal(None, difference(PETS, PETS))

    # Nothing intersecting
    assert is_equal(OWNER, difference(OWNER, MANAGERS))
    assert is_equal(MANAGERS, difference(MANAGERS, OWNER))
示例#24
0
def test_difference():
    """
    Test difference operation.
    """

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

    result_2 = [["Name", "Gender", "Age", "School"],
                ["Matt", "Male", 21, "McMaster University"],
                ["Claire", "Female", 24, "University of Toronto"]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))
    assert is_equal(result_2, difference(APPLICANT, CANDIDATE))

    try:
        assert difference(GRADUATES, APPLICANT)
    except MismatchedAttributesException:
        pass
def test_advanced_difference():
    # Test the difference function by comparing the additional tables generated.
    result = [["Name", "Sex", "ID"],
              ["Jessica", "Female", 8863],
              ["Frank","Male", 1103]]

    assert is_equal(result, difference(LIST1, LIST2))

    # A special situation where two tables are completely identical.
    result = []
    assert is_equal(result, difference(LIST1, LIST4))

    # A special situation where there are no intersection between two tables.
    result = [["Name", "Sex", "ID"],
              ["Terry", "Male", 0755],
              ["Nana", "Female", 7766],
              ["Jowell", "Male", 6688]]
    assert is_equal(result, difference(LIST2, LIST5))
示例#26
0
def test_difference_negative():
    """
    Test error intersection operation.
    """
    result = [["Number", "Surname", "Age"],
              [7274, "Robinson", 37]]

    if not is_equal(result, difference(GRADUATES, MANAGERS)):
        assert True
示例#27
0
def my_test_difference():
    """
	Test difference operation.
	"""
    result = [["Title", "Author_Last_Name", "Holdings"],
              ["Suite Venitienne", "Calle", "Robarts"],
              ["Illuminations", "Benjamin", "Pratt"]]

    assert result == difference(LIBRARY_1, LIBRARY_2)
def test_my_difference_test():
    """
    Test difference operation.
    """
    result = [['Make', 'Color', 'Year', 'Works(y/n)'],
              ['Honda', 'Orange', 2011, 'n'],
              ['Fiat', 'Polka dot', 1999, 'y']]

    assert is_equal(result, difference(CARS, TRUCKS))
def my_test_difference():
	"""
	Test difference operation.
	"""
	result = [["Title", "Author_Last_Name", "Holdings"],
			  ["Suite Venitienne", "Calle", "Robarts"],
			  ["Illuminations", "Benjamin", "Pratt"]]

	assert result == difference(LIBRARY_1, LIBRARY_2)
def test_difference():
    """
    Test difference operation. After its been determined that the schema of both tables is the same the
    function will return a new table that holds all unique rows that appear in the first table but not the second.
    """

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

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

    assert difference(GRADUATES, ALUMNI) == None

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

    assert is_equal(result, difference(GRADUATES, ACTORS))
def test_difference():
    """
    Test difference operation.
    """

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

    result_2 = [["Name", "Gender", "Age", "School"],
                ["Matt", "Male", 21, "McMaster University"],
                ["Claire", "Female", 24, "University of Toronto"]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))
    assert is_equal(result_2, difference(APPLICANT,CANDIDATE))

    try:
        assert difference(GRADUATES, APPLICANT)
    except MismatchedAttributesException:
        pass
def test_difference_student():
    """
    Testing difference between student tables
    """

    result = [['First Name', 'Last Name', 'Student ID', 'Number of Courses'],
              ['Albert', 'Tai', '99902312', 5],
              ['James', 'Falcon', '99502312', 12]]

    assert is_equal(result, difference(UOFT_STUDENTS, RY_STUDENTS))
def test_difference():
    """
    Test difference operation.
    """

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

    result_2 = [["Name", "Student No", "Program", "Course"],
                ["Mibin", 1002176123, "KMIM", 2176],
                ["Steph", 1002154321, "LIS", 8712]]

    assert is_equal(result, difference(GRADUATES, MANAGERS))
    assert is_equal(result_2, difference(STUDENTS, COURSES))
    # Test Case when the Schemas don't match
    try:
        assert difference(GRADUATES, STUDENTS)
    except MismatchedAttributesException:
        pass
def test_difference_student():
    """
    Testing difference between student tables
    """

    result = [['First Name', 'Last Name', 'Student ID', 'Number of Courses'],
              ['Albert', 'Tai', '99902312', 5],
              ['James', 'Falcon', '99502312', 12]]

    assert is_equal(result, difference(UOFT_STUDENTS, RY_STUDENTS))
def test_difference_graduates_employees():
    """
    Test difference operation.Table1 is the GRADUATES table; Table2 is the EMPLOYEES table.
    """

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

    assert is_equal(result, difference(GRADUATES, EMPLOYEES))
def test_difference_graduates_header():
    """
    Test difference 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, difference(GRADUATES, HEADER_ONLY))
def test_difference_employees_graduates():
    """
    Test difference operation.Table1 is the EMPLOYEES table; Table2 is the GRADUATES table.
    """

    result = [["Number", "Surname", "Age"],
              [1000, "Ann", 20],
              [1001, "Mary", 22],
              [1002, "Ming", 60]]

    assert is_equal(result, difference(EMPLOYEES, GRADUATES))
示例#38
0
def test_difference():
    """
    Test difference operation.
    """

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

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

    # mismatched tables

    try:
        difference(GRADS_WRONG, MANAGERS)
    except MismatchedAttributesException:
        assert True
    else:
        assert False

    try:
        difference(MNGRS_WRONG, MANAGERS)
    except MismatchedAttributesException:
        assert True
    else:
        assert False