def test_projection_attribute():
    """
    Test Unknown attribute Raise
    """
    try:
        projection(EMPLOYEES, ["hello"])
    except UnknownAttributeException:
        assert True
def test_projection_no_attributes():
    """
    Test projection operation with no attributes getting projected.
    """
    assert projection(EMPLOYEES, []) is None

    empty_table = [["Surname", "FirstName", "Age", "Salary"]]
    assert projection(empty_table, []) is None
def test_cross_product_error():
    """
    Test if there is no attribute matched found
    """
    try:
        projection(R1, EMPTY)
    except UnknownAttributeException:
        assert True
def test_projection_error():
    """
    Test if there is no attribute matched found
    """
    try:
        projection(EMPLOYEES, ["No_Name"])
    except UnknownAttributeException:
        assert True
def test_projection_error():
    """
    Test if there is no attribute matched found
    """
    try:
        projection(EMPLOYEES, ["No_Name"])
    except UnknownAttributeException:
        assert True
def test_cross_product_error():
    """
    Test if there is no attribute matched found
    """
    try:
        projection(R1, EMPTY)
    except UnknownAttributeException:
        assert True
def test_projection_no_attributes():
    """
    Test projection operation with no attributes getting projected.
    """
    assert projection(EMPLOYEES, []) is None

    empty_table = [["Surname", "FirstName", "Age", "Salary"]]
    assert projection(empty_table, []) is None
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"], ["Verdi", "Nico"], ["Smith", "Mark"]]
    result_2 = [["Age", "Salary"], [25, 2000], [40, 3000], [36, 4500], [40, 3900]]
    result_3 = [["Surname"], ["Smith"], ["Black"], ["Verdi"], ["Smith"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
    assert is_equal(result_2, projection(EMPLOYEES, ["Age", "Salary"]))
    assert is_equal(result_3, projection(EMPLOYEES, ["Surname"]))
    try:
        projection(EMPLOYEES, ["inf"])
    except ValueError:
        assert True

    try:
        projection(R3, ["inf"])
    except ValueError:
        assert True

    try:
        projection(R3, [""])
    except ValueError:
        assert True
Beispiel #9
0
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"],
              ["Verdi", "Nico"], ["Smith", "Mark"]]
    result_2 = [["Age", "Salary"], [25, 2000], [40, 3000], [36, 4500],
                [40, 3900]]
    result_3 = [["Surname"], ["Smith"], ["Black"], ["Verdi"], ["Smith"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
    assert is_equal(result_2, projection(EMPLOYEES, ["Age", "Salary"]))
    assert is_equal(result_3, projection(EMPLOYEES, ["Surname"]))
    try:
        projection(EMPLOYEES, ["inf"])
    except ValueError:
        assert True

    try:
        projection(R3, ["inf"])
    except ValueError:
        assert True

    try:
        projection(R3, [""])
    except ValueError:
        assert True
def test_projection_all_attributes():
    """
    Test projection operation with all attributes projected.
    """
    result = [["Surname", "FirstName", "Age", "Salary"],
              ["Smith", "Mary", 25, 2000], ["Black", "Lucy", 40, 3000],
              ["Verdi", "Nico", 36, 4500], ["Smith", "Mark", 40, 3900]]
    attribute_list = ["Surname", "FirstName", "Age", "Salary"]
    empty_table = [attribute_list]
    assert is_equal(result, projection(EMPLOYEES, attribute_list))
    assert projection(empty_table, attribute_list) is None
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"],
              ["Verdi", "Nico"], ["Smith", "Mark"]]
    result_2 = [["Surname"], ["Smith"], ["Black"], ["Verdi"], ["Smith"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
    assert is_equal(result_2, projection(EMPLOYEES, ["Surname"]))
    assert projection(R3, []) is None
def test_projection_all_attributes():
    """
    Test projection operation with all attributes projected.
    """
    result = [["Surname", "FirstName", "Age", "Salary"],
              ["Smith", "Mary", 25, 2000],
              ["Black", "Lucy", 40, 3000],
              ["Verdi", "Nico", 36, 4500],
              ["Smith", "Mark", 40, 3900]]
    attribute_list = ["Surname", "FirstName", "Age", "Salary"]
    empty_table = [attribute_list]
    assert is_equal(result, projection(EMPLOYEES, attribute_list))
    assert projection(empty_table, attribute_list) is None
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
    assert projection(R3, R6) is None
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]
    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))

    result = [["A", "C"], [1, 3], [4, 6]]
    assert is_equal(result, projection(R, ["A", "C"]))

    # If attributes passed in is empty, return empty table
    assert is_equal([], projection(EMPLOYEES, []))

    # Empty table as input should return empty table
    assert is_equal([], projection([], ["Surname", "FirstName"]))

    with pytest.raises(UnknownAttributeException):
        projection(EMPLOYEES, ["InvalidColumn"])

        # Mix of valid and invalid columns should still raise exception
        projection(EMPLOYEES, ["Surname", "InvalidColumn"])
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"], ["Verdi", "Nico"], ["Smith", "Mark"]]

    result1 = [["Surname"], ["Smith"], ["Black"], ["Verdi"], ["Smith"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
    assert is_equal(result1, projection(EMPLOYEES, ["Surname"]))

    with pytest.raises(AssertionError):
        assert projection(EMPLOYEES, ["Surname", "MiddleName", "FirstName"])
def test_projection_error():
    """
    Checks to make sure that the UnknownAttributeException is
    raised when the indicated attribute is not found within the table
    and when attribute is left blank
    :return:
    """
    try:
        projection(EMPLOYEES, [""])
    except UnknownAttributeException:
        assert True

    try:
        projection(EMPLOYEES, ["Department"])
    except UnknownAttributeException:
        assert True
def test_projection_attribute_not_found():
    """
    Test projection operation if attribute not found.
    """
    # All mismatch
    try:
        projection(EMPLOYEES, ["LastName", "GivenName"])
        assert False
    except UnknownAttributeException:
        assert True
    # Partial mismatch
    try:
        projection(EMPLOYEES, ["Date of Birth", "Income"])
        assert False
    except UnknownAttributeException:
        assert True
def test_projection_attribute_not_found():
    """
    Test projection operation if attribute not found.
    """
    # All mismatch
    try:
        projection(EMPLOYEES, ["LastName", "GivenName"])
        assert False
    except UnknownAttributeException:
        assert True
    # Partial mismatch
    try:
        projection(EMPLOYEES, ["Date of Birth", "Income"])
        assert False
    except UnknownAttributeException:
        assert True
def test_projection_empty_input_table():
    """
    Test select operation where input table is an empty table.
    """
    empty_table = [["Surname", "FirstName", "Age", "Salary"]]

    assert projection(empty_table, ["Surname", "FirstName", "Surname", "FirstName"]) is None
def test_projection_some_attributes():
    """
    Test projection operation such that some but not all attributes get projected.
    """
    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"],
              ["Verdi", "Nico"], ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
def test_projection2():
    result = [["Age"],
              [25],
              [40],
              [36],
              [40]]

    assert is_equal(result, projection(EMPLOYEES, ["Age"]))
def test_projection_empty_input_table():
    """
    Test select operation where input table is an empty table.
    """
    empty_table = [["Surname", "FirstName", "Age", "Salary"]]

    assert projection(empty_table,
                      ["Surname", "FirstName", "Surname", "FirstName"]) is None
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"], ["Xio", "Anna"], ["Black", "Lucy"],
              ["Sara", "Maria"], ["Smith", "Mark"]]

    assert is_equal(result, projection(STUDENTS, ["Surname", "FirstName"]))
def test_projection_student():
    # Test projection
    result = [["Surname", "Age"],
              ["Yang", 25],
              ["Jia", 23],
              ["Wang", 25],
              ["Fu", 31],
              ["Whiten", 66]]

    assert is_equal(result, projection(STUDENTS, ["Surname", "Age"]))
def test_projection_multiple_same_attribute():
    """
    Test projection operation where attribute list has duplicates. Should only show the attribute once.
    """
    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName", "Surname", "FirstName"]))
def test_projection_team_test():
    # Tests projection operation
    result = [["Surname", "Age"],
          ["Smith", 17],
          ["Vasquez", 23],
          ["Allen", 18],
          ["Allen", 16],
          ["Xun", 47],
          ["Qian", 117]]

    assert is_equal(result, projection(VOTERS, ["Surname", "Age"]))
def test_projection_multiple_same_attribute():
    """
    Test projection operation where attribute list has duplicates. Should only show the attribute once.
    """
    result = [["Surname", "FirstName"], ["Smith", "Mary"], ["Black", "Lucy"],
              ["Verdi", "Nico"], ["Smith", "Mark"]]

    assert is_equal(
        result,
        projection(EMPLOYEES,
                   ["Surname", "FirstName", "Surname", "FirstName"]))
def test_projection_some_attributes():
    """
    Test projection operation such that some but not all attributes get projected.
    """
    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
def test_projection_different_order():
    """
    Test projection for single attribute projection
    :return: list of column named in attribute
    """
    result = [["FirstName"],
              ["Mary"],
              ["Lucy"],
              ["Nico"],
              ["Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["FirstName"]))
def test_projection_our_test():
    """
    Test cross product operation
    :return: list of cross product rows
    """
    result = [["Surname", "Title"],
              ["Mustard", "Colonel"],
              ["Scarlet", "Ms."],
              ["Green", "Mr."],
              ["White", "Mrs."],
              ["Plum", "Professor"]]

    assert is_equal(result, projection(SUSPECTS, ["Surname", "Title"]))
def test_projection():
    """
    Test projection operation for multiple attribute
    return: list of columns named in attributes
    """

    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))
def test_projection_wrong_attributes():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]
    try:
        assert is_equal(result, projection(EMPLOYEES, ["fat guy"]))
    except UnknownAttributeException:
        return True
def test_projection():
    """
    Test projection operation.
    """

    result = [["Surname", "FirstName"],
              ["Smith", "Mary"],
              ["Black", "Lucy"],
              ["Verdi", "Nico"],
              ["Smith", "Mark"]]

    assert is_equal(result, projection(EMPLOYEES, ["Surname", "FirstName"]))

    result2 = [["Surname", "Age", "Salary"],
             ["Smith", 25, 2000],
             ["Black", 40, 3000],
             ["Verdi", 36, 4500],
             ["Smith", 40, 3900]]
    assert is_equal(result2, projection(EMPLOYEES, ["Surname", "Age", "Salary"]))

    result3 = [["Head"],
             ["Mori"],
             ["Brown"]]
    assert is_equal(result3, projection(R2, ["Head"]))
def test_projection1():
    """
    Test projection operation (student version)
    """
    result1 = [['Make', 'Year'],
              ['Toyota', 1989],
              ['Honda', 2011],
              ['Dodge', 2000],
              ['Fiat', 1999]]

    result2 = [["Size", "Preferred Salinity"],
                ["Small", "Fresh"],
                ["Medium", "Salt"],
                ["Large", "Salt"]]

    result3 = [["Preferred Salinity"],
                ["Fresh"],
                ["Salt"],
                ["Salt"]]

    result4 = [["Type", "Size", "Preferred Salinity"],
             ["Trout", "Small", "Fresh"],
             ["Dogfish", "Medium", "Salt"],
             ["Great White", "Large", "Salt"]]

    # Test with regular table and 2 attributes.
    assert is_equal(result1, projection(CARS,["Make", "Year"]))

    # Test with another regular table and 2 attributes
    assert is_equal(result2, projection(FISH, ["Size", "Preferred Salinity"]))

    # Test with regular table and only 1 attribute
    assert is_equal(result3, projection(FISH, ["Preferred Salinity"]))

    # Test with regular table and all included attributes
    assert is_equal(result4, projection(FISH, ["Type", "Size", "Preferred Salinity"]))

    # Test with regular table and attributes provided out of order
    assert is_equal(result4, projection(FISH, ["Size", "Preferred Salinity", "Type"]))

    # Test with attributes not included in table
    try:
       projection(FISH, ["Colour"])
    except UnknownAttributeException:
        assert True
def test_projection_returns_error():
     #Tests whether projection() function raises AttributeError if column is in attributes list but not table1
    try:
        projection(VOTERS, ["Age", "Riding"])
    except AttributeError:
        assert True
def test_projection_returns_error():
    # Checks if projection() function raises an "AttributeError" if column is in the attributes list but not in table1.
    try:
        projection(BASEBALL_PLAYERS, ["Shirt Number", "name"])
    except AttributeError:
        assert True
def test_projection_returns_error():
    # Test if projection has error
    try:
        projection(STUDENTS, ["Age", "Surname"])
    except AttributeError:
        assert True
def projection_error():
    """
    Tests attributes not found on list.
    """
    assert projection(EMPLOYEES,["Hello"]) == False