Commits

Miguel Ángel García committed 0a376a0

Red. Added MarkII tests and copied from MarkI

Comments (0)

Files changed (6)

+'''
+Created on 09/10/2010
+
+@author: miguel
+'''
+
+class MarkI(object):
+    WHEEL = [
+             "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+             "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
+             "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
+             "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+             "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
+             ".", ",", "?", "!", "'", "\"", " "
+             ]
+
+
+    def __init__(self, wheelmove):
+        '''
+        Constructor
+        '''
+        self.wheelMove = wheelmove
+        
+    def decode (self, input):
+        result = ""
+        for letter in input:
+            pos = (MarkI.WHEEL.index(letter) + self.wheelMove) % len (MarkI.WHEEL)
+            result += MarkI.WHEEL[pos]
+        return result
+
+
+class MarkII(object):
+    WHEEL = [
+             "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+             "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
+             "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
+             "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+             "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
+             ".", ",", "?", "!", "'", "\"", " "
+             ]
+
+
+    def __init__(self, wheelmove):
+        '''
+        Constructor
+        '''
+        self.wheelMove = wheelmove
+        
+    def decode (self, input):
+        result = ""
+        for letter in input:
+            pos = (MarkI.WHEEL.index(letter) + self.wheelMove) % len (MarkI.WHEEL)
+            result += MarkI.WHEEL[pos]
+        return result
+

src/MarkI.py

-'''
-Created on 09/10/2010
-
-@author: miguel
-'''
-
-class MarkI(object):
-    WHEEL = [
-             "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
-             "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
-             "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
-             "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
-             "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
-             ".", ",", "?", "!", "'", "\"", " "
-             ]
-
-
-    def __init__(self, wheelmove):
-        '''
-        Constructor
-        '''
-        self.wheelMove = wheelmove
-        
-    def decode (self, input):
-        result = ""
-        for letter in input:
-            pos = (MarkI.WHEEL.index(letter) + self.wheelMove) % len (MarkI.WHEEL)
-            result += MarkI.WHEEL[pos]
-        return result

src/MarkITest.py

-'''
-Created on 09/10/2010
-
-@author: miguel
-'''
-
-import unittest
-from MarkI import MarkI
-
-class MarkITest(unittest.TestCase):
-
-
-    def setUp(self):
-        pass
-
-
-    def tearDown(self):
-        pass
-
-
-    def testSetting5Geta(self):
-        mark = MarkI(5)
-        input = 'a'
-        expected = 'f'
-        result = mark.decode ( input )
-        self.assertEquals ( expected, result )
-        
-    def testSetting5Getc(self):
-        mark = MarkI(5)
-        input = 'c'
-        expected = 'h'
-        result = mark.decode(input)
-        self.assertEquals (expected, result)
-        
-    def testSetting5GetAdm(self):
-        mark = MarkI(5)
-        input = '!'
-        expected = '1'
-        result = mark.decode(input)
-        self.assertEquals (expected, result)
-
-    def testSetting6GetWindString (self):
-        mark = MarkI(6)
-        input = 'Strong NE Winds!'
-        expected = 'Yzxutm5TK5cotjy2'
-        result = mark.decode(input)
-        self.assertEquals (expected, result)
-        
-
-if __name__ == "__main__":
-    #import sys;sys.argv = ['', 'Test.testName']
-    unittest.main()
+'''
+Created on 09/10/2010
+
+@author: miguel
+'''
+
+import unittest
+from Mark import MarkI, MarkII
+
+class MarkITest(unittest.TestCase):
+    def setUp(self):
+        pass
+
+
+    def tearDown(self):
+        pass
+
+
+    def testSetting5Geta(self):
+        mark = MarkI(5)
+        input = 'a'
+        expected = 'f'
+        result = mark.decode (input)
+        self.assertEquals (expected, result)
+        
+    def testSetting5Getc(self):
+        mark = MarkI(5)
+        input = 'c'
+        expected = 'h'
+        result = mark.decode(input)
+        self.assertEquals (expected, result)
+        
+    def testSetting5GetAdm(self):
+        mark = MarkI(5)
+        input = '!'
+        expected = '1'
+        result = mark.decode(input)
+        self.assertEquals (expected, result)
+
+    def testSetting6GetWindString (self):
+        mark = MarkI(6)
+        input = 'Strong NE Winds!'
+        expected = 'Yzxutm5TK5cotjy2'
+        result = mark.decode(input)
+        self.assertEquals (expected, result)
+     
+class MarkIITest (unittest.TestCase):
+    def setUp(self):
+        pass
+
+
+    def tearDown(self):
+        pass
+
+
+    def testSetting25Getabc(self):
+        mark = MarkII(2,5)
+        input = 'abc'
+        expected = 'STU'
+        result = mark.decode (input)
+        self.assertEquals (expected, result)
+
+if __name__ == "__main__":
+    #import sys;sys.argv = ['', 'Test.testName']
+    unittest.main()

src/MinisculusTest.py

 '''
 import unittest
 from Minisculus import Minisculus
-from MarkI import MarkI 
+from Mark import MarkI, MarkII 
 
 class MinisculusTest(unittest.TestCase):
     FIRST_QUESTION_LOCATION = '/14f7ca5f6ff1a5afb9032aa5e533ad95'
     SECOND_QUESTION_LOCATION = '/2077f244def8a70e5ea758bd8352fcd8'
+    
+    FIRST_SENTENCE = 'Strong NE Winds!'
+    SECOND_SENTENCE = 'The Desert Fox will move 30 tanks to Calais at dawn'
 
     def setUp(self):
         self.minisculus = Minisculus ()
     def testRequestFirstQuestion (self):
         response = self.minisculus.askForQuestion (MinisculusTest.FIRST_QUESTION_LOCATION)
         self.assertEquals ( 200, response[0] )
-        self.assertEquals ( 'Strong NE Winds!', response[2]['question'] )
+        self.assertEquals ( MinisculusTest.FIRST_SENTENCE, response[2]['question'] )
         
     def testSendFirstAnswerErroneous (self):
         response = self.minisculus.sendAnswer ('error', MinisculusTest.FIRST_QUESTION_LOCATION)
         
     def testSendFirstAnswerCorrect (self):
         mark = MarkI(6)
-        answer = mark.decode('Strong NE Winds!')
+        answer = mark.decode(MinisculusTest.FIRST_SENTENCE)
         response = self.minisculus.sendAnswer (answer, MinisculusTest.FIRST_QUESTION_LOCATION)
         self.assertEquals ( 303, response[0] )
         self.assertEquals ( MinisculusTest.SECOND_QUESTION_LOCATION, response[1]['location'] )
         
     def testAskForSecondQuestion (self):
         response = self.minisculus.askForQuestion(MinisculusTest.SECOND_QUESTION_LOCATION)
-        print response
+        self.assertEquals ( 200, response[0] )
+        self.assertEquals ( MinisculusTest.SECOND_SENTENCE, response[2]['question'])
         
         
 if __name__ == "__main__":
 '''
 import unittest
 from unittest import TestSuite, TestLoader
-from MarkITest import MarkITest
+from MarkTest import MarkITest, MarkIITest
 from MinisculusTest import MinisculusTest
 
 def runSuite ():
     suite = TestSuite()
     suite.addTest(unittest.makeSuite(MarkITest))
+    suite.addTest(unittest.makeSuite(MarkIITest))
     suite.addTest(unittest.makeSuite(MinisculusTest))
     
     result = unittest.TextTestRunner(verbosity=2).run(suite)