Esempio n. 1
0
 def test_numbers_with_e(self):
     for input, expected in [([1e20, 1e21, 2e20], [1e20, 3e20, 5e20, 7e20, 9e20]),
                             ([1e-21, 1.1e-20, 3e-21], [1e-21, 4e-21, 7e-21, 1e-20]),
                             ([1.1e-20, 1.1e-21, -5e-21], [1.1e-20, 6e-21])]:
         result = frange(*input)
         assert_equal(len(result), len(expected))
         # Floats are not accurate and values depend on Python versions
         diffs = [round(r-e, 30) for r, e in zip(result, expected)]
         assert_equal(sum(diffs), 0)
Esempio n. 2
0
 def test_basics(self):
     for input, expected in [([6.0], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]),
                             ([6.01], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]),
                             ([-2.4, 2.1], [-2.4, -1.4, -0.4, 0.6, 1.6]),
                             ([0, 0.5, 0.1], [0, 0.1, 0.2, 0.3, 0.4])]:
         assert_equal(frange(*input), expected)
Esempio n. 3
0
 def test_preserve_type(self):
     for input in [(2,), (0, 2), (0, 2, 1)]:
         assert_true(all(isinstance(item, int) for item in frange(*input)))
     for input in [(2.0,), (0, 2.0), (0.0, 2), (0, 2, 1.0), (0, 2.0, 1)]:
         assert_true(all(isinstance(item, float) for item in frange(*input)))
Esempio n. 4
0
 def test_compatibility_with_range(self):
     for input in [(10,), (-10,), (1, 10), (1, 10, 2), (10, -5, -2)]:
         assert_equal(frange(*input), list(range(*input)))
         assert_equal(frange(*(float(i) for i in input)), list(range(*input)))