Example #1
0
def test_logbin_float():
    # Everything less than 10 should be integers only.
    r = range(-10, 10+1)
    b = [log_bin(x, minlog=10) for x in r]
    [ assert_almost_equal(x, y) for x,y in zip(r, b) ]

    # Check that all bin widths are one
    r = range(-10, 9+1)  # 10 is different
    w = [log_bin_width(x, minlog=10) for x in r]
    #print r, w
    [ assert_almost_equal(1, y) for x,y in zip(r, w) ]

    # Long bin of 11 is no longer integer.
    assert_not_almost_equal(log_bin(11, minlog=10), 11)

    print 9.9, log_bin(9.9,minlog=10), log_bin_width(9.9,minlog=10)
    print 10 , log_bin(10, minlog=10), log_bin_width(10, minlog=10)
    print 11 , log_bin(11, minlog=10), log_bin_width(11, minlog=10)
    print 12 , log_bin(12, minlog=10), log_bin_width(12, minlog=10)
Example #2
0
def test_logbin_float():
    # Everything less than 10 should be integers only.
    r = range(-10, 10 + 1)
    b = [log_bin(x, minlog=10) for x in r]
    [assert_almost_equal(x, y) for x, y in zip(r, b)]

    # Check that all bin widths are one
    r = range(-10, 9 + 1)  # 10 is different
    w = [log_bin_width(x, minlog=10) for x in r]
    #print r, w
    [assert_almost_equal(1, y) for x, y in zip(r, w)]

    # Long bin of 11 is no longer integer.
    assert_not_almost_equal(log_bin(11, minlog=10), 11)

    print 9.9, log_bin(9.9, minlog=10), log_bin_width(9.9, minlog=10)
    print 10, log_bin(10, minlog=10), log_bin_width(10, minlog=10)
    print 11, log_bin(11, minlog=10), log_bin_width(11, minlog=10)
    print 12, log_bin(12, minlog=10), log_bin_width(12, minlog=10)
Example #3
0
def test_logbin_int():
    r = range(0, 1000)
    counts = {}
    for x in r:
        v = log_bin(x, minlog=10, ints=True)
        print x, v
        counts[v] = counts.get(v, 0) + 1
    for v, w in counts.iteritems():
        if v > 900: continue
        print v, w
        assert_equal(w, log_bin_width(v, minlog=10, ints=True))

    r = range(0, 1000)
    counts = {}
    for x in r:
        v = log_bin(x, minlog=1, ints=True)
        print x, v, 'xx'
        counts[v] = counts.get(v, 0) + 1
    for v, w in counts.iteritems():
        if v > 900: continue
        print v, w, 'xx'
        assert_equal(w, log_bin_width(v, minlog=1, ints=True))
Example #4
0
def test_logbin_int():
    r = range(0, 1000)
    counts = { }
    for x in r:
        v = log_bin(x, minlog=10, ints=True)
        print x, v
        counts[v] = counts.get(v, 0) + 1
    for v, w in counts.iteritems():
        if v > 900: continue
        print v, w
        assert_equal(w, log_bin_width(v, minlog=10, ints=True))


    r = range(0, 1000)
    counts = { }
    for x in r:
        v = log_bin(x, minlog=1, ints=True)
        print x, v, 'xx'
        counts[v] = counts.get(v, 0) + 1
    for v, w in counts.iteritems():
        if v > 900: continue
        print v, w, 'xx'
        assert_equal(w, log_bin_width(v, minlog=1, ints=True))