MCPcopy Index your code
hub / github.com/RustPython/RustPython / testFloor

Method testFloor

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

Source from the content-addressed store, hash-verified

561 self.assertRaises(TypeError, math.factorial, 1e100)
562
563 def testFloor(self):
564 self.assertRaises(TypeError, math.floor)
565 self.assertEqual(int, type(math.floor(0.5)))
566 self.assertEqual(math.floor(0.5), 0)
567 self.assertEqual(math.floor(1.0), 1)
568 self.assertEqual(math.floor(1.5), 1)
569 self.assertEqual(math.floor(-0.5), -1)
570 self.assertEqual(math.floor(-1.0), -1)
571 self.assertEqual(math.floor(-1.5), -2)
572 #self.assertEqual(math.ceil(INF), INF)
573 #self.assertEqual(math.ceil(NINF), NINF)
574 #self.assertTrue(math.isnan(math.floor(NAN)))
575
576 class TestFloorIsNone(float):
577 __floor__ = None
578 class TestFloor:
579 def __floor__(self):
580 return 42
581 class FloatFloor(float):
582 def __floor__(self):
583 return 42
584 class TestNoFloor:
585 pass
586 class TestBadFloor:
587 __floor__ = BadDescr()
588 self.assertEqual(math.floor(TestFloor()), 42)
589 self.assertEqual(math.floor(FloatFloor()), 42)
590 self.assertEqual(math.floor(FloatLike(41.9)), 41)
591 self.assertRaises(TypeError, math.floor, TestNoFloor())
592 self.assertRaises(ValueError, math.floor, TestBadFloor())
593 self.assertRaises(TypeError, math.floor, TestFloorIsNone(3.5))
594
595 t = TestNoFloor()
596 t.__floor__ = lambda *args: args
597 self.assertRaises(TypeError, math.floor, t)
598 self.assertRaises(TypeError, math.floor, t, 0)
599
600 self.assertEqual(math.floor(FloatLike(+1.0)), +1.0)
601 self.assertEqual(math.floor(FloatLike(-1.0)), -1.0)
602
603 def testFmod(self):
604 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