@@ -0,0 +1,1056 @@
+from __future__ import division%0A%0Afrom nose.tools import *%0A%0Afrom fractions import Fraction%0Afrom ..fraction import *%0A%0Adef test_fraction():%0A    %22%22%22Smoke tests to convert float to fraction.%22%22%22%0A    numerators = range(10)%0A    denominator = 10%0A    xvals = %5Bx / denominator for x in numerators%5D%0A    af = lambda x: approximate_fraction(x, .01)%0A    yvals = map(af, xvals)%0A    yvals_ = map(lambda x: Fraction(x, denominator), numerators)%0A    for y, y_ in zip(yvals, yvals_):%0A        assert_equal(y, y_)%0A%0A    # Negative values%0A    af = lambda x: approximate_fraction(-x, .01)%0A    yvals = map(af, xvals)%0A    yvals_ = map(lambda x: Fraction(-x, denominator), numerators)%0A    for y, y_ in zip(yvals, yvals_):%0A        assert_equal(y, y_)%0A%0Adef test_fraction_zero():%0A    %22%22%22Convert float to fraction when closer to 0.%22%22%22%0A    x = .1%0A    y = approximate_fraction(x, .2)%0A    y_ = Fraction(0, 1)%0A    assert_equal(y, y_)%0A    y = approximate_fraction(-x, .2)%0A    assert_equal(y, -y_)%0A%0Adef test_fraction_emptyinterval():%0A    assert_raises(ValueError, approximate_fraction, 0.1, 0)%0A

Add some unit tests for approximate fractions.