def test_should_return_float():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(50):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.cos(math.radians(degree * 10)), degree, degree + 1)

    assert isinstance(rel.get_correlation_coefficient(), float)
def test_should_show_perfect_association():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)

    assert rel.get_correlation_coefficient() == 1
def test_should_not_return_nan():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.sin(math.radians(degree * 100)), degree, degree + 1)

    assert not math.isnan(rel.get_correlation_coefficient())
def test_should_return_float_from_frame_db():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(180):
        var1.on_data(math.sin(math.radians(degree * 10)), degree, degree + 1)
        var2.on_data(math.cos(math.radians(degree * 10)), degree, degree + 1)

    assert isinstance(rel.get_value_between_times(0, 63), float)
def test_should_cause_frame_skip():
    if os.path.exists("spearframe.db"):
        os.remove("spearframe.db")
    var1 = Variable()
    var2 = Variable()
    rel = SpearframeRelationship(var1, var2)

    for degree in range(20):
        if degree > 15 and rel.current_iteration[rel.sensor_x.get_uuid()]:
            var1.on_data(None, degree, degree + 1)
            var2.on_data(math.cos(math.radians(degree * 10)), degree,
                         degree + 1)
            break
        else:
            var1.on_data(math.sin(math.radians(degree * 10)), degree,
                         degree + 1)
            var2.on_data(math.cos(math.radians(degree * 10)), degree,
                         degree + 1)

    assert not rel.current_iteration[rel.sensor_x.get_uuid()]