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
def test_exercise_example_8():

    x = [3, 2, 2, 3]
    result = find_maxima(x)
    correct_results = [0, 3]
    print(result)
    assert result == correct_results
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
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]
Exemple #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
Exemple #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)
Exemple #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"
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
Exemple #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)
Exemple #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")
Exemple #15
0
def test_check_input():
    with raises(ValueError):
        find_maxima(2)
def test_max_on_both_borders():
    inp = [4, 2, 1, 3, 1, 2]
    out = find_maxima(inp)
    exp = [0, 3, 5]
def test_short_sequence():
    x = [1,2,3]
    out = find_maxima(x)
    exp = [2]
    assert exp == out
def test_neighbors5():
    x = [3, 2, 2, 1, 2]
    out = find_maxima(x)
    exp = [0, 4]
    assert exp == out
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)
Exemple #20
0
def test_first_element():
    x = [3, 1, 4]
    idx = find_maxima(x)
    assert idx == [0, 2]
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])
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)
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)
def test_exercise_02():
    
    x = [-i**2 for i in range(-3, 4)]
    out = find_maxima(x)
    exp = [3]
    assert exp == out
def test_exercise_01():
    
    x = [0, 1, 2, 1, 2, 1, 0]
    out = find_maxima(x)
    exp = [2, 4]
    assert exp == out
def test_2():
    x = [1,2,3]
    exp = [2]
    out = find_maxima(x)
    assert out == exp, 'expected {}, but got {}'.format(exp, out)
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])
Exemple #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)
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)
Exemple #33
0
def test3():
    lista = [1, 2, 3]
    resultado_esperado = [2]
    resultado = find_maxima(lista)
    assert resultado == resultado_esperado
def test_neighbors2():
    x = [1, 2, 2, 3, 1]
    out = find_maxima(x)
    exp = [3]
    assert exp == out
def test_exercise_example_1():
    x = [1, 2, 2, 1]
    result = find_maxima(x)
    correct_results = [1, 2]
    assert result == correct_results, "Incorrect result"
def test_neighbors3():
    x = [3, 2, 2, 3]
    out = find_maxima(x)
    exp = [0, 3]
    assert exp == out
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)
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)
Exemple #39
0
def test_last_element():
    x = [1, 2]
    idx = find_maxima(x)
    assert idx == [1]
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)
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
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)
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]
Exemple #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
def test_simple_sequence():
    exp = [2,4]
    x = [1, 2, 3, 2, 4, 3]
    out = find_maxima(x)
    assert exp == out
Exemple #46
0
def test_max_on_lower_border():
    inp = [4, 2, 1, 3, 1]
    out = find_maxima(inp)
    exp = [0, 3]
    assert exp == out
def test_neighbors4():
    x = [1, 3, 2, 2, 1]
    out = find_maxima(x)
    exp = [1]
    assert exp == out
Exemple #48
0
def test_max_with_plateau():
    inp = [1, 2, 2, 1]
    out = find_maxima(inp)
    exp = [1, 2]
    assert exp == out
def test_equal_beginning():
    x = [2, 2, 1, 2]
    out = find_maxima(x)
    exp = [0, 4]
    assert exp == out
Exemple #50
0
def test_max_with_saddel():
    inp = [1, 2, 2, 3, 1]
    out = find_maxima(inp)
    exp = [3]
    assert exp == out
def test_simple_sequence_one_maxima():
    inp = [-i**2 for i in range(-3, 4)]
    out = find_maxima(inp)
    exp = [3]
    assert exp == out
Exemple #52
0
def test_max_with_reverse_saddel():
    inp = [1, 3, 2, 2, 1]
    out = find_maxima(inp)
    exp = [1]
    assert exp == out
def test_simple_sequence_two_maxima():
    inp = [0, 1, 2, 1, 2, 1, 0]
    out = find_maxima(inp)
    exp = [2, 4]
    assert exp == out
Exemple #54
0
def test_max_with_valley():
    inp = [3, 2, 2, 3]
    out = find_maxima(inp)
    exp = [0, 3]
    assert exp == out