Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created October 3, 2019 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/f00896c53ec36dac9ce82ab33c26a4e2 to your computer and use it in GitHub Desktop.
Save jasongorman/f00896c53ec36dac9ce82ab33c26a4e2 to your computer and use it in GitHub Desktop.
import unittest
from maths import sqrt
class SqrtTest(unittest.TestCase):
def test_sqrt_0(self):
self.assertEqual(0.0, sqrt(0.0))
def test_sqrt_minus1(self):
self.assertRaisesRegex(Exception,
'Input to sqrt must be a positive number',
lambda: sqrt(-1))
def test_sqrt_1(self):
self.assertEqual(1.0, sqrt(1))
def test_sqrt_4(self):
self.assertEqual(2.0, sqrt(4.0))
def test_sqrt_6point25(self):
self.assertEqual(2.5, sqrt(6.25))
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment