Skip to main content

A helper to compare two numbers generously

Project description

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('@')) == '@...'

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for almost, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size almost-0.1.5.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page