Test Setup Failed
Push — master ( af1115...273b78 )
by Ken M.
57s
created

almost_equal()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 2
b 0
f 0
1
def checkio(*args):
2
    if args:
3
        result = max(args) - min(args)
4
        if isinstance(result, int):
5
            return result
6
        else:
7
            return round(result, 3)
8
    else:
9
        return 0
10
11
12
# These "asserts" using only for self-checking and not necessary for
13
# auto-testing
14
if __name__ == '__main__':  # pragma: no cover
15
    def almost_equal(checked, correct, significant_digits):
16
        precision = 0.1 ** significant_digits
17
        return correct - precision < checked < correct + precision
18
19
    assert almost_equal(checkio(1, 2, 3), 2, 3), "3-1=2"
20
    assert almost_equal(checkio(5, -5), 10, 3), "5-(-5)=10"
21
    assert almost_equal(
22
        checkio(10.2, -2.2, 0, 1.1, 0.5), 12.4, 3), "10.2-(-2.2)=12.4"
23
    assert almost_equal(checkio(), 0, 3), "Empty"
24