def within_margin(testvalue, mainvalue, margin):
    """
        returns true if and only if
        testvalue is within margin of mainvalue
    """
    return mainvalue - margin <= testvalue <= mainvalue + margin