def test_creaEnigmaOk(self): rotor = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) rotor.ini = 'K' reflector = enigma.Reflector(conf=UKW) maquina = enigma.Enigma(rotores=[rotor], reflector=reflector) self.assertEqual(maquina.ini, "A") self.assertEqual(rotor.pos_ini, "A")
def test_creaEnigmaErrores(self): with self.assertRaises(AttributeError) as e: rotor = enigma.Rotor(abecedario, rotor_types['I'][0]+'Ñ', rotor_types['I'][1]) rotor = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) rotor.ini = 'K' reflector = enigma.Reflector(conf=['ABC', 'CBA']) with self.assertRaises(AttributeError): maquina = enigma.Enigma(rotores=[rotor], reflector=reflector)
def test_codifica_frase(self): rotor1 = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) rotor2 = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) rotor3 = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) reflector = enigma.Reflector(UKW) maquina = enigma.Enigma([rotor1, rotor2, rotor3], reflector=reflector, ini='ZAA') self.assertEqual(maquina.codifica("HOLA"), "LCHD") self.assertEqual(maquina.ini, "DAA")
def test_cambia_ini(self): rotor = enigma.Rotor(abecedario, rotor_types['I'][0], rotor_types['I'][1]) rotor.ini = 'K' reflector = enigma.Reflector(conf=UKW) maquina = enigma.Enigma(rotores=[rotor], reflector=reflector, ini="C") self.assertEqual(maquina.ini, "C") self.assertEqual(maquina.rotores[0].pos_ini, "C") maquina.ini = "T" self.assertEqual(maquina.ini, "T") self.assertEqual(maquina.rotores[0].pos_ini, "T")
def test_crea_con_error(self): with self.assertRaises(AttributeError): reflector = enigma.Reflector(conf=['AAB', 'BCA'])
def test_reflejaOK(self): reflector = enigma.Reflector(UKW) self.assertEqual(reflector.refleja(0), 25)
import enigma machine = enigma.Enigma(enigma.Plugboard.STATIC_WIRING, enigma.Rotor(1, 'A', 'A'), enigma.Rotor(2, 'A', 'A'), enigma.Rotor(3, 'A', 'A'), enigma.Reflector('REFLECTOR_B')) def test_RotorWiring(rotor_n, rings, pos, fwd_in, rev_in, fwd_out, rev_out): rotor = enigma.Rotor(rotor_n, rings, pos) if rotor.produceLetterOutput( fwd_in) == fwd_out and rotor.produceReverseOutput( rev_in) == rev_out: print('Test for rotor PASS') else: print('Test for rotor FAIL') print('## CORRECT OUTPUT\n' + fwd_out + '\n' + rev_out + '\n## ACTUAL OUTPUT') print(rotor.produceLetterOutput(fwd_in)) print(rotor.produceReverseOutput(fwd_out)) def test_letterToPosition(rotor, letter, good_out): t = machine.letterToPosition(rotor, letter) if t == good_out: print('Test for letterToPosition PASS') else: print('Test for letterToPosition FAIL') print('## CORRECT OUTPUT\n' + str(good_out) + '\n## ACTUAL OUTPUT') print(t)
def test_refleja(self): reflector = enigma.Reflector() self.assertEqual(reflector.refleja(26), 0)