Commits

Miguel Ángel García committed 2661c97

Green. I have the third answer and the fourth question. Thanks, Todd for your example.

Comments (0)

Files changed (5)

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
 '''
 Created on 09/10/2010
 
     def decode (self, input):
         result = ""
         for letter in input:
-            result += Mark.WHEEL[self.getLetterPosition(letter)]
+            result += Mark.WHEEL[self.__getLetterPosition(letter)]
         return result
     
-    def getLetterPosition (self, letter):
+    def __getLetterPosition (self, letter):
         current = Mark.WHEEL.index(letter)
         result = self.getPosition(current) % len (Mark.WHEEL)
         return result
         super (MarkI,self).__init__(wheel1)
     
     def getPosition (self, letter):
-        return self.wheel1 + letter
+        return letter + self.wheel1
 
 class MarkII(Mark):
     def __init__(self, wheel1, wheel2):
         
 class MarkIV(Mark):
     def __init__(self, wheel1, wheel2):
-        super (MarkIV,self).__init__()
-        self.wheel1 = wheel1
-        self.wheel2 = wheel2
+        super (MarkIV,self).__init__(wheel1, wheel2)
 
     def getPosition (self, letter):
-        result = letter + ( self.wheel1  - (2 * self.wheel2) + (2 * self.wheel3) )
-        self.wheel3 = letter
+        result = letter +  ( self.wheel1  - (2 * self.wheel2) + ( 2 * self.wheel3  ) )
+        self.wheel3 =  letter
         return result
     
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
 '''
 Created on 09/10/2010
 
 
     def tearDown(self):
         pass
-
+        
     def testSetting25Geta(self):
         mark = MarkII(2,5)
         input = 'abc'
     def tearDown(self):
         pass
     
+    def testSetting12Geta (self):
+        mark = MarkIV(1,2)
+        input = 'a'
+        expected = 'X'
+        result = mark.decode(input)
+        self.assertEquals (expected, result)
+        
+    def testSetting12Getab (self):
+        mark = MarkIV(1,2)
+        input = 'ab'
+        expected = 'Xb'
+        #expected = 'XV'
+        result = mark.decode(input)
+        self.assertEquals (expected, result)
+
     def testSetting12Getabc (self):
         mark = MarkIV(1,2)
         input = 'abc'
         expected = 'Xbe'
         result = mark.decode(input)
-        print result
         self.assertEquals (expected, result)
 
 if __name__ == "__main__":

src/Minisculus.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 '''
 Created on 09/10/2010
 
 
     def sendAnswer (self, answer, where):
         headers = "Accept: application/json"
-        body = '{ "answer" : "' + answer + '" }'
+        body = '{ "answer" : "' + answer.replace('"', '\\"') + '" }'
         method = "PUT"
         address = where
         return self.__sendMessage(headers, body.__str__(), method, address)

src/MinisculusTest.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
 '''
 Created on 09/10/2010
 
     FIRST_QUESTION_LOCATION = '/14f7ca5f6ff1a5afb9032aa5e533ad95'
     SECOND_QUESTION_LOCATION = '/2077f244def8a70e5ea758bd8352fcd8'
     THIRD_QUESTION_LOCATION = '/36d80eb0c50b49a509b49f2424e8c805'
+    FOURTH_QUESTION_LOCATION = '/4baecf8ca3f98dc13eeecbac263cd3ed'
     
     FIRST_SENTENCE = 'Strong NE Winds!'
     SECOND_SENTENCE = 'The Desert Fox will move 30 tanks to Calais at dawn'
         response = self.minisculus.askForQuestion(MinisculusTest.THIRD_QUESTION_LOCATION)
         self.assertEquals ( 200, response[0] )
         self.assertEquals ( MinisculusTest.THIRD_SENTENCE, response[2]['question'])
+        print response
         
     def testSendThirdAnswerCorrect (self):
         mark = MarkIV(4,7)
         answer = mark.decode(MinisculusTest.THIRD_SENTENCE)
         response = self.minisculus.sendAnswer (answer, MinisculusTest.THIRD_QUESTION_LOCATION)
         self.assertEquals ( 303, response[0] )
-        print response
-        self.assertEquals ( MinisculusTest.THIRD_QUESTION_LOCATION, response[1]['location'] )
+        self.assertEquals ( MinisculusTest.FOURTH_QUESTION_LOCATION, response[1]['location'] )
     
         
 if __name__ == "__main__":
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
 '''
 Created on 12/10/2010