File: utils.py

package info (click to toggle)
python-ratelimitqueue 0.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: python: 463; makefile: 15
file content (21 lines) | stat: -rw-r--r-- 413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import math


def almost(a, b, threshold=0.05):
    """
    Test whether `a` and `b` within `threshold` of each other.

    Useful for timing related asserts where the timing is not 100%
    certain but should be close to a given number.

    Parameters
    ----------
    a: float
    b: float
    threshold: float (default 0.01)

    Returns
    -------
    bool
    """
    return math.fabs(a - b) < threshold