Commits

Miguel Ángel García committed 152699e

Green. Implementing the cracker.

Comments (0)

Files changed (3)

              ".", ",", "?", "!", "'", "\"", " "
              ]
 
-    def applyAlgorithm (self, input, modifier=1):
-        result = ""
-        for letter in input:
-            result += Mark.WHEEL[self.__getLetterPosition(letter, modifier)]
-        return result
-
     def encode (self, input):
         result = ""
         for letter in input:
     
     def updateWheels (self, value):
         pass
-
+    
 class MarkI(Mark):
     def __init__(self, wheel1):
         super (MarkI, self).__init__()
 
     def updateWheels (self, value):
         self.wheel3 = value
+
+class MarkIVCracker (object):
+    def __init__ (self, code, keywords):
+        self.code = code
+        self.keywords = keywords
+        
+    def next (self):
+        return ( (1,2), 'En un lugar de la mancha')
+        
+        
 '''
 
 import unittest
-from Mark import MarkI, MarkII, MarkIV
+from Mark import MarkI, MarkII, MarkIV, MarkIVCracker
 
 class MarkITest(unittest.TestCase):
     def setUp(self):
         expected = 'The white cliffs of Alghero are visible at night'
         result = mark.decode(input)
         self.assertEquals (expected, result)
+        
+class MarkIVCrack (unittest.TestCase):
+    def testCrackSimple (self):
+        mark = MarkIV (1,2)
+        input = 'En un lugar de la mancha'
+        coded = mark.encode(input)
+        cracker = MarkIVCracker ( input, ['lugar, mancha'])
+        decoded = cracker.next()
+        
+        self.assertEquals ( (1,2) , decoded[0])
+        self.assertEquals ( input , decoded[1])
+        
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']
     unittest.main()

src/MinisculusTest.py

     SECOND_QUESTION_LOCATION = '/2077f244def8a70e5ea758bd8352fcd8'
     THIRD_QUESTION_LOCATION = '/36d80eb0c50b49a509b49f2424e8c805'
     FOURTH_QUESTION_LOCATION = '/4baecf8ca3f98dc13eeecbac263cd3ed'
+    FIFTH_QUESTION_LOCATION = '/finish/50763edaa9d9bd2a9516280e9044d885'
     
     FIRST_SENTENCE = 'Strong NE Winds!'
     SECOND_SENTENCE = 'The Desert Fox will move 30 tanks to Calais at dawn'
     THIRD_SENTENCE = 'The white cliffs of Alghero are visible at night'
-    FOURTH_SENTENCE = 'WZyDsL3u\'0TfxP06RtSSF \'DbzhdyFIAu2 zF f5KE"SOQTNA8A"NCKPOKG5D9GSQE\'M86IGFMKE6\'K4pEVPK!bv83I'
+    FOURTH_SENTENCE = 'WZyDsL3u\'0TfxP06RtSSF \'DbzhdyFIAu2 zF f5KE"SOQTNA8A"NCKPOKG5D9GSQE\'M86IGFMKE6\'K4pEVPK!bv83I' 
+    FIFTH_SENTENCE  = 'QT4e8MJYVhkls.27BL9,.MSqYSi\'IUpAJKWg9Ul9p4o8oUoGy\'ITd4d0AJVsLQp4kKJB2rz4dxfahwUa"Wa.MS!k4hs2yY' +\
+        '3k8ymnla.MOTxJ6wBM7sC0srXmyAAMl9t"Wk4hs2yYTtH0vwUZp4a"WhB2u,o6.!8Zt"Wf,,eh5tk8WXv9UoM99w2Vr4!.xq' +\
+        'A,5MSpWl9p4kJ2oUg\'6evkEiQhC\'d5d4k0qA\'24nEqhtAQmy37il9p4o8vdoVr!xWSkEDn?,iZpw24kF"fhGJZMI8nkI'
 
     def setUp(self):
         self.minisculus = Minisculus ()
     def testSendThirdAnswerCorrect (self):
         mark = MarkIV(4,7)
         answer = mark.encode(MinisculusTest.THIRD_SENTENCE)
-        print answer
         response = self.minisculus.sendAnswer (answer, MinisculusTest.THIRD_QUESTION_LOCATION)
         self.assertEquals ( 303, response[0] )
         self.assertEquals ( MinisculusTest.FOURTH_QUESTION_LOCATION, response[1]['location'] )
         self.assertEquals ( 200, response[0] )
         self.assertEquals ( MinisculusTest.FOURTH_SENTENCE, response[2]['question'])
         
+    def testSendFourthAnswerCorrect (self):
+        mark = MarkIV(7,2)
+        answer = mark.decode(MinisculusTest.FOURTH_SENTENCE)
+        response = self.minisculus.sendAnswer (answer, MinisculusTest.FOURTH_QUESTION_LOCATION)
+        print response
+        self.assertEquals ( 303, response[0] )
+        self.assertEquals ( MinisculusTest.FIFTH_QUESTION_LOCATION, response[1]['location'] )
+        
+    def testAskForFifthQuestion (self):
+        response = self.minisculus.askForQuestion(MinisculusTest.FIFTH_QUESTION_LOCATION)
+        self.assertEquals ( 200, response[0] )
+        print response
+        self.assertEquals ( MinisculusTest.FIFTH_SENTENCE, response[2]['code'])
+       
+    def testCracker
+        
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']
     unittest.main()