MCPcopy Index your code
hub / github.com/python/cpython / test_heading

Method test_heading

Lib/test/test_turtle.py:390–422  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

388 self.assertEqual(self.nav.towards(Vec2D(x, y)), expected)
389
390 def test_heading(self):
391
392 self.nav.left(90)
393 self.assertAlmostEqual(self.nav.heading(), 90)
394 self.nav.left(45)
395 self.assertAlmostEqual(self.nav.heading(), 135)
396 self.nav.right(1.6)
397 self.assertAlmostEqual(self.nav.heading(), 133.4)
398 self.assertRaises(TypeError, self.nav.right, 'sdkfjdsf')
399 self.nav.reset()
400
401 rotations = [10, 20, 170, 300]
402 result = sum(rotations) % 360
403 for num in rotations:
404 self.nav.left(num)
405 self.assertEqual(self.nav.heading(), result)
406 self.nav.reset()
407
408 result = (360-sum(rotations)) % 360
409 for num in rotations:
410 self.nav.right(num)
411 self.assertEqual(self.nav.heading(), result)
412 self.nav.reset()
413
414 rotations = [10, 20, -170, 300, -210, 34.3, -50.2, -10, -29.98, 500]
415 sum_so_far = 0
416 for num in rotations:
417 if num < 0:
418 self.nav.right(abs(num))
419 else:
420 self.nav.left(num)
421 sum_so_far += num
422 self.assertAlmostEqual(self.nav.heading(), sum_so_far % 360)
423
424 def test_setheading(self):
425 self.nav.setheading(102.32)

Callers

nothing calls this directly

Calls 8

absFunction · 0.85
leftMethod · 0.80
rightMethod · 0.80
assertAlmostEqualMethod · 0.45
headingMethod · 0.45
assertRaisesMethod · 0.45
resetMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected