def test_exercise_example_4():
    x1 = [1, 2, 2, 3, 1]
    x2 = [1, 3, 2, 2, 1]
    x3 = [3, 2, 2, 3]
    result1 = find_maxima(x1)
    result2 = find_maxima(x2)
    result3 = find_maxima(x3)
    correct_results1 = [1, 3]
    correct_results2 = [1, 3]
    correct_results3 = [0, 3]
    assert result1 == correct_results1
    assert result2 == correct_results2
    assert result3 == correct_results3
def test_more_sequences():
    x = [4, 2, 1, 3, 1, 2]
    out = find_maxima(x)
    exp = [0, 3, 5]
    assert exp == out

    x = [4, 2, 1, 3, 1, 5]
    out = find_maxima(x)
    exp = [0, 3, 5]
    assert exp == out

    x = [4, 2, 1, 3, 1]
    out = find_maxima(x)
    exp = [0, 3]
    assert exp == out
def test_exercise_example_1():
    x = [0, 1, 2, 1, 2, 1, 0]
    result = find_maxima(x)
    correct_results = [2, 4]
    assert result == correct_results
    print(result)
    print(correct_results)
def test_exercise_example_3():
    x = [np.sin(2 * alpha) for alpha in np.linspace(0.0, 5.0, 100)]
    # x =
    result = find_maxima(x)
    print(result)
    correct_results = [78]
    assert result == correct_results
Beispiel #5
0
def test_exercise_example_8():

    x = [3, 2, 2, 3]
    result = find_maxima(x)
    correct_results = [0, 3]
    print(result)
    assert result == correct_results
Beispiel #6
0
def test_exercise_example_6():

    x = [1, 2, 2, 3, 1]
    result = find_maxima(x)
    correct_results = [1, 3]
    print(result)
    assert result == correct_results
Beispiel #7
0
def test_exercise_example_3():

    x = [4, 2, 1, 3, 1, 5]

    result = find_maxima(x)
    correct_results = [0, 3, 5]
    assert result == correct_results
def test_randomized():
    seedval = pytest.config.getoption('seed')
    if seedval is None:
        seedval = np.random.randint(2**32)
    print()
    print(f'seedval: {seedval}')

    # given
    rand_gen = np.random.RandomState(seed=seedval)
    numel = rand_gen.randint(0, 1000)
    print(f'numel: {numel}')

    test_vec = rand_gen.random_integers(low=1, high=20, size=numel)
    print(f'test_vec: {test_vec}')

    # when
    out      = find_maxima(test_vec)

    # then
    numMax = len(out)
    for i in range(0,numMax):
        iE = out[i]
        if iE == 0:
            assert test_vec[0] >= test_vec[1]
        elif iE == numel - 1:
            assert test_vec[numel-1] >= test_vec[numel-2]
        else:
            assert test_vec[iE-1] <= test_vec[iE] and test_vec[iE+1] <= test_vec[iE]
Beispiel #9
0
def test_equality():
    case_res = [([1, 2, 2, 1, 1], [2]),
                ([1, 2, 2, 3, 1], [3]),
                ([1, 3, 2, 2, 1], [1]),
                ([3, 2, 2, 2, 3], [0, 4])]
    for x, desired in case_res:
        idx = find_maxima(x)
        assert idx == desired
Beispiel #10
0
 def test_last_index(self):
     #Given
     x = [4, 2, 1, 3, 1, 2]
     expected_ind = [0, 3, 5]
     #When
     returned_ind = find_maxima(x)
     #Then
     self.assertEqual(expected_ind, returned_ind)
Beispiel #11
0
def test_exercise_example_1():
    #x = [0, 1, 2, 1, 2, 1, 0]
    #x = [-i**2 for i in range(-3, 4)]
    x = [np.sin(2 * alpha) for alpha in np.linspace(0.0, 5.0, 100)]
    #x = [1,2,3,4]
    pdb.set_trace()
    result = find_maxima(x)
    #correct_results = [2, 4]
    #correct_results = [3]
    correct_results = [16, 78]
    assert result == correct_results  #, "no correct maxima found"
Beispiel #12
0
def test_trick():
    x = [1, 2, 2, 1]
    out = find_maxima(x)
    exp = [1]
    assert exp == out

    x = [1, 2, 2, 3, 1]
    out = find_maxima(x)
    exp = [1, 3]
    assert exp == out

    x = [1, 3, 2, 2, 1]
    out = find_maxima(x)
    exp = [1]
    assert exp == out

    x = [3, 2, 2, 3]
    out = find_maxima(x)
    exp = [0, 3]
    assert exp == out
Beispiel #13
0
def test_exercise_example_1():
    #x = [0, 1, 2, 1, 2, 1, 0]
    #x = [-i**2 for i in range(-3, 4)]
    x = [np.sin(2 * alpha) for alpha in np.linspace(0.0, 5.0, 100)]
    result = find_maxima(x)
    #correct_results = [2, 4]
    #correct_results = [3]
    correct_results = [78]

    assert result == correct_results
    print(result)
Beispiel #14
0
def test_maxima():
    test1=find_maxima(x1)
    if test1==[2,4]:
        print("test_1 passed")
    else:
        print("test_1 failed")

    test2=find_maxima(x2)
    if test2==[3]:
        print("test_2 passed")
    else:
        print("test_2 failed")

    test3=find_maxima(x3)
    if test3==[16,78]:
        print("test_3 passed")
    else:
        print("test_3 failed")

    test4=find_maxima(x4)
    if test4==[0]:
        print("test_4 passed")
    else:
        print("test_4 failed")
Beispiel #15
0
def test_check_input():
    with raises(ValueError):
        find_maxima(2)
Beispiel #16
0
def test_max_on_both_borders():
    inp = [4, 2, 1, 3, 1, 2]
    out = find_maxima(inp)
    exp = [0, 3, 5]
Beispiel #17
0
def test_short_sequence():
    x = [1,2,3]
    out = find_maxima(x)
    exp = [2]
    assert exp == out
Beispiel #18
0
def test_neighbors5():
    x = [3, 2, 2, 1, 2]
    out = find_maxima(x)
    exp = [0, 4]
    assert exp == out
Beispiel #19
0
def test_1():
    exp = [2,4]
    x = [1,2,3,2,4,3]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
Beispiel #20
0
def test_first_element():
    x = [3, 1, 4]
    idx = find_maxima(x)
    assert idx == [0, 2]
Beispiel #21
0
def test_11():
    x = [1, 3, 2, 2, 1]
    exp = [1]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
 def test_first_element(self):
     x = [3, 1, 4]
     idx = find_maxima(x)
     self.assertEqual(idx, [0, 2])
Beispiel #23
0
def test_shorter_sequence3():
    exp = [0, 3]
    x = [3, 2, 2, 3]
    out = find_maxima(x)
    assert exp == out, "returns " + str(out) + " instead of " + str(exp)
Beispiel #24
0
def test_shorter_sequence2():
    exp = [0, 3, 5]
    x = [4, 2, 1, 3, 1, 5]
    out = find_maxima(x)
    assert exp == out, "returns " + str(out) + " instead of " + str(exp)
Beispiel #25
0
def test_exercise_02():
    
    x = [-i**2 for i in range(-3, 4)]
    out = find_maxima(x)
    exp = [3]
    assert exp == out
Beispiel #26
0
def test_exercise_01():
    
    x = [0, 1, 2, 1, 2, 1, 0]
    out = find_maxima(x)
    exp = [2, 4]
    assert exp == out
Beispiel #27
0
def test_2():
    x = [1,2,3]
    exp = [2]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
Beispiel #28
0
def test_14():
    x = [1,1,1,3,2,4,4]
    exp = [3,6]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
 def test_last_element(self):
     x = [1, 2]
     idx = find_maxima(x)
     self.assertEqual(idx, [1])
Beispiel #30
0
def test1():
    lista = [1, 2, 1]
    resultado_esperado = [1]
    resultado = find_maxima(lista)
    assert resultado == resultado_esperado
 def test_equality(self):
     case_res = [([1, 2, 2, 1, 1], [2]), ([1, 2, 2, 3, 1], [3]),
                 ([1, 3, 2, 2, 1], [1]), ([3, 2, 2, 2, 3], [0, 4])]
     for x, desired in case_res:
         idx = find_maxima(x)
         self.assertEqual(idx, desired)
Beispiel #32
0
def test_8():
    x = [4, 2, 1, 3, 1]
    exp = [0, 3]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
Beispiel #33
0
def test3():
    lista = [1, 2, 3]
    resultado_esperado = [2]
    resultado = find_maxima(lista)
    assert resultado == resultado_esperado
Beispiel #34
0
def test_neighbors2():
    x = [1, 2, 2, 3, 1]
    out = find_maxima(x)
    exp = [3]
    assert exp == out
Beispiel #35
0
def test_exercise_example_1():
    x = [1, 2, 2, 1]
    result = find_maxima(x)
    correct_results = [1, 2]
    assert result == correct_results, "Incorrect result"
Beispiel #36
0
def test_neighbors3():
    x = [3, 2, 2, 3]
    out = find_maxima(x)
    exp = [0, 3]
    assert exp == out
Beispiel #37
0
def test_simple_sequence():
    exp = [2, 4]
    x = [1, 2, 3, 2, 4, 3]
    out = find_maxima(x)
    assert exp == out, "returns " + str(out) + " instead of " + str(exp)
Beispiel #38
0
def test_5():
    x = [np.sin(2*alpha) for alpha in np.linspace(0.0, 5.0, 100)]
    exp = [16, 78]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
Beispiel #39
0
def test_last_element():
    x = [1, 2]
    idx = find_maxima(x)
    assert idx == [1]
Beispiel #40
0
def test_shorter_sequence6():
    exp = [2, 4]
    x = [0, 1, 2, 1, 2, 1, 0]
    out = find_maxima(x)
    assert exp == out, "returns " + str(out) + " instead of " + str(exp)
Beispiel #41
0
def test_exercise_example_2():
    x = [-i**2 for i in range(-3, 4)]
    # x = [-9, -4, -1, 0, -1, -4, -9]
    result = find_maxima(x)
    correct_results = [3]
    assert result == correct_results
Beispiel #42
0
def test_shorter_sequence7():
    exp = [2]
    x = [1, 2, 2, 1]
    out = find_maxima(x)
    assert exp == out, "returns " + str(out) + " instead of " + str(exp)
Beispiel #43
0
def test_maxima():
    inputs = [[1, 2, 1, 0], [-1, 2, 1, 3, 2], [4, 3, 4, 3], [1, 2, 3]]
    expected_maxima = [[1], [1, 3], [0, 2], [2]]
    for i in range(len(inputs)):
        assert find_maxima(inputs[i]) == expected_maxima[i]
Beispiel #44
0
def test_max_on_both_borders_global_maxima_right():
    inp = [4, 2, 1, 3, 1, 5]
    out = find_maxima(inp)
    exp = [0, 3, 5]
    assert exp == out
Beispiel #45
0
def test_simple_sequence():
    exp = [2,4]
    x = [1, 2, 3, 2, 4, 3]
    out = find_maxima(x)
    assert exp == out
Beispiel #46
0
def test_max_on_lower_border():
    inp = [4, 2, 1, 3, 1]
    out = find_maxima(inp)
    exp = [0, 3]
    assert exp == out
Beispiel #47
0
def test_neighbors4():
    x = [1, 3, 2, 2, 1]
    out = find_maxima(x)
    exp = [1]
    assert exp == out
Beispiel #48
0
def test_max_with_plateau():
    inp = [1, 2, 2, 1]
    out = find_maxima(inp)
    exp = [1, 2]
    assert exp == out
Beispiel #49
0
def test_equal_beginning():
    x = [2, 2, 1, 2]
    out = find_maxima(x)
    exp = [0, 4]
    assert exp == out
Beispiel #50
0
def test_max_with_saddel():
    inp = [1, 2, 2, 3, 1]
    out = find_maxima(inp)
    exp = [3]
    assert exp == out
Beispiel #51
0
def test_simple_sequence_one_maxima():
    inp = [-i**2 for i in range(-3, 4)]
    out = find_maxima(inp)
    exp = [3]
    assert exp == out
Beispiel #52
0
def test_max_with_reverse_saddel():
    inp = [1, 3, 2, 2, 1]
    out = find_maxima(inp)
    exp = [1]
    assert exp == out
Beispiel #53
0
def test_simple_sequence_two_maxima():
    inp = [0, 1, 2, 1, 2, 1, 0]
    out = find_maxima(inp)
    exp = [2, 4]
    assert exp == out
Beispiel #54
0
def test_max_with_valley():
    inp = [3, 2, 2, 3]
    out = find_maxima(inp)
    exp = [0, 3]
    assert exp == out