Skip to content

Commit d7a3c3e

Browse files
authored
Merge branch 'master' into array-binary-search
2 parents 12e378e + cd1e574 commit d7a3c3e

File tree

8 files changed

+61
-2
lines changed

8 files changed

+61
-2
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"ponicode.testSettings.testLocation.locationType": "Same folder as source file",
3-
"ponicode.testSettings.testLocation.path": "{rootDir}/{filePath}/{fileName}.test.{ext}"
3+
"ponicode.testSettings.testLocation.path": "{rootDir}/{filePath}/{fileName}.test.{ext}",
4+
"python.pythonPath": ".venv/bin/python3.9"
45
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# data-structures-and-algorithms-python
22

3+
34
# Challenge Summary
45
Write a function called BinarySearch which takes in 2 parameters: a sorted array and the search key. Without utilizing any of the built-in methods available to your language, return the index of the array’s element that is equal to the search key, or -1 if the element does not exist.
56
## Challenge Description
@@ -11,4 +12,4 @@ OUTPUT => 2
1112
## Solution![Getting Started](ALGO3.png)
1213

1314

14-
https://github.com/MsDiala/data-structures-and-algorithms-python/pull/3
15+
https://github.com/MsDiala/data-structures-and-algorithms-python/pull/3
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def array_shift(l,b):
2+
middle = len(l) // 2
3+
if len(l) % 2 == 0:
4+
5+
return l[:middle] + [b] + l[middle:]
6+
else:
7+
return l[:middle + 1] + [b] + l[middle +1:]
8+
Binary file not shown.

dddddddddddd.png

314 KB
Loading
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# put your array_reverse challenge tests here
2+
from data_structures_and_algorithms.challenges.array_reverse.array_shift import array_shift
3+
4+
5+
# "Happy Path" cases
6+
# test should pass for array with number of even element where elements are integers
7+
def test_one():
8+
expected = [1,2,5,3,4]
9+
actual = array_shift([1,2,3,4],5)
10+
assert actual == expected
11+
12+
# test should pass for array with number of even element where elements are letters
13+
def test_two():
14+
expected = ['a','b','z','c','d']
15+
actual = array_shift(['a','b','c','d'],'z')
16+
assert actual == expected
17+
18+
# test should pass for array with odd number of elements where elements are letters and integers
19+
def test_three():
20+
expected = [1,2,3,'a',4,5]
21+
actual = array_shift([1,2,3,4,5],'a')
22+
assert actual == expected
23+
24+
25+
26+
# Edge Case
27+
# test should pass for initial array with only 2 elements
28+
def test_four():
29+
expected = [1,2,1]
30+
actual = array_shift([1,1],2)
31+
assert actual == expected
32+
33+
34+
35+
# Expected Failure
36+
# test should pass for initial array with elements ptinted with spaces
37+
def test_five():
38+
expected = [1,2,9,3]
39+
actual = array_shift([ 1 , 2 , 3 ],9)
40+
assert actual == expected
41+
42+
# test should pass for initial array with only one element
43+
def test_six():
44+
expected = [1,2]
45+
actual = array_shift([1],2)
46+
assert actual == expected
47+
48+
49+

0 commit comments

Comments
 (0)