Commits

Anonymous committed e25eabf

clean merge

Comments (0)

Files changed (3)

 __author__ = 'sam'
-  
+import math
+
+
+def chop(value_to_find,values):
+   pass
 
 class TestChopper(unittest.TestCase):
 
-	def chop_kata_moves(self,chop):
-		
-		self.assertEqual(-1, chop(3, []))
-		self.assertEqual(-1, chop(3, [1]))
-		self.assertEqual(0,  chop(1, [1]))
-		
-    
-		self.assertEqual(0,  chop(1, [1, 3, 5]))
-		self.assertEqual(1,  chop(3, [1, 3, 5]))
-		self.assertEqual(2,  chop(5, [1, 3, 5]))
-		self.assertEqual(-1, chop(0, [1, 3, 5]))
-		self.assertEqual(-1, chop(2, [1, 3, 5]))
-		self.assertEqual(-1, chop(4, [1, 3, 5]))
-		self.assertEqual(-1, chop(6, [1, 3, 5]))
-		
-		self.assertEqual(0,  chop(1, [1, 3, 5, 7]))
-		self.assertEqual(1,  chop(3, [1, 3, 5, 7]))
-		self.assertEqual(2,  chop(5, [1, 3, 5, 7]))
-		self.assertEqual(3,  chop(7, [1, 3, 5, 7]))
-		self.assertEqual(-1, chop(0, [1, 3, 5, 7]))
-		self.assertEqual(-1, chop(2, [1, 3, 5, 7]))
-		self.assertEqual(-1, chop(4, [1, 3, 5, 7]))
-		self.assertEqual(-1, chop(6, [1, 3, 5, 7]))
-		self.assertEqual(-1, chop(8, [1, 3, 5, 7]))
+    def chop_kata_moves(self,chop):
 
-	def test_chop_one(self):		
-		from one.chopper import chop as chop_one
-		self.chop_kata_moves(chop_one)
-		
-	def test_chop_two(self):		
-		from two.chopper import chop as chop_two
-		self.chop_kata_moves(chop_two)
-	
-	def test_chop_three(self):		
-		from three.chopper import chop as chop_three
-		self.chop_kata_moves(chop_three)
-		
-	
+        self.assertEqual(-1, chop(3, []))
+        self.assertEqual(-1, chop(3, [1]))
+        self.assertEqual(0,  chop(1, [1]))
+
+
+        self.assertEqual(0,  chop(1, [1, 3, 5]))
+        self.assertEqual(1,  chop(3, [1, 3, 5]))
+        self.assertEqual(2,  chop(5, [1, 3, 5]))
+        self.assertEqual(-1, chop(0, [1, 3, 5]))
+        self.assertEqual(-1, chop(2, [1, 3, 5]))
+        self.assertEqual(-1, chop(4, [1, 3, 5]))
+        self.assertEqual(-1, chop(6, [1, 3, 5]))
+
+        self.assertEqual(0,  chop(1, [1, 3, 5, 7]))
+        self.assertEqual(1,  chop(3, [1, 3, 5, 7]))
+        self.assertEqual(2,  chop(5, [1, 3, 5, 7]))
+        self.assertEqual(3,  chop(7, [1, 3, 5, 7]))
+        self.assertEqual(-1, chop(0, [1, 3, 5, 7]))
+        self.assertEqual(-1, chop(2, [1, 3, 5, 7]))
+        self.assertEqual(-1, chop(4, [1, 3, 5, 7]))
+        self.assertEqual(-1, chop(6, [1, 3, 5, 7]))
+        self.assertEqual(-1, chop(8, [1, 3, 5, 7]))
+
+    def test_chop_one(self):
+        from one.chopper import chop as chop_one
+        self.chop_kata_moves(chop_one)
+
+    def test_chop_two(self):
+        from two.chopper import chop as chop_two
+        self.chop_kata_moves(chop_two)
+
+    def test_chop_three(self):
+        from three.chopper import chop as chop_three
+        self.chop_kata_moves(chop_three)
+
+
+
+#    def test_chop_five(self):
+#        from five.chopper import chop as chop_five
+#        self.chop_kata_moves(chop_five)
+
+
+
+
 
 if __name__ == '__main__':
     unittest.main()
 
 def check_index_value(mid_index, value_to_find, values):
     if value_to_find == values[mid_index]:
-        return 0
+        return mid_index
     else:
         return -1
 
 
     while mid_index >= 0 and mid_index < len(values) and len(values) > 0 :
        
-        if mid_index == 0:
+        if mid_index == 0 or mid_index == len(values)-1:
             return check_index_value(mid_index, value_to_find, values)
 
         elif value_to_find == values[mid_index]:
             half_mid_index = int( math.ceil(float(mid_index) / 2))
             if half_mid_index == 0:
                 return check_index_value(0, value_to_find, values)
+            elif value_to_find > values[mid_index-1] and value_to_find < values[mid_index]:
+                return -1
             elif value_to_find > values[mid_index]:
                mid_index = mid_index + half_mid_index
             else: