Skip to content

Instantly share code, notes, and snippets.

@jeffallen
Created February 1, 2024 18:52
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 jeffallen/1ae2b5b03dc9b28f17e622a5ee44645e to your computer and use it in GitHub Desktop.
Save jeffallen/1ae2b5b03dc9b28f17e622a5ee44645e to your computer and use it in GitHub Desktop.
import unittest
class TestPoint(unittest.TestCase):
def test_init(self):
"""Tests if the Point object is initialized correctly."""
p = Point(1, 2)
self.assertEqual(p.x, 1)
self.assertEqual(p.y, 2)
def test_distance_to(self):
"""Tests if the distance between two points is calculated correctly."""
p1 = Point(1, 2)
p2 = Point(3, 4)
expected_distance = 2.8284271247461903
distance = p1.distance_to(p2)
self.assertAlmostEqual(distance, expected_distance, places=7)
def test_str(self):
"""Tests if the string representation of the Point is correct."""
p = Point(5, 7)
expected_string = "(5, 7)"
self.assertEqual(str(p), expected_string)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment