예제 #1
0
class TestEx11(unittest.TestCase):

    def setUp(self):
        self.racional_number1 = RacionalNumber(3, 4)
        self.racional_number2 = RacionalNumber(4, 2)

    def test_consult_denominator_and_numerator_from_racional_number1(self):
        self.racional_number1.numerator |should| equal_to(3)
        self.racional_number1.denominator |should| equal_to(4)

    def test_consult_denominator_and_numerator_from_racional_number2(self):
        self.racional_number2.numerator |should| equal_to(2)
        self.racional_number2.denominator |should| equal_to(1)

    def test_addition(self):
        self.racional_number1 + self.racional_number2 |should| \
         equal_to(RacionalNumber(11, 4))

    def test_subtraction(self):
        self.racional_number1 - self.racional_number2 |should| \
         equal_to(RacionalNumber(-5, 4))

    def test_multiplication(self):
        self.racional_number1 * self.racional_number2 |should| \
         equal_to(RacionalNumber(3, 2))

    def test_division(self):
        self.racional_number1 / self.racional_number2 |should| \
         equal_to(RacionalNumber(6, 16))

    def test_parse_to_string(self):
        self.racional_number1.string |should| equal_to('3/4')

    def test_parse_to_float_string(self):
        self.racional_number1.float_string(3) |should| equal_to('0.75')
예제 #2
0
 def setUp(self):
     self.racional_number1 = RacionalNumber(3, 4)
     self.racional_number2 = RacionalNumber(4, 2)