skip to navigation
skip to content

Not Logged In

almost 0.1.5

A helper to compare two numbers generously

A helper for approximate comparison.

from almost import almost

def test_repeating_decimal():
    assert almost(1 / 3.) == 0.333
    assert almost(1 / 6.) == 0.167
    assert almost(3227 / 555., precision=6) == 5.814414

def test_irrational_number():
    import math
    assert almost(math.pi) == 3.142
    assert almost(math.sqrt(2)) == 1.414

def test_random_text():
    import random
    def gen_text_with_prefix(prefix):
        return prefix + str(random.random())[:-5]
    assert almost(gen_text_with_prefix('@')) == '@...'
 
File Type Py Version Uploaded on Size
almost-0.1.5.tar.gz (md5) Source 2013-03-06 3KB
  • Downloads (All Versions):
  • 99 downloads in the last day
  • 399 downloads in the last week
  • 1510 downloads in the last month