Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

#!/usr/bin/env python 

 

class approx: 

 

    def __init__(self, expected, plus_or_minus=1e-5): 

        self.expected = expected 

        self.plus_or_minus = plus_or_minus 

 

    def __repr__(self): 

        return '{}±{}'.format(self.expected, self.plus_or_minus) 

 

    def __eq__(self, actual): 

        from collections import Iterable 

        expected = self.expected 

        eps = self.plus_or_minus 

 

        if isinstance(actual, Iterable) and isinstance(expected, Iterable): 

            return all(abs(a - x) < eps for a, x in zip(actual, expected)) 

        else: 

            return abs(actual - expected) < eps