Created
February 1, 2024 18:52
-
-
Save jeffallen/1ae2b5b03dc9b28f17e622a5ee44645e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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