1
Midterm Exam E01 Handout
for
e01
CS8 S18

Example pytest test cases

import pytest

def fToC(fTemp):
   return fTemp - 32.0 # incorrect formula!

def cToF(cTemp):
   return cTemp + 32.0 # incorrect formula!

def test_fToC_freezing():
   assert fToC(32.0)==pytest.approx(0.0)

def test_cToF_freezing():
   assert cToF(0.0)==pytest.approx(32.0)

def test_fToC_boiling():
   assert fToC(212.0)==pytest.approx(100.0)

def test_cToF_boiling():
   assert cToF(100.0)==pytest.approx(212.0)
End of Handout