def test_continuingFractionAction(self): interim_result = InterimResult(p=.1, s=1, v=24) self.assertIsNone(Actions.continuingFractionAction( interim_result, "5")) self.assertEqual(.01, interim_result.getP()) self.assertEqual(1, interim_result.getS()) self.assertEqual(24.5, interim_result.getV())
def parseText(self, text): current_state = State.START interim_result = InterimResult(p=0, s=1, v=0) for character in list(text): next_edge = self.searchForEdge(current_state, character) if next_edge is not None: next_edge.action(interim_result, character) current_state = next_edge.next_state else: print("Error: You didn't type a real number!") final_result = interim_result.getS() * interim_result.getV() return final_result
def continuingFractionAction(interim_result: InterimResult, character): interim_result.setV(interim_result.getV() + interim_result.getP() * int(character)) interim_result.setP(interim_result.getP() / 10)
def continuingIntegerAction(interim_result: InterimResult, character): interim_result.setV(10 * interim_result.getV() + int(character))
def startFraction(interim_result: InterimResult, character): interim_result.setP(0.1)
def negateAction(interim_result: InterimResult, character): interim_result.setS(-1)
def test_continuingIntegerAction(self): interim_result = InterimResult(p=0, s=1, v=23) self.assertIsNone(Actions.continuingIntegerAction(interim_result, "5")) self.assertEqual(0, interim_result.getP()) self.assertEqual(1, interim_result.getS()) self.assertEqual(235, interim_result.getV())
def test_startFraction(self): interim_result = InterimResult(p=0, s=1, v=0) self.assertIsNone(Actions.startFraction(interim_result, ".")) self.assertEqual(.1, interim_result.getP()) self.assertEqual(1, interim_result.getS()) self.assertEqual(0, interim_result.getV())
def test_negateAction(self): interim_result = InterimResult(p=0, s=1, v=0) self.assertIsNone(Actions.negateAction(interim_result, "-")) self.assertEqual(0, interim_result.getP()) self.assertEqual(-1, interim_result.getS()) self.assertEqual(0, interim_result.getV())
def test_valueIsDigitAction(self): interim_result = InterimResult(p=0, s=1, v=0) self.assertIsNone(Actions.valueIsDigitAction(interim_result, "1")) self.assertEqual(0, interim_result.getP()) self.assertEqual(1, interim_result.getS()) self.assertEqual(1, interim_result.getV())