示例#1
0
def testFilter():
    studentList = exampleList2

    filteredList = filterProperty(2, 5, studentList)
    assert len(filteredList) == 3
    assert studentIsEqualTo(filteredList[0], 3, 4, 4)
    assert studentIsEqualTo(filteredList[1], 4, 4, 2)
    assert studentIsEqualTo(filteredList[2], 6, 5, 1)

    filteredList = filterProperty(1, 10, studentList)
    assert len(filteredList) == 0

    studentList = exampleList3

    filteredList = filterProperty(1, 4.95, studentList)
    assert len(filteredList) == 5
    assert studentIsEqualTo(filteredList[0], 8, 10, 10)
    assert studentIsEqualTo(filteredList[1], 0, 9, 9)
    assert studentIsEqualTo(filteredList[2], 2, 6, 8)
    assert studentIsEqualTo(filteredList[3], 8, 6, 1)
    assert studentIsEqualTo(filteredList[4], 2, 9, 6)

    filteredList = filterProperty(0, 6, studentList)
    assert len(filteredList) == 1
    assert studentIsEqualTo(filteredList[0], 0, 9, 9)
示例#2
0
def testAdd():
    studentList = []

    add(studentList, createStudent(2, 3, 4))
    assert len(studentList) == 1
    assert studentIsEqualTo(studentList[0], 2, 3, 4)

    add(studentList, createStudent(0, 3, 3))
    assert len(studentList) == 2
    assert studentIsEqualTo(studentList[0], 2, 3, 4)
    assert studentIsEqualTo(studentList[1], 0, 3, 3)
示例#3
0
def testInsert():
    studentList = []

    studentList.append(createStudent(10, 10, 10))
    insert(studentList, 0, createStudent(1, 2, 3))
    assert len(studentList) == 2
    assert studentIsEqualTo(studentList[0], 1, 2, 3)
    assert studentIsEqualTo(studentList[1], 10, 10, 10)

    insert(studentList, 1, createStudent(8, 8, 8))
    assert len(studentList) == 3
    assert studentIsEqualTo(studentList[0], 1, 2, 3)
    assert studentIsEqualTo(studentList[1], 8, 8, 8)
    assert studentIsEqualTo(studentList[2], 10, 10, 10)
示例#4
0
def testReplace():
    studentList = []

    studentList.append(createStudent(1, 3, 3))
    replace(studentList, 0, 2, 10)
    assert len(studentList) == 1
    assert studentIsEqualTo(studentList[0], 1, 10, 3)
def replaceUI(studentList, paramList):
    '''
    Interface for the 'replace' function
    @param:
        - studentList = list of students
        - paramList = list of parameters
            - position of the student to be replaced (integer)
            - Px = which grade to change (string)
            - "with" keyword
            - grade to replace Px with
    @return:
        - None
    '''
    try:
        position = getValidPosition(paramList[0], studentList)
        grade = getValidNumber(paramList[3], 'I')
        problem = getValidProblem(paramList[1])

        if studentIsEqualTo(studentList[position], 0, 0, 0):
            raise EmptyPositionError("Cannot replace an empty position")

    except:
        return

    replace(studentList, position, problem, grade)
示例#6
0
def testAverageRange():
    studentList = []

    studentList.append(createStudent(2, 3, 4))
    result = getAverage(studentList, 0, 0)
    assert result == 3
    assert len(studentList) == 1
    assert studentIsEqualTo(studentList[0], 2, 3, 4)

    studentList.append(createStudent(10, 10, 10))
    studentList.append(createStudent(9, 9, 8))
    result = getAverage(studentList, 0, 2)
    assert result == 7.222
    assert len(studentList) == 3
    assert studentIsEqualTo(studentList[0], 2, 3, 4)
    assert studentIsEqualTo(studentList[1], 10, 10, 10)
    assert studentIsEqualTo(studentList[2], 9, 9, 8)
示例#7
0
def testAverage():
    studentList = []

    studentList.append(createStudent(1, 2, 3))
    result = studentAverage(studentList[0])
    assert result == 2.0
    assert studentIsEqualTo(studentList[0], 1, 2, 3)
    assert len(studentList) == 1

    studentList.append(createStudent(10, 4, 2))
    result = studentAverage(studentList[1])
    assert result == 5.333
    assert studentIsEqualTo(studentList[1], 10, 4, 2)
    assert len(studentList) == 2

    studentList.append(createStudent(0, 0, 0))
    result = studentAverage(studentList[2])
    assert result == 0.0
    assert studentIsEqualTo(studentList[2], 0, 0, 0)
    assert len(studentList) == 3
示例#8
0
def testRemove():
    studentList = []

    studentList.append(createStudent(2, 2, 2))
    removePosition(0, studentList)
    assert len(studentList) == 1
    assert studentIsEqualTo(studentList[0], 0, 0, 0)

    studentList.append(createStudent(2, 2, 2))
    studentList.append(createStudent(3, 3, 3))
    studentList.append(createStudent(4, 4, 4))
    removeRange(1, 2, studentList)
    assert len(studentList) == 4
    assert studentIsEqualTo(studentList[0], 0, 0, 0)
    assert studentIsEqualTo(studentList[1], 0, 0, 0)
    assert studentIsEqualTo(studentList[2], 0, 0, 0)
    assert studentIsEqualTo(studentList[3], 4, 4, 4)

    removeAllWithProperty(2, 4.1, studentList)
    assert len(studentList) == 4
    assert studentIsEqualTo(studentList[0], 0, 0, 0)
    assert studentIsEqualTo(studentList[1], 0, 0, 0)
    assert studentIsEqualTo(studentList[2], 0, 0, 0)
    assert studentIsEqualTo(studentList[3], 0, 0, 0)
示例#9
0
def testMinRange():
    studentList = []

    studentList.append(createStudent(2, 3, 4))
    studentList.append(createStudent(8, 9, 10))
    studentList.append(createStudent(9, 9, 10))
    result = getMinimum(studentList, 0, 2)
    assert result == 3
    assert len(studentList) == 3
    assert studentIsEqualTo(studentList[0], 2, 3, 4)
    assert studentIsEqualTo(studentList[1], 8, 9, 10)
    assert studentIsEqualTo(studentList[2], 9, 9, 10)

    result = getMinimum(studentList, 1, 1)
    assert result == 9
    assert len(studentList) == 3
    assert studentIsEqualTo(studentList[0], 2, 3, 4)
    assert studentIsEqualTo(studentList[1], 8, 9, 10)
    assert studentIsEqualTo(studentList[2], 9, 9, 10)
示例#10
0
def testCreateStudent():
    s = createStudent(2, 3, 4)
    assert studentIsEqualTo(s, 2, 3, 4)

    s = createStudent(5, 6, 7)
    assert studentIsEqualTo(s, 5, 6, 7)