Question
  • in python please I need both unittest and traditional test
  • Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram.
  • Input Files: students.txt  study-groups.txt
  • The study_group instance variable is a list that contains the username values of the other members in the student's study group.
  • Details:
    1. Implement the OnlineStudent class in the module onlinestudent.py as specified by the Student/OnlineStudent UML Diagram. OnlineStudent is the derived class of the base classStudent.
    2. The __lt__ method for an OnlineStudent object should return true if
      self.username < other.username
      
    3. The add_group_member method adds the username of a new study group member to the study_group instance member list.
    4. Write a traditional test class test1.py (different than your test1 script in Project 4a) that tests the additional instance members of the OnlineStudent class that are not in the Student class:
      __init__   __str__   __repr__   __lt__  
      
      email  study_group  add_group_member
      
      __init__, __str__, and __repr__ are tested again in the OnlineStudent class because they are overridden methods.
  • Convert your test1.py script to a unit test script test2.py.

students.txt

mcarter,Carter,Marilyn,312/473-4837,1,[email protected]
ggraber,Graber,Gary,312/837-2837,3,[email protected]
ccarpent,Carpenter,Carrie,312/377-2873,2,[email protected]
ccheng,Cheng,Sam,312/272-4473,1,[email protected]
obooker,Booker,Olivia,312/928-3980,4,[email protected]
rscanchez,Sanchez,Ricardo,312/838-9928,2,[email protected]
cdharan,Dharan,Connor,312/263-3922,2,[email protected]
yboulet,Boulet,Yvette,312/235-3728,3,[email protected]
rbolger,Bolger,Raymond,312/663-3827,4,[email protected]
sstrickl,Strickland,Sheryl,312/878-9800,1,[email protected]

study-groups.txt

ccarpent,yboulet,obooker
yboulet,ccarpent,obooker
obooker,ccarpent,yboulet
ccheng,cdharan,rbolger,ggraber
cdharan,rbolger,ggraber,ccheng
rbolger,ggraber,ccheng,cdharan
ggraber,ccheng,cdharan,rbolger
mcarter,sstrickl
sstrickl,mcarter

Student + last_name: str +first_name: str +phone str + year: int -init-(self: Student, i : int, last: str, first: str, ph : s

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Student:

    def __init__(self, i, last, first, ph, yr):
        self.username = i
        self.last_name = last
        self.first_name = first
        self.phone = ph
        self.year = yr

    def update_year(self):
        self.year += 1


class OnlineStudent(Student):
    """This class inherits from Student class"""

    def __init__(self, i, last, first, ph, year, em):
        """Call parent class constructor"""
        Student.__init__(self, i, last, first, ph, year)
        self.email = em
        # Initialize empty study group array
        self.study_group = []

    def __str__(self):
        return self.last_name + "," + self.first_name

    def __lt__(self, other):
        return self.username < other.username

    def add_group_member(self, member_id):
        # Add the member id to the study group
        self.study_group.append(member_id)

--------------------------------------------------------------------------------------------------------------------------------------

Test2.py

import unittest

import Student



class OnlineStudentTest(unittest.TestCase):
    def test_email(self):
        student = Student.OnlineStudent(1, 'last1', 'first1', 1, 1, "[email protected]")
        self.assertEqual("[email protected]", student.email, "Email not correct")

    def test_lt(self):
        student1 = Student.OnlineStudent(1, 'last1', 'first1', 1, 1, "[email protected]")
        student2 = Student.OnlineStudent(2, 'last2', 'first2', 1, 1, "[email protected]")
        self.assertTrue(student1.__lt__(student2), "Student 1 is less than 2")

    def test_str(self):
        student1 = Student.OnlineStudent(1, 'last1', 'first1', 1, 1, "[email protected]")
        self.assertEqual("last1,first1", student1.__str__(), "str function should gives all fields")

    def test_add_group_member(self):
        year = 1
        student = Student.OnlineStudent(1, 'last1', 'first1', 1, 1, "[email protected]")
        student.add_group_member("1")
        self.assertEqual("1", student.study_group[0], "Group member should be added")
Add a comment
Know the answer?
Add Answer to:
in python please I need both unittest and traditional test Goal: Implement and test the OnlineStudent class as shown in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python programming Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram....

    python programming Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram. Input Files: students.txt  study-groups.txt The study_group instance variable is a list that contains the username values of the other members in the student's study group. Details: Implement the OnlineStudent class in the module onlinestudent.py as specified by the Student/OnlineStudent UML Diagram. OnlineStudent is the derived class of the base classStudent. The __lt__ method for an OnlineStudent object should return true if self.username < other.username...

  • this is written in python Goal: Implement and test the Onlinestudent class as shown in the Student/OnlineStudent UML Dia...

    this is written in python Goal: Implement and test the Onlinestudent class as shown in the Student/OnlineStudent UML Diagram Relevant Examples: EmployeeHierarchy PersonArray Pet Input Files: students.txt study-groups.txt The study_group instance variable is a list that contains the username values of the other members in the student's study group Details: 1. Implement the onlinestudent class in the module onlinestudent.py as specified by the Student/OnlineStudent UML Diagram. Onlinestudent is the derived class of the base class student. 2. The_1t__method for an...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT