Sometimes there is a situation when we want to check if the tested result is within the proper range.  An example of such a situation would be a function that returns the Pi number. Pi is an irrational number, which means it can’t be expressed as a simple fraction.  Because of that, we are not sure with what accuracy the result will be returned. The proper approach is to test whether the function result is within the given range. In the case of Pi, the range will be from 3.1415 to 3.1416. 

Firstly let's write a function like in the snipped below:

import math


def get_pi():
    return math.pi


To test get_pi function correctness we will just check if the result is in the range of 3.1415 to 3.1416. 

from sources.operations import get_pi


def test_get_pi():
    assert 3.1415 <= get_pi() <= 3.1416


Test passed. As expected, the get_pi function returns Pi value within a range from 3.1415 to 3.1416. 



The scientific work is published for the realization of the international project co-financed by Polish Ministry of Science and Higher Education in 2019 from financial resources of the program entitled "PMW"; Agreement No. 5040/H2020/Euratom/2019/2

This work has been carried out within the framework of the EUROfusion Consortium and has received funding from the Euratom research and training programme 2014–2020 under grant agreement No 633053. The views and opinions expressed herein do not necessarily reflect those of the European Commission or ITER