Ejemplo n.º 1
0
 def test_power_with_zero_raised_to_zero(self):
     calc.one_time_use("0.0 0.0 pow")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("0/-/ 0 pow")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("0 0/-/ pow")
     assert config.exit_flag == 1
Ejemplo n.º 2
0
def main():
    arg_parser = argparse.ArgumentParser(
        description='Processes a rpn expression.')

    arg_parser.add_argument('--version',
                            '-v',
                            action='store_true',
                            default=False,
                            help='Prints the version number and exits.')

    arg_parser.add_argument(
        'expression',
        nargs='*',
        help='Evaluates the expression in one time use format and exits.')

    args = arg_parser.parse_args()

    # if args.help:
    #     print ("\033[34m" + docs + "\033[0m")
    #     sys.exit()

    if args.version:
        from rpn import __version__
        print(config.bcolors.OKGREEN + __version__ + config.bcolors.ENDC)
    else:
        #print("~ Nums: {}".format(args.expression))
        if len(args.expression) > 0:
            # For one time use
            eval_string = ''
            for i in args.expression:
                eval_string += (i + " ")
            #print(eval_string)
            calc.one_time_use(eval_string)
        else:
            # For interactive use
            calc.interactive_use()
Ejemplo n.º 3
0
 def test_greater_than(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 4
0
 def test_rightshift_with_non_integers(self):
     calc.one_time_use("2 3 - 1 + 2 * 99 / 2 >>")
     # equals to "0.0 2 >>"
     assert config.exit_flag == 1
Ejemplo n.º 5
0
 def test_divide_by_zero(self):
     calc.one_time_use("2 0 /")
     assert config.exit_flag == 1
Ejemplo n.º 6
0
 def test_repeat(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 7
0
 def test_nhs(self, inp, out):
     # config.dEG=1
     assert calc.one_time_use(inp) == out
Ejemplo n.º 8
0
 def test_multiply(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 9
0
 def test_sqrt_for_negatives(self):
     calc.one_time_use("2/-/ sqrt")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("3.3/-/ sqrt")
     assert config.exit_flag == 1
Ejemplo n.º 10
0
 def test_log_to_the_base_one(self):
     calc.one_time_use("1.0 1.0 log")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("3 1 log")
     assert config.exit_flag == 1
Ejemplo n.º 11
0
 def test_log_negtive(self):
     calc.one_time_use("4/-/ 2 log")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("4 2/-/ log")
     assert config.exit_flag == 1
Ejemplo n.º 12
0
 def test_mod_by_zero(self):
     calc.one_time_use("4.7 0 %")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("0/-/ 0 %")
     assert config.exit_flag == 1
Ejemplo n.º 13
0
 def test_power(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 14
0
 def test_bool_xor(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 15
0
 def test_bit_xor_with_non_integers(self):
     calc.one_time_use("1.0 1.0 ^")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("1 1.0 ^")
     assert config.exit_flag == 1
Ejemplo n.º 16
0
 def test_minus(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 17
0
 def test_asin_input_outside_range(self):
     calc.one_time_use("2 asin")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("3.3/-/ asin")
     assert config.exit_flag == 1
Ejemplo n.º 18
0
 def test_log_zero(self):
     calc.one_time_use("0 2.3 log")
     assert config.exit_flag == 1
Ejemplo n.º 19
0
 def test_fact_of_floats_and_negative_integers(self):
     calc.one_time_use("2/-/ fact")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("3.3 fact")
     assert config.exit_flag == 1
Ejemplo n.º 20
0
 def test_log_non_positive(self):
     calc.one_time_use("4/-/ ln")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("0 ln")
     assert config.exit_flag == 1
Ejemplo n.º 21
0
 def test_hnl_negative_and_floats(self):
     calc.one_time_use("2/-/ hnl")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("2.2 hnl")
     assert config.exit_flag == 1
Ejemplo n.º 22
0
 def test_increment(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 23
0
 def test_nhs_negative_and_floats(self):
     calc.one_time_use("2/-/ nhs")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("2.2 nhs")
     assert config.exit_flag == 1
Ejemplo n.º 24
0
 def test_bit_not(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 25
0
 def test_divide(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 26
0
 def test_bit_not_floats(self):
     calc.one_time_use("4.2/-/ ~")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("0.2 ~")
     assert config.exit_flag == 1
Ejemplo n.º 27
0
 def test_rightshift(self, inp, out):
     assert calc.one_time_use(inp) == out
Ejemplo n.º 28
0
 def test_sinh_overflow(self):
     calc.one_time_use("2300.2 sinh")
     assert config.exit_flag == 1
     config.exit_flag = 0
     calc.one_time_use("3000/-/ sinh")
     assert config.exit_flag == 1
Ejemplo n.º 29
0
 def test_rightshift_with_negative_second_operand(self):
     calc.one_time_use("1/-/ 2/-/ >>")
     assert config.exit_flag == 1
Ejemplo n.º 30
0
 def test_acos(self, inp, out):
     config.dEG, config.rAD = 1, 0
     assert calc.one_time_use(inp) == out
     config.dEG, config.rAD = 0, 1