Issue #21916: Added more tests for the turtle module.

Original patch by Jelle Zijlstra.
This commit is contained in:
Serhiy Storchaka 2016-06-05 10:32:57 +03:00
parent ed0425c60a
commit 3c5fa560ed
1 changed files with 36 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import pickle
import unittest
from test import support
@ -129,6 +130,41 @@ class VectorComparisonMixin:
class TestVec2D(VectorComparisonMixin, unittest.TestCase):
def test_constructor(self):
vec = Vec2D(0.5, 2)
self.assertEqual(vec[0], 0.5)
self.assertEqual(vec[1], 2)
self.assertIsInstance(vec, Vec2D)
self.assertRaises(TypeError, Vec2D)
self.assertRaises(TypeError, Vec2D, 0)
self.assertRaises(TypeError, Vec2D, (0, 1))
self.assertRaises(TypeError, Vec2D, vec)
self.assertRaises(TypeError, Vec2D, 0, 1, 2)
def test_repr(self):
vec = Vec2D(0.567, 1.234)
self.assertEqual(repr(vec), '(0.57,1.23)')
def test_equality(self):
vec1 = Vec2D(0, 1)
vec2 = Vec2D(0.0, 1)
vec3 = Vec2D(42, 1)
self.assertEqual(vec1, vec2)
self.assertEqual(vec1, tuple(vec1))
self.assertEqual(tuple(vec1), vec1)
self.assertNotEqual(vec1, vec3)
self.assertNotEqual(vec2, vec3)
def test_pickling(self):
vec = Vec2D(0.5, 2)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
pickled = pickle.dumps(vec, protocol=proto)
unpickled = pickle.loads(pickled)
self.assertEqual(unpickled, vec)
self.assertIsInstance(unpickled, Vec2D)
def _assert_arithmetic_cases(self, test_cases, lambda_operator):
for test_case in test_cases:
with self.subTest(case=test_case):