Skip to content

Commit 1d7bcbd

Browse files
authored
Create test.py
1 parent 1fa3ff1 commit 1d7bcbd

File tree

1 file changed

+48
-0
lines changed
  • exercises/042-understanding_classes

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pytest
2+
from app import Student
3+
4+
@pytest.mark.it("The Student class should exist")
5+
def test_student_class_exists():
6+
try:
7+
assert Student
8+
except AttributeError:
9+
raise AttributeError("The class 'Student' should exist in app.py")
10+
11+
@pytest.mark.it("The Student class includes the 'name' attribute")
12+
def test_student_has_name_attribute():
13+
student = Student("John", 21, 75)
14+
assert hasattr(student, "name")
15+
16+
@pytest.mark.it("The Student class includes the 'age' attribute")
17+
def test_student_has_age_attribute():
18+
student = Student("John", 21, 75)
19+
assert hasattr(student, "age")
20+
21+
@pytest.mark.it("The Student class includes the 'grade' attribute")
22+
def test_student_has_grade_attribute():
23+
student = Student("John", 21, 75)
24+
assert hasattr(student, "grade")
25+
26+
@pytest.mark.it("The Student class includes the 'introduce' method")
27+
def test_student_has_introduce_method():
28+
student = Student("Alice", 22, 90)
29+
assert hasattr(student, "introduce")
30+
31+
@pytest.mark.it("The introduce method should return the expected string. Testing with different values")
32+
def test_student_introduce_method_returns_expected_string():
33+
student1 = Student("Alice", 22, 90)
34+
student2 = Student("Bob", 19, 85)
35+
assert student1.introduce() == "Hello! I am Alice, I am 22 years old, and my current grade is 90"
36+
assert student2.introduce() == "Hello! I am Bob, I am 19 years old, and my current grade is 85"
37+
38+
@pytest.mark.it("The Student class includes the 'study' method")
39+
def test_student_has_study_method():
40+
student = Student("John", 21, 75)
41+
assert hasattr(student, "study")
42+
43+
@pytest.mark.it("The study method should return the expected string. Testing with different values")
44+
def test_student_study_method_returns_expected_string():
45+
student1 = Student("Eve", 20, 78)
46+
student2 = Student("Charlie", 23, 88)
47+
assert student1.study(3) == "After studying for 3 hours, Eve's new grade is 79.5."
48+
assert student2.study(2) == "After studying for 2 hours, Charlie's new grade is 89.0."

0 commit comments

Comments
 (0)