Beispiel #1
0
def test_layer2(init_value):
    intervals_to_add = [(-2, 1, 1), (3, 5, 2), (1, 5, -1), (-5, -3, 3)]
    int_seq = Stairs(initial_value=init_value)
    int_seq2 = Stairs(initial_value=init_value)
    for interval in intervals_to_add:
        int_seq.layer(*interval)
    starts, ends, values = list(zip(*intervals_to_add))
    int_seq2.layer(starts, ends, values)
    assert int_seq.identical(int_seq2)
    assert int_seq2.identical(int_seq)
Beispiel #2
0
def test_layer1(init_value):
    intervals_to_add = [(-2, 1), (3, 5), (1, 5), (-5, -3), (None, 0),
                        (0, None)]
    int_seq = Stairs(initial_value=init_value)
    int_seq2 = Stairs(initial_value=init_value)
    for start, end in intervals_to_add:
        int_seq.layer(start, end)
    starts, ends = list(zip(*intervals_to_add))
    starts = [{None: np.nan}.get(x, x) for x in starts]
    ends = [{None: np.nan}.get(x, x) for x in ends]
    int_seq2.layer(starts, ends)
    assert int_seq.identical(int_seq2)
    assert int_seq2.identical(int_seq)
Beispiel #3
0
def test_layering_index(s1_fix):
    result = Stairs(
        start=pd.Index([1, -4, 3, 6, 7]),
        end=pd.Index([10, 5, 5, 7, 10]),
        value=pd.Index([2, -1.75, 2.5, -2.5, -2.5]),
    )
    assert result.identical(s1_fix)
def test_le(s1_fix, s2_fix):
    calc = s1_fix <= s2_fix
    expected = Stairs(initial_value=1)
    expected.layer(1, 2, -1)
    expected.layer(2.5, 7, -1)
    assert calc.identical(expected), "LE calculation not what it should be"
    assert expected.identical(calc), "LE calculation not what it should be"
def test_gt(s1_fix, s2_fix):
    calc = s1_fix > s2_fix
    expected = Stairs(initial_value=0)
    expected.layer(1, 2)
    expected.layer(2.5, 7)
    assert calc.identical(expected), "GT calculation not what it should be"
    assert expected.identical(calc), "GT calculation not what it should be"
def test_eq_2(s1_fix, s2_fix):
    calc = s1_fix == s2_fix
    expected = Stairs(initial_value=1)
    expected.layer(-4, -2, -1)
    expected.layer(1, 10, -1)
    assert calc.identical(expected), "EQ calculation not what it should be"
    assert expected.identical(calc), "EQ calculation not what it should be"
Beispiel #7
0
def test_invert(s2_fix):
    int_seq = s2_fix
    calc = ~int_seq
    expected = Stairs(initial_value=1)
    expected.layer(-2, 7, -1)
    expected.layer(8, 10, -1)
    assert calc.identical(expected), "Invert calculation not what it should be"
    assert expected.identical(calc), "Invert calculation not what it should be"
Beispiel #8
0
def test_make_boolean(s2_fix):
    int_seq = s2_fix
    calc = int_seq.make_boolean()
    expected = Stairs()
    expected.layer(-2, 7, 1)
    expected.layer(8, 10, 1)
    assert calc.identical(expected), "Boolean calculation not what it should be"
    assert expected.identical(calc), "Boolean calculation not what it should be"
def test_ge(s1_fix, s2_fix):
    calc = s1_fix >= s2_fix
    expected = Stairs(initial_value=1)
    expected.layer(-4, -2, -1)
    expected.layer(2, 2.5, -1)
    expected.layer(7, 10, -1)
    assert calc.identical(expected), "GE calculation not what it should be"
    assert expected.identical(calc), "GE calculation not what it should be"
def test_lt(s1_fix, s2_fix):
    calc = s1_fix < s2_fix
    expected = Stairs(initial_value=0)
    expected.layer(-4, -2)
    expected.layer(2, 2.5)
    expected.layer(7, 10)
    assert calc.identical(expected), "LT calculation not what it should be"
    assert expected.identical(calc), "LT calculation not what it should be"
def test_ne(s1_fix, s2_fix):
    calc = s1_fix != s2_fix
    expected = Stairs(initial_value=0)
    expected.layer(-4, -2, 1)
    expected.layer(1, 10, 1)
    assert calc.identical(
        expected), "NOT EQUAL calculation not what it should be"
    assert expected.identical(
        calc), "NOT EQUAL calculation not what it should be"
Beispiel #12
0
def test_or(s3_fix, s4_fix):
    calc = s3_fix | s4_fix
    expected = Stairs(initial_value=0)
    expected.layer(-11, -7.5)
    expected.layer(-7, 0.5)
    expected.layer(1, 7)
    expected.layer(8.5, 9)
    expected.layer(9.5, 10)
    assert calc.identical(expected), "OR calculation not what it should be"
    assert expected.identical(calc), "OR calculation not what it should be"
Beispiel #13
0
def test_and(s3_fix, s4_fix):
    calc = s3_fix & s4_fix
    expected = Stairs(initial_value=0)
    expected.layer(-10, -9.5)
    expected.layer(-7, -5)
    expected.layer(-2, 0)
    expected.layer(3.5, 6)
    expected.layer(6.5, 7)
    assert calc.identical(expected), "AND calculation not what it should be"
    assert expected.identical(calc), "AND calculation not what it should be"