コード例 #1
0
 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())
コード例 #2
0
    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
コード例 #3
0
def continuingFractionAction(interim_result: InterimResult, character):
    interim_result.setV(interim_result.getV() +
                        interim_result.getP() * int(character))
    interim_result.setP(interim_result.getP() / 10)
コード例 #4
0
def continuingIntegerAction(interim_result: InterimResult, character):
    interim_result.setV(10 * interim_result.getV() + int(character))
コード例 #5
0
def startFraction(interim_result: InterimResult, character):
    interim_result.setP(0.1)
コード例 #6
0
def negateAction(interim_result: InterimResult, character):
    interim_result.setS(-1)
コード例 #7
0
 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())
コード例 #8
0
 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())
コード例 #9
0
 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())
コード例 #10
0
 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())