From 851d402b580c581fd008fd0dff29105c09538ed1 Mon Sep 17 00:00:00 2001 From: ParvN Date: Tue, 2 Apr 2019 14:34:22 +0200 Subject: [PATCH 1/5] Added Hash and Salt --- .travis.yml | 5 +++++ maxima.py | 7 ++++++- test_function.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 test_function.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..239882f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: python +python: + -"3.6" +script: + - pytest diff --git a/maxima.py b/maxima.py index ed03ef6..a9b7659 100755 --- a/maxima.py +++ b/maxima.py @@ -14,8 +14,13 @@ def find_maxima(x): """ idx = [] + max = (len(x)-1) for i in range(len(x)): # `i` is a local maximum if the signal decreases before and after it - if x[i-1] < x[i] and x[i+1] < x[i]: + if i ==0 and x[i+1] <= x[i]: + idx.append(i) + elif i ==max and x[i-1] <= x[i]: + idx.append(i) + elif 0 Date: Tue, 2 Apr 2019 14:48:26 +0200 Subject: [PATCH 2/5] Added Hash and Salt --- test_function.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test_function.py b/test_function.py index ce05210..9cc9581 100644 --- a/test_function.py +++ b/test_function.py @@ -2,15 +2,14 @@ import pytest import maxima from maxima import find_maxima -test_case_1 = [([0, 1, 2, 1, 2, 1, 0],[2,4]),([-i**2 for i in range(-3, 4)],[3]),([np.sin(2*alpha) for alpha in np.linspace(0.0, 5.0, 100)],[16,78]),] -def test_first_set(): - x = [0,1,2,1,2,1,0] +#def test_first_set(): + # x = [0,1,2,1,2,1,0] # x = [1, 2, 2, 1] - assert find_maxima(x) == [1,2] + #assert find_maxima(x) == [1,2] -test_case_2 = [([4, 2, 1, 3, 1, 2],[0,3,5]),([4, 2, 1, 3, 1, 5],[0,3,5]),([4, 2, 1, 3, 1],[0,3])] -test_case_3 = [([1, 2, 2, 3, 1],[1,3]),([1, 3, 2, 2, 1],[1,3]),([3, 2, 2, 3],[0,3])] +test_case_1 = [([0, 1, 2, 1, 2, 1, 0],[2,4]),([-i**2 for i in range(-3, 4)],[3]),([np.sin(2*alpha) for alpha in np.linspace(0.0, 5.0, 100)],[16,78]), +([4, 2, 1, 3, 1, 2],[0,3,5]),([4, 2, 1, 3, 1, 5],[0,3,5]),([4, 2, 1, 3, 1],[0,3]),([1, 2, 2, 3, 1],[1,3]),([1, 3, 2, 2, 1],[1,3]),([3, 2, 2, 3],[0,3])] @pytest.mark.parametrize('inp,exp',test_case_1) def test_case_1_maxima(inp,exp): From 63b399ca7e1b3404459a615221eaa0496d03a11e Mon Sep 17 00:00:00 2001 From: ParvN Date: Tue, 2 Apr 2019 15:01:20 +0200 Subject: [PATCH 3/5] Added Test functions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 239882f..b656b79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: python python: - -"3.6" + -"3.7.0" script: - pytest From 3dd5084f9e5a7f8d7b1329d35a1776a4ae7318b1 Mon Sep 17 00:00:00 2001 From: ParvN Date: Tue, 2 Apr 2019 15:24:37 +0200 Subject: [PATCH 4/5] Added Test functions --- test_function.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test_function.py b/test_function.py index 9cc9581..26820c8 100644 --- a/test_function.py +++ b/test_function.py @@ -15,3 +15,29 @@ def test_case_1_maxima(inp,exp): out = find_maxima(inp) assert out ==exp + +def test_randomized(): + #given + seedval =0 + rand_gen = np.random.RandomState(seed = seedval) + numel = rand_gen.randint(0,1000) + 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 + if out[0]==0: + assert test_vec[0] > test_vec[1] + else: + for k in range(1,out[0]): + assert test_vec[k]>=test_vec[k-1] + if len(out)>3 : + up=False + for i,j in zip(out[1:-2],out[2:-1]): + for k in range(i,j): + if test_vec[k] >test_vec[k-1]: + up = True + if test_vec[k] < test_vec[k-1]: + assert not up From cf679fd1d724b801032a57bc582ce11b2788d604 Mon Sep 17 00:00:00 2001 From: ParvN Date: Tue, 2 Apr 2019 15:33:38 +0200 Subject: [PATCH 5/5] modified yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b656b79..abf86eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -language: python +language: generic python: - -"3.7.0" + -"3.6" script: - pytest