Skip to content

Commit

Permalink
Solution to issue #18 in Python (#26)
Browse files Browse the repository at this point in the history
* Solution to issue #18 in Python

* Modified the code,function created to allow passing the parameters

* Tests for issue #18 added. SKELETON CODE to test python(2.7) solutions created.

* Modification to 18.py

Comments in the code have been removed. for loop has been used as discussed.

* Modification to test18.py

Tests have been modified as per the modified code of 18.py . The code has been tested and it passed the test cases.

* Solution to issue #34 in Python 2.7

* Delete 34.py

* Delete test34.py

* print statement removed from solution

* Test skeleton moved from solutions to tests

* Test modified to eliminate redundancy. pythontest_skeleton modified with new changes. Name of solution changed from 18.py to sol18.py to avoid conflict while importing the file for testing

* Renamed test18.py to 18.py and deleted pythontest_skeleton
  • Loading branch information
Himanshu1495 authored and msach22 committed Jul 7, 2017
1 parent 96fcb01 commit 100b5c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions solutions/sol18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Himanshu Nachane (@Himanshu1495)
'''return missing number in an input array of consecutively increasing numbers.
i: [5,6,8,9]
o: 7
'''

def missing_num(arr):
first_element = arr[0]
last_element = arr[-1]
new_sum = 0
for x in range(first_element,last_element+1):
new_sum += x
return new_sum - sum(arr)



14 changes: 14 additions & 0 deletions test/18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
sys.path.insert(0,'../solutions/')
from sol18 import missing_num
import unittest

class MyTest(unittest.TestCase):
def test1(self):
self.assertEqual(missing_num([10,11,12,14,15,16]),13)
def test2(self):
self.assertEqual(missing_num([125,126,128,129,130]),127)
def test3(self):
self.assertEqual(missing_num([1125,1127,1128,1129,1130]),1126)

unittest.main()

0 comments on commit 100b5c1

Please sign in to comment.