Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47e8438

Browse files
Create test.py
1 parent 7365bde commit 47e8438

File tree

1 file changed

+66
-0
lines changed
  • exercises/043-inheritance_and_polymorphism

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
from app import CollegeStudent
3+
4+
@pytest.mark.it("The CollegeStudent class should exist")
5+
def test_college_student_class_exists():
6+
try:
7+
assert CollegeStudent
8+
except AttributeError:
9+
raise AttributeError("The class 'CollegeStudent' should exist in app.py")
10+
11+
@pytest.mark.it("The CollegeStudent class includes the 'name' attribute")
12+
def test_college_student_has_name_attribute():
13+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
14+
assert hasattr(college_student, "name")
15+
16+
@pytest.mark.it("The CollegeStudent class includes the 'age' attribute")
17+
def test_college_student_has_age_attribute():
18+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
19+
assert hasattr(college_student, "age")
20+
21+
@pytest.mark.it("The CollegeStudent class includes the 'grade' attribute")
22+
def test_college_student_has_grade_attribute():
23+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
24+
assert hasattr(college_student, "grade")
25+
26+
@pytest.mark.it("The CollegeStudent class includes the 'major' attribute")
27+
def test_college_student_has_major_attribute():
28+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
29+
assert hasattr(college_student, "major")
30+
31+
@pytest.mark.it("The CollegeStudent class includes the 'introduce' method")
32+
def test_college_student_has_introduce_method():
33+
college_student = CollegeStudent("Alice", 22, 90, "Computer Science")
34+
assert hasattr(college_student, "introduce")
35+
36+
@pytest.mark.it("The CollegeStudent class includes the 'study' method")
37+
def test_college_student_has_study_method():
38+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
39+
assert hasattr(college_student, "study")
40+
41+
@pytest.mark.it("The CollegeStudent class includes the 'attend_lecture' method")
42+
def test_college_student_has_attend_lecture_method():
43+
college_student = CollegeStudent("John", 21, 75, "Computer Science")
44+
assert hasattr(college_student, "attend_lecture")
45+
46+
@pytest.mark.it("The introduce method should return the expected string. Testing with different values")
47+
def test_college_student_introduce_method_returns_expected_string():
48+
student1 = CollegeStudent("Alice", 22, 90, "Computer Science")
49+
student2 = CollegeStudent("Bob", 19, 85, "Mathematics")
50+
assert student1.introduce() == "Hi there! I'm Alice, a college student majoring in Computer Science."
51+
assert student2.introduce() == "Hi there! I'm Bob, a college student majoring in Mathematics."
52+
53+
@pytest.mark.it("The study method should return the expected string. Testing with different values")
54+
def test_college_student_study_method_returns_expected_string():
55+
student1 = CollegeStudent("Eve", 20, 78, "Physics")
56+
student2 = CollegeStudent("Charlie", 23, 88, "Chemistry")
57+
assert student1.study(3) == "Eve is studying for 3 hours."
58+
assert student2.study(2) == "Charlie is studying for 2 hours."
59+
60+
@pytest.mark.it("The attend_lecture method should return the expected string. Testing with different values")
61+
def test_college_student_attend_lecture_method_returns_expected_string():
62+
student1 = CollegeStudent("Eve", 20, 78, "Physics")
63+
student2 = CollegeStudent("Charlie", 23, 88, "Chemistry")
64+
assert student1.attend_lecture() == "Eve is attending a lecture for Physics students."
65+
assert student2.attend_lecture() == "Charlie is attending a lecture for Chemistry students."
66+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /