Skip to content

Commit c8b5bad

Browse files
committed
added quadratic test and solution
1 parent accfe70 commit c8b5bad

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Solutions/Session08/quadratic.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
quadratic function evaluator:
5+
6+
example of callable functions
7+
"""
8+
9+
10+
class Quadratic(object):
11+
"""
12+
class for evaluating the quadratic equation
13+
"""
14+
def __init__(self, a, b, c):
15+
self.a = a
16+
self.b = b
17+
self.c = c
18+
19+
def __call__(self, x):
20+
return (self.a * x**2) + (self.b * x) + self.c
21+
22+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
test code for the quadratic function evaluator
5+
"""
6+
7+
import pytest
8+
9+
from quadratic import Quadratic
10+
11+
12+
def test_init():
13+
q = Quadratic(1,2,3)
14+
15+
16+
def test_evaluate():
17+
q = Quadratic(1,2,3)
18+
19+
assert q(3) == 9 + 6 + 3
20+
21+
22+
def test_bad_input():
23+
24+
with pytest.raises(TypeError):
25+
q = Quadratic(2,3)
26+

0 commit comments

Comments
 (0)