Ejemplo n.º 1
0
 def test_empty_courselist(self):
     cl = CourseList()
     self.assertIsNone(cl.head)
     self.assertEqual(cl.size(), 0)
     self.assertAlmostEqual(cl.calculate_gpa(), 0.0)
     self.assertAlmostEqual(cl.calculate_gpa(), 0.0)
     self.assertTrue(cl.is_sorted())
def test_empty_courselist():
    cl = CourseList()
    assert cl.head == None
    assert cl.size() == 0
    assert cl.calculate_gpa() == 0.0
    assert cl.calculate_gpa() == 0.0
    assert cl.is_sorted()
def test_gpa():
    random.seed(0)
    cl = CourseList()
    total_credits = 0.0
    total_grade_points = 0.0
    for _ in range(10):
        credits = random.uniform(1.0, 5.0)
        grade = random.uniform(0.0, 4.0)
        total_credits += credits
        total_grade_points += credits * grade
        cl.insert(Course(1234, "Test", credits, grade))

    assert math.isclose(cl.calculate_gpa(), total_grade_points / total_credits)
Ejemplo n.º 4
0
    def test_gpa(self):
        random.seed(0)
        cl = CourseList()
        total_credits = 0.0
        total_grade_points = 0.0
        for _ in range(10):
            credits = random.uniform(1.0, 5.0)
            grade = random.uniform(0.0, 4.0)
            total_credits += credits
            total_grade_points += credits * grade
            cl.insert(Course(1234, "Test", credits, grade))

        self.assertAlmostEqual(cl.calculate_gpa(), (total_grade_points / total_credits))
Ejemplo n.º 5
0
def main ():

    filePath = "data.txt" # path of file to access.
    file = open(filePath) # opens file.
    lines = len(file.readlines()) # accesses number of lines in data file.
    file = open(filePath) # reopens data file.
    number = 0 # temporary variable for class number.
    name = " " # temporary variable for class name.
    credit = 0 # temporary variable for credit hours.
    grade = 0.0 # temporary variable for grades.
    schedule = CourseList(None) # empty CourseList object.

    for x in range(lines - 1): # for loop parsing each line of data file.
        firstLine = file.readline()
        comma = firstLine.index(',')
        number = firstLine[0:comma] # accesses class number.
        firstLine = firstLine[comma + 1:len(firstLine)]
        comma = firstLine.index(',')
        name = firstLine[0:comma] # accesses class name.
        firstLine = firstLine[comma + 1:len(firstLine)]
        comma = firstLine.index(',')
        credit = firstLine[0:comma] # accesses credit hours.
        firstLine = firstLine[comma + 1:len(firstLine)]
        grade = firstLine # accesses grade.
        

        schedule.insert(Course(int(number), name, float(credit), float(grade), None)) # inserts a Course object into the CourseList object using parsed data.

    firstLine = file.readline() # repeats parsing process for last line of the data file.
    comma = firstLine.index(',')
    number = firstLine[0:comma]
    firstLine = firstLine[comma + 1:len(firstLine)]
    comma = firstLine.index(',')
    name = firstLine[0:comma]
    firstLine = firstLine[comma + 1:len(firstLine)]
    comma = firstLine.index(',')
    credit = firstLine[0:comma]
    firstLine = firstLine[comma + 1:len(firstLine)]
    grade = firstLine

    schedule.insert(Course(int(number), name, int(credit), float(grade), None)) # inserts last Course object.
    print("Current List: (", schedule.size(), ")") # prints out current CourseList object size.
    print("\n")


    print(schedule) # prints current CourseList with inserted courses.


    print("\n\n\n")
    print("Cumulative GPA: ", schedule.calculate_gpa()) # prints out cumulative GPA.