Esempio n. 1
0
    def dispose_decrement(self, base_val: int, base_sign: str,
                  base_obj: my_module.RomanDigit, v: int, s: str,
                  decr_val: int, decr_sign: str, assert_success: bool, msg: str):
        # base_val: the base value of the RomanDigit being tested
        # base_sign: the base sign of the RomanDigit being tested
        # base_obj: the RomanDigit to be tested
        # v: the value for decrementing, varies through the loop
        # s: the sign for decrementing, varies through the loop
        # decr_val: the value for calling the decreaser function
        # decr_sign: the sign for calling the decreaser function
        # forced: decides whether to use forced decrement
        # assert_success: decides whether to assert success
        #
        # return values: the RomanDigit and the value and sign after the test

        if assert_success:
            v += decr_val
            assert v == base_val and s[-1] == s[1:], "something went wrong with test\nmessage: %s" % msg
            s = s[1:]
            base_obj.dispose_decrement()
            self.assertEqual(base_obj.get_value(), v, 'value is not all-right\nmessage: %s' % msg)
            self.assertEqual(base_obj.get_sign(), s, 'sign is not all-right\nmessage: %s' % msg)
        else:
            self.assertRaises(my_module.IncreaseError, my_module.RomanDigit.dispose_decrement, base_obj)
        return [base_obj, v, s]
Esempio n. 2
0
    def dispose_increment(self, base_val: int, base_sign: str,
                          base_obj: my_module.RomanDigit, v: int, s: str,
                          incr_val: int, incr_sign: str, all_increments: bool, assert_success: bool, msg: str):
        # base_val: the base value of the RomanDigit being tested
        # base_sign: the base sign of the RomanDigit being tested
        # base_obj: the RomanDigit to be tested
        # v: the value for incrementing, varies through the loop
        # s: the sign for incrementing, varies through the loop
        # all_increments: decides whether to dispose all increments
        # assert_success: decides whether to assert success
        # msg: message to be displayed on assertion failure
        #
        # return value: the RomanDigit and the value and sign after the test

        if assert_success:
            if all_increments:
                v = base_val
                s = s[1]
            else:
                v -= incr_val
                s = s[:-1]
            base_obj.dispose_increment(all_increments)
            self.assertEqual(base_obj.get_value(), v,
                             'value is not all-right (value: {0}, sign: {1})\nmessage: %s'.format(v, s) % msg)
            self.assertEqual(base_obj.get_sign(), s,
                             'sign is not all-right (value: {0}, sign: {1})\nmessage: %s'.format(v, s) % msg)
        else:
            self.assertRaises(my_module.IncreaseError, my_module.RomanDigit.dispose_increment, base_obj, all_increments)
        return [base_obj, v, s]
Esempio n. 3
0
    def increase(self, base_val: int, base_sign: str,
                  base_obj: my_module.RomanDigit, v: int, s: str,
                  incr_val: int, incr_sign: str, forced: bool, max_n_incr: int, msg: str):
        # base_val: the base value of the RomanDigit being tested
        # base_sign: the base sign of the RomanDigit being tested
        # base_obj: the RomanDigit to be tested
        # v: the value for incrementing, varies through the loop
        # s: the sign for incrementing, varies through the loop
        # incr_val: the value for calling the increaser function
        # incr_sign: the sign for calling the increaser function
        # forced: decides whether to use forced increment
        # max_n_incr: the number of increments -- failure is asserted if zero
        # msg: message to be displayed on assertion failure
        #
        # return values: the RomanDigit and the value and sign after the test

        if max_n_incr == 0:
            self.assertRaises(my_module.IncrementError, my_module.RomanDigit.increase, base_obj, incr_val, forced)
        for j in range(max_n_incr):
            v += incr_val
            s += incr_sign
            base_obj.increase(incr_val, forced)
            self.assertEqual(base_obj.get_value(), v,
                             'value is not all-right (value: {0}, sign: {1})\nmessage: %s'.format(v, s) % msg)
            self.assertEqual(base_obj.get_sign(), s,
                             'sign is not all-right (value: {0}, sign: {1})\nmessage: %s'.format(v, s) % msg)
        return [base_obj, v, s]
Esempio n. 4
0
    def decrease(self, base_val: int, base_sign: str,
                  base_obj: my_module.RomanDigit, v: int, s: str,
                  decr_val: int, decr_sign: str, forced: bool, assert_success: bool, msg: str):
        # base_val: the base value of the RomanDigit being tested
        # base_sign: the base sign of the RomanDigit being tested
        # base_obj: the RomanDigit to be tested
        # v: the value for decrementing, varies through the loop
        # s: the sign for decrementing, varies through the loop
        # decr_val: the value for calling the decreaser function
        # decr_sign: the sign for calling the decreaser function
        # forced: decides whether to use forced decrement
        # assert_success: decides whether to assert success
        #
        # return values: the RomanDigit and the value and sign after the test

        if assert_success:
            v -= decr_val
            s = decr_sign + s
            base_obj.decrease(decr_val, forced)
            self.assertEqual(base_obj.get_value(), v, 'bla')
            self.assertEqual(base_obj.get_sign(), s, 'bla')
        else:
            self.assertRaises(my_module.IncreaseError, my_module.RomanDigit.decrease, base_obj, decr_val)
        return [base_obj, v, s]