Example #1
0
 def test_best_rational_approximation(self):
     assert {'n': 1, 'd': 10} == utils.best_rational_approximation("0.1")
     assert {'n': 1, 'd': 100} == utils.best_rational_approximation("0.01")
     assert {
         'n': 1,
         'd': 1000
     } == utils.best_rational_approximation("0.001")
     assert {
         'n': 54301793,
         'd': 100000
     } == utils.best_rational_approximation("543.017930")
     assert {
         'n': 31969983,
         'd': 100000
     } == utils.best_rational_approximation("319.69983")
     assert {'n': 93, 'd': 100} == utils.best_rational_approximation("0.93")
     assert {'n': 1, 'd': 2} == utils.best_rational_approximation("0.5")
     assert {
         'n': 173,
         'd': 100
     } == utils.best_rational_approximation("1.730")
     assert {
         'n': 5333399,
         'd': 6250000
     } == utils.best_rational_approximation("0.85334384")
     assert {'n': 11, 'd': 2} == utils.best_rational_approximation("5.5")
     assert {
         'n': 272783,
         'd': 100000
     } == utils.best_rational_approximation("2.72783")
     assert {
         'n': 638082,
         'd': 1
     } == utils.best_rational_approximation("638082.0")
     assert {
         'n': 36731261,
         'd': 12500000
     } == utils.best_rational_approximation("2.93850088")
     assert {
         'n': 1451,
         'd': 25
     } == utils.best_rational_approximation("58.04")
     assert {
         'n': 8253,
         'd': 200
     } == utils.best_rational_approximation("41.265")
     assert {
         'n': 12869,
         'd': 2500
     } == utils.best_rational_approximation("5.1476")
     assert {
         'n': 4757,
         'd': 50
     } == utils.best_rational_approximation("95.14")
     assert {
         'n': 3729,
         'd': 5000
     } == utils.best_rational_approximation("0.74580")
     assert {
         'n': 4119,
         'd': 1
     } == utils.best_rational_approximation("4119.0")
     assert {
         'n': 1,
         'd': 100000000
     } == utils.best_rational_approximation("0.00000001")
     assert {
         'n': 1,
         'd': 1000000000
     } == utils.best_rational_approximation("0.000000001")
     assert {
         'n': 1,
         'd': 500000000
     } == utils.best_rational_approximation("0.000000002")
     assert {
         'n': 3,
         'd': 1000000000
     } == utils.best_rational_approximation("0.000000003")
     assert {
         'n': 2147483647,
         'd': 1
     } == utils.best_rational_approximation("2147483647")
Example #2
0
 def test_best_rational_approximation_not_found_denominator(self):
     with pytest.raises(Exception, match="Couldn't find approximation"):
         utils.best_rational_approximation("0.0000000003")
Example #3
0
 def test_best_rational_approximation_not_found_numerator(self):
     with pytest.raises(Exception, match="Couldn't find approximation"):
         utils.best_rational_approximation("2147483648")
Example #4
0
 def test_best_rational_approximation_not_found_numerator(self):
     utils.best_rational_approximation("2147483648")
Example #5
0
 def test_best_rational_approximation_not_found_denominator(self):
     utils.best_rational_approximation("0.0000000003")
 def test_best_rational_approximation_not_found_numerator(self):
     utils.best_rational_approximation("2147483648")
 def test_best_rational_approximation_not_found_denominator(self):
     utils.best_rational_approximation("0.0000000003")
 def test_best_rational_approximation(self):
     assert {'n': 1, 'd': 10} == utils.best_rational_approximation("0.1")
     assert {'n': 1, 'd': 100} == utils.best_rational_approximation("0.01")
     assert {'n': 1, 'd': 1000} == utils.best_rational_approximation("0.001")
     assert {'n': 54301793, 'd': 100000} == utils.best_rational_approximation("543.017930")
     assert {'n': 31969983, 'd': 100000} == utils.best_rational_approximation("319.69983")
     assert {'n': 93, 'd': 100} == utils.best_rational_approximation("0.93")
     assert {'n': 1, 'd': 2} == utils.best_rational_approximation("0.5")
     assert {'n': 173, 'd': 100} == utils.best_rational_approximation("1.730")
     assert {'n': 5333399, 'd': 6250000} == utils.best_rational_approximation("0.85334384")
     assert {'n': 11, 'd': 2} == utils.best_rational_approximation("5.5")
     assert {'n': 272783, 'd': 100000} == utils.best_rational_approximation("2.72783")
     assert {'n': 638082, 'd': 1} == utils.best_rational_approximation("638082.0")
     assert {'n': 36731261, 'd': 12500000} == utils.best_rational_approximation("2.93850088")
     assert {'n': 1451, 'd': 25} == utils.best_rational_approximation("58.04")
     assert {'n': 8253, 'd': 200} == utils.best_rational_approximation("41.265")
     assert {'n': 12869, 'd': 2500} == utils.best_rational_approximation("5.1476")
     assert {'n': 4757, 'd': 50} == utils.best_rational_approximation("95.14")
     assert {'n': 3729, 'd': 5000} == utils.best_rational_approximation("0.74580")
     assert {'n': 4119, 'd': 1} == utils.best_rational_approximation("4119.0")
     assert {'n': 1, 'd': 100000000} == utils.best_rational_approximation("0.00000001")
     assert {'n': 1, 'd': 1000000000} == utils.best_rational_approximation("0.000000001")
     assert {'n': 1, 'd': 500000000} == utils.best_rational_approximation("0.000000002")
     assert {'n': 3, 'd': 1000000000} == utils.best_rational_approximation("0.000000003")
     assert {'n': 2147483647, 'd': 1} == utils.best_rational_approximation("2147483647")