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

Method testFloor

Lib/test/test_math.py:518–556  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

516 self.ftest('fabs(1)', math.fabs(1), 1)
517
518 def testFloor(self):
519 self.assertRaises(TypeError, math.floor)
520 self.assertEqual(int, type(math.floor(0.5)))
521 self.assertEqual(math.floor(0.5), 0)
522 self.assertEqual(math.floor(1.0), 1)
523 self.assertEqual(math.floor(1.5), 1)
524 self.assertEqual(math.floor(-0.5), -1)
525 self.assertEqual(math.floor(-1.0), -1)
526 self.assertEqual(math.floor(-1.5), -2)
527 #self.assertEqual(math.ceil(INF), INF)
528 #self.assertEqual(math.ceil(NINF), NINF)
529 #self.assertTrue(math.isnan(math.floor(NAN)))
530
531 class TestFloorIsNone(float):
532 __floor__ = None
533 class TestFloor:
534 def __floor__(self):
535 return 42
536 class FloatFloor(float):
537 def __floor__(self):
538 return 42
539 class TestNoFloor:
540 pass
541 class TestBadFloor:
542 __floor__ = BadDescr()
543 self.assertEqual(math.floor(TestFloor()), 42)
544 self.assertEqual(math.floor(FloatFloor()), 42)
545 self.assertEqual(math.floor(FloatLike(41.9)), 41)
546 self.assertRaises(TypeError, math.floor, TestNoFloor())
547 self.assertRaises(ValueError, math.floor, TestBadFloor())
548 self.assertRaises(TypeError, math.floor, TestFloorIsNone(3.5))
549
550 t = TestNoFloor()
551 t.__floor__ = lambda *args: args
552 self.assertRaises(TypeError, math.floor, t)
553 self.assertRaises(TypeError, math.floor, t, 0)
554
555 self.assertEqual(math.floor(FloatLike(+1.0)), +1.0)
556 self.assertEqual(math.floor(FloatLike(-1.0)), -1.0)
557
558 def testFmod(self):
559 self.assertRaises(TypeError, math.fmod)

Callers

nothing calls this directly

Calls 8

TestFloorClass · 0.85
FloatFloorClass · 0.85
TestNoFloorClass · 0.85
TestBadFloorClass · 0.85
TestFloorIsNoneClass · 0.85
FloatLikeClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected