1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
from __future__ import print_function, unicode_literals, absolute_import, division
EPSILON = 1e-8
REQUIRED = 1001001000
STRONG = 1000000
MEDIUM = 1000
WEAK = 1
def approx_equal(a, b, epsilon=EPSILON):
"A comparison mechanism for floats"
return abs(a - b) < epsilon
def repr_strength(strength):
"""Convert a numerical strength constant into a human-readable value.
We could wrap this up in an enum, but enums aren't available in Py2;
we could use a utility class, but we really don't need the extra
implementation weight. In practice, this repr is only used for debug
purposes during development.
"""
return {
REQUIRED: 'Required',
STRONG: 'Strong',
MEDIUM: 'Medium',
WEAK: 'Weak'
}[strength]
|