慷慨地比较两个数字的助手
almost的Python项目详细描述
一个近似比较的辅助工具。
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('@')) == '@...'