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()
Exemple #2
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())
Exemple #3
0
def main():
    """reads from data file and creates course objects which are stored in
    the courselist class"""
    course_list = CourseList()
    with open("B:\\GitHub\\HomieRepo\\CS2420\\p3\\data.txt", 'r') as file:
        reader = csv.reader(file, delimiter=',')
        for data in reader:
            course = Course(data[0], data[1], data[2], data[3])
            course_list.insert(course)
Exemple #4
0
def main():
    """ Main driver to test CourseList and Course modules. """
    file = open("data.txt", "r")
    current_list = CourseList()
    for line in file:
        temp = line.split(",")
        current_list.insert(Course(int(temp[0]), str(temp[1]), float(temp[2]), float(temp[3])))
    file.close()

    print(current_list)
Exemple #5
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))
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)
Exemple #7
0
def main():
    CL = CourseList()
    file = open('data.txt', 'r')
    lines = file.readlines()
    for line in lines:
        data = line.split(',')
        class_number = int(data[0])
        class_name = str(data[1])
        class_credit_hrs = float(data[2])
        class_grade = float(data[3])

        C = Course(class_number, class_name, class_credit_hrs, class_grade)
        CL.insert(C)
    print(CL)
Exemple #8
0
def create_linked_list():
    '''reads from text file and creates linked list'''

    course_list = CourseList()

    file = open('data.txt', 'r')

    for line in file:
        line = line.rstrip()
        data = line.split(',')
        course = Course(int(data[0]), data[1], float(data[2]), float(data[3]))
        course_list.insert(course)

    return course_list
Exemple #9
0
def main():
    """
    main function driver for reading in file and then
    processing input.
    NOTE: I have my own test code commented out below
    """
    course_list = CourseList()
    file = open('data.txt', 'r')
    course_list = parser(file, course_list)
    file.close()
    print(str(course_list))
Exemple #10
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.
Exemple #11
0
 def test_remove_recursion(self):
     cl = CourseList()
     for i in range(1000, 1010):
         cl.insert(Course(i, "Test", 1.0, 1.0))
     RecursionCounter.recursion_count = 0
     cl.remove(1005)
     self.assertGreater(RecursionCounter.recursion_count, 4)
Exemple #12
0
 def test_sorted_recursion(self):
     cl = CourseList()
     for i in range(1000, 1010):
         cl.insert(Course(i, "Test", 1.0, 1.0))
     RecursionCounter.recursion_count = 0
     cl.is_sorted()
     self.assertGreater(RecursionCounter.recursion_count, 9)
Exemple #13
0
    def test_insert(self):
        random.seed(0)
        cl = CourseList()
        for i in range(37):
            cl.insert(Course(random.randrange(1000, 7000), "test", 1.0, 2.0))

        self.assertEqual(cl.size(), 37)
        self.assertTrue(cl.is_sorted())
def test_insert():
    random.seed(0)
    cl = CourseList()
    for _ in range(37):
        cl.insert(Course(random.randrange(1000, 7000), "test", 1.0, 2.0))

    assert cl.size() == 37
    assert cl.is_sorted()
Exemple #15
0
 def test_iterate_list(self):
     cl = CourseList()
     cl.insert(Course(1000))
     for _ in range(20):
         cl.insert(Course(1200))
     totalCourses = 0
     for _ in cl:
         totalCourses += 1
     self.assertEqual(totalCourses, 21)
def test_iterate_list():
    cl = CourseList()
    cl.insert(Course(1000, "", 0.0, 0.0))
    for _ in range(20):
        cl.insert(Course(1200, "", 0.0, 0.0))
    totalCourses = 0
    for _ in cl:
        totalCourses += 1
    assert totalCourses == 21
Exemple #17
0
def main():
    """Function that runs the the assignments for project 3"""
    # Reading in the data.txt file into a list of course objects
    course_lyst = []
    with open("data.txt", 'r') as file:
        for line in file:
            # List is created at top of each loop so linked list can be a nested list
            temp_lyst = []
            temp_lyst.append(line.split(','))
            for i in temp_lyst:
                temp_lyst = [j.replace('\n', '') for j in i]
            course = Course(int(temp_lyst[0]), temp_lyst[1], float(temp_lyst[2]), float(temp_lyst[3]))
            course_lyst.append(course)

    # Creating a linked list for course objects
    head = None
    for i in course_lyst:
        head = CourseList(i, head)
Exemple #18
0
def main():
    """main function"""
    f = open("data.txt", "r")
    line = f.readline()
    LinkedList = CourseList()

    while line:
        line = line.strip("\n").split(",")
        course = Course(int(line[0]), line[1], float(line[2]), float(line[3]))

        if LinkedList.head == None:
            LinkedList.head = course  # inserts head
        else:
            LinkedList.insert(course)  # inserts middle elements

        line = f.readline()
    f.close()

    LinkedList.__str__()
Exemple #19
0
 def test_remove_all(self):
     cl = CourseList()
     cl.insert(Course(1000))
     for _ in range(20):
         cl.insert(Course(1200))
     cl.insert(Course(1800))
     self.assertEqual(cl.size(), 22)
     cl.remove_all(1200)
     self.assertEqual(cl.size(), 2)
Exemple #20
0
    def test_remove(self):
        random.seed(0)
        cl = CourseList()
        courseNumbers = []
        for _ in range(37):
            courseNumbers.append(random.randrange(1000, 7000))
        for number in courseNumbers:
            cl.insert(Course(number, "test", 1.0, 2.0))

        course = cl.find(courseNumbers[0])
        self.assertEqual(course.number(), courseNumbers[0])
        course = cl.find(courseNumbers[10])
        self.assertEqual(course.number(), courseNumbers[10])
        course = cl.find(courseNumbers[36])
        self.assertEqual(course.number(), courseNumbers[36])

        for i in range(0, 30, 3):
            cl.remove(courseNumbers[i])

        self.assertEqual(cl.size(), 27)
        self.assertTrue(cl.is_sorted())
def test_remove():
    random.seed(0)
    cl = CourseList()
    courseNumbers = []
    for _ in range(37):
        courseNumbers.append(random.randrange(1000, 7000))
    for number in courseNumbers:
        cl.insert(Course(number, "test", 1.0, 2.0))

    course = cl.find(courseNumbers[0])
    assert course.number() == courseNumbers[0]
    course = cl.find(courseNumbers[10])
    assert course.number() == courseNumbers[10]
    course = cl.find(courseNumbers[36])
    assert course.number() == courseNumbers[36]

    for i in range(0, 30, 3):
        cl.remove(courseNumbers[i])

    assert cl.size() == 27
    assert cl.is_sorted()
Exemple #22
0
# Joey Rudek, @jrdek, jer5ae
# October 21, 2019

from courselist import CourseList

# line = '{"index":49,"crse_id":"006897","crse_offer_nbr":1,"strm":"1202","session_code":"SRT","session_descr":"Short Add","class_section":"001","location":"MAIN","location_descr":"On Grounds","start_dt":"01/13/2020","end_dt":"04/28/2020","class_stat":"A","campus":"MAIN","campus_descr":"Main Campus","class_nbr":15073,"acad_career":"UGRD","acad_career_descr":"Undergraduate","component":"LEC","subject":"CS","subject_descr":"Computer Science","catalog_nbr":"3102","class_type":"E","schedule_print":"Y","acad_group":"ENGR","instruction_mode":"P","instruction_mode_descr":"In Person","acad_org":"CS","wait_tot":0,"wait_cap":199,"class_capacity":200,"enrollment_total":0,"enrollment_available":200,"descr":"Theory of Computation","rqmnt_designtn":"","units":"3","combined_section":"N","enrl_stat":"O","enrl_stat_descr":"Open","topic":"","instructors":[{"name":"Nathan Brunelle","email":"*****@*****.**"}],"section_type":"Lecture","class_meeting_patterns":[{"class_mtg_nbr":1,"meeting_time_start":"15:30","meeting_time_end":"16:45","mon":"N","tues":"Y","wed":"N","thurs":"Y","fri":"N","sat":"N","sun":"N","start_dt":"01/13/2020","end_dt":"04/28/2020","stnd_mtg_pat":"TuTh","facility_id":"WIL 402","bldg_cd":"WIL","bldg_has_coordinates":true,"facility_descr":"Wilson Hall 402","room":"402","room_descr":"Wilson Hall 402"}],"crse_attr":"","crse_attr_value":"","reserve_caps":[]},'

# theoryOfComp = Course(line)

# print(theoryOfComp.subject, theoryOfComp.catalog_nbr+":", theoryOfComp.descr)

computer = CourseList("CS", "1202")
num = len(computer.courses)

print("There are", num, computer.mnemonic, "courses being offered in term", computer.term)

print("courses taught by Aaron Bloomfield:")
for c in computer.courses:
    for instr in c.instructors:
        if instr.name == "Aaron Bloomfield":
            print(c.subject, c.catalog_nbr+":", c.descr)
def test_remove_all():
    cl = CourseList()
    cl.insert(Course(1000, "", 0.0, 0.0))
    for _ in range(20):
        cl.insert(Course(1200, "", 0.0, 0.0))
    cl.insert(Course(1800, "", 0.0, 0.0))
    assert cl.size() == 22
    cl.remove_all(1200)
    assert cl.size() == 2