Пример #1
0
 def test_divide_by_zero_returns_error(self):
     calc = Calculator()
     try:
         calc.div(12, 0)
         self.assertFalse(True, "Expected exception")
     except:
         return
Пример #2
0
 def test_zero_to_power_of_zero_returns_error(self):
     calc = Calculator()
     try:
         calc.power(0, 0)
         self.assertFalse(True, "Expected exception")
     except UndefinedResultError:
         return
     except:
         self.assertFalse(True, "Unexpected type of exception")
Пример #3
0
 def test_multy_test2(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(
             self.calculator.root(3, 5).multiply(10, 20, 30).subtract(
                 10, 100, 1000000).power(4).value)),
         float('{:.10f}'.format(
             ((((calc_value**(1.0 / 3.0))**(1.0 / 5.0)) * 6000.0) -
              1000110)**4)))
Пример #4
0
 def test_multy_test1(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(
             self.calculator.add(30, 239).divide(
                 20, 30,
                 integer_divide=False).power(7, 8,
                                             350).subtract(1000000).value)),
         float('{:.10f}'.format(((((calc_value + 269) / 600.0)**7)**8) -
                                1000000)))
Пример #5
0
def test_build_rpn():
    print('Testing Calculator.build.rpn()')
    calc = Calculator()
    calc.input_queue.enqueue(calc.functions['exp'])
    calc.input_queue.enqueue('(')
    calc.input_queue.enqueue(1)
    calc.input_queue.enqueue(calc.operators['add'])
    calc.input_queue.enqueue(2)
    calc.input_queue.enqueue(calc.operators['mul'])
    calc.input_queue.enqueue(3)
    calc.input_queue.enqueue(')')
    calc.build_rpn()
    print(calc.output_queue)
class TestCalculator(unittest.TestCase):
    def setUp(self):
        self.test_class = Calculator()
        self.data = {}

        with open('fixtures_test_class.json', encoding='utf8') as f:
            self.data = json.load(f)

    def test_calculate_sum(self):
        for v in self.data['sum']:
            self.assertEqual(self.test_class.sum(v[0], v[1]), v[2])

    def test_calculate_mult(self):
        for v in self.data['mult']:
            self.assertEqual(self.test_class.mult(v[0], v[1]), v[2])
Пример #7
0
class TestCalculator(TestCase):
    def setUp(self):
        self.calc = Calculator()

    @patch('main.Calculator.sum', return_value=9)
    def test_sum(self, sum):
        self.assertEqual(sum(2, 3), 9)

    def test_sum2(self):
        answer = self.calc.sum(2, 4)
        self.assertEqual(answer, 6)

    @patch('main.Blog')
    def test_blog_posts(self, MockBlog):
        blog = MockBlog()

        blog.posts.return_value = [{
            'userId':
            1,
            'id':
            1,
            'title':
            'Test Title',
            'body':
            'Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the Galaxy\ lies a small unregarded yellow sun.'
        }]

        response = blog.posts()
        self.assertIsNotNone(response)
        self.assertIsInstance(response[0], dict)
Пример #8
0
class TestCalculator(TestCase):
    def setUp(self):
        self.calc = Calculator()

    def test_sum(self):
        answer = self.calc.sum(2, 4)
        self.assertEqual(answer, 6)
Пример #9
0
class CalculatorTest(unittest.TestCase):
    def setUp(self):
        self.calculator = Calculator()

    @unittest.skip("цей тест ми скіпаємо, бо нам хочеться!")
    def test_add(self):
        self.assertEqual(self.calculator.add(4, 7), 11)

    def test_subtract(self):
        self.assertEqual(self.calculator.subtract(10, 5), 5)

    @unittest.skipIf(7 > 1, "а тут невірна умова!")
    def test_multiply(self):
        self.assertEqual(self.calculator.multiply(3, 7), 21)

    def test_divide(self):
        self.assertEqual(self.calculator.divide(10, 2), 5)
Пример #10
0
class TestCalc(unittest.TestCase):
    def setUp(self):
        self.a = 13
        self.b = 2
        self.calc = Calculator(self.a, self.b)

    def test_sum(self):
        self.assertEqual(self.calc.sum(), 15)

    def test_sub(self):
        self.assertEqual(self.calc.sub(), 11)

    def test_mul(self):
        self.assertEqual(self.calc.mul(), 26)

    def test_div(self):
        self.assertEqual(self.calc.div(), 13 / 2)
Пример #11
0
class CalculatorTest(unittest.TestCase):

  def setUp(self):
    self.calculator = Calculator()

  def test_add(self):
    self.assertEqual(self.calculator.add(4,7), 11)

  def test_subtract(self):
    self.assertEqual(self.calculator.subtract(10,5), 5)

  def test_multiply(self):
    self.assertEqual(self.calculator.multiply(3,7), 21)

  def test_divide(self):
    self.assertEqual(self.calculator.divide(10,2), 5)

  def test_divide2(self):
    self.assertEqual(self.calculator.divide(10,0), None)
Пример #12
0
def test_eval_rpn():
    print('Testing Calculator.eval_rpn()')
    calc = Calculator()
    calc.output_queue.enqueue(1)
    calc.output_queue.enqueue(2)
    calc.output_queue.enqueue(3)
    calc.output_queue.enqueue(calc.operators['mul'])
    calc.output_queue.enqueue(calc.operators['add'])
    calc.output_queue.enqueue(calc.functions['exp'])
    print(f'RPN Evualation: {calc.eval_rpn()}')
Пример #13
0
class TestCalculator(TestCase):

    # using mock patch
    @patch('main.Calculator.sum', return_value=6)
    def test_sum(self, sum):
        self.assertEqual(sum(2, 4), 6)

    # using normal unit testing
    def setUp(self):
        self.calc = Calculator()

    def test_two(self):
        ans = self.calc.sum(2, 5)
        self.assertEqual(ans, 7)
Пример #14
0
 def test_root_less_zero(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(self.calculator.root(-10).value)),
         float('{:.10f}'.format(1.0 / calc_value**0.1)))
Пример #15
0
 def test_pow_incorrect_input(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.power("MAAD").message, "Error")
Пример #16
0
 def test_root_zero(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.root(0).message, "Error")
Пример #17
0
class TestCalculator(unittest.TestCase):
    def setUp(self):
        self.calculator = Calculator()

    def test_time1(self):
        t0 = time.time()
        print("System time is " + str(t0) + " seconds")

    def test_add(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6)

    def test_mul(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            self.calculator.multiply(5, 2, 90).value, calc_value * 900)

    def test_divide(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6)

    def test_divide_zero(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.divide(0).message, "Error")

    def test_pow(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.power(2, 3).value, (calc_value**2)**3)

    def test_pow_large(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.power(12).value, calc_value**12)

    def test_pow_zero(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.power(0).value, 1)

    def test_pow_less_zero(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            self.calculator.power(-5).value, 1.0 / (calc_value**5))

    def test_pow_rational(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(self.calculator.power(3.14).value)),
            float('{:.10f}'.format((calc_value**3.14))))

    def test_pow_incorrect_input(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.power("MAAD").message, "Error")

    def test_root(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(self.calculator.root(25).value)),
            float('{:.10f}'.format(calc_value**0.04)))

    def test_root_zero(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(self.calculator.root(0).message, "Error")

    def test_root_less_zero(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(self.calculator.root(-10).value)),
            float('{:.10f}'.format(1.0 / calc_value**0.1)))

    def test_root_rational(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(self.calculator.root(2.7).value)),
            float('{:.10f}'.format(calc_value**(1.0 / 2.7))))

    def test_root_large(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(self.calculator.root(1000).value)),
            float('{:.10f}'.format(calc_value**0.001)))

    def test_multy_test1(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(
                self.calculator.add(30, 239).divide(
                    20, 30,
                    integer_divide=False).power(7, 8,
                                                350).subtract(1000000).value)),
            float('{:.10f}'.format(((((calc_value + 269) / 600.0)**7)**8) -
                                   1000000)))

    def test_multy_test2(self):
        self.calculator = Calculator()
        calc_value = self.calculator.value
        self.assertEqual(
            float('{:.10f}'.format(
                self.calculator.root(3, 5).multiply(10, 20, 30).subtract(
                    10, 100, 1000000).power(4).value)),
            float('{:.10f}'.format(
                ((((calc_value**(1.0 / 3.0))**(1.0 / 5.0)) * 6000.0) -
                 1000110)**4)))

    def test_time2(self):
        t1 = time.time()
        print("System time is " + str(t1) + " seconds")
Пример #18
0
 def test_pow_rational(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(self.calculator.power(3.14).value)),
         float('{:.10f}'.format((calc_value**3.14))))
Пример #19
0
 def test_pow_less_zero(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         self.calculator.power(-5).value, 1.0 / (calc_value**5))
Пример #20
0
 def test_pow_zero(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.power(0).value, 1)
 def test_calculator_add_method_returns_correct_result(self):
     calc = Calculator()
     result = calc.add(2, 2)
     self.assertEqual(4, result)
Пример #22
0
 def test_root_rational(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(self.calculator.root(2.7).value)),
         float('{:.10f}'.format(calc_value**(1.0 / 2.7))))
Пример #23
0
from main import Calculator

for i in range(5):
    eg = Calculator(input1=float(input("Enter a number:")), input2=float(input("Enter another number: ")),
                    choice=input("Enter the desired operation: "))
Пример #24
0
 def test_root_large(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(
         float('{:.10f}'.format(self.calculator.root(1000).value)),
         float('{:.10f}'.format(calc_value**0.001)))
Пример #25
0
 def test_divide(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6)
Пример #26
0
from main import Calculator

basicCal = Calculator()
basicCal.addNumbers(22, 45)
Пример #27
0
 def test_divide_zero(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.divide(0).message, "Error")
Пример #28
0
 def calc(self):
     return Calculator()
Пример #29
0
 def test_pow(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.power(2, 3).value, (calc_value**2)**3)
Пример #30
0
 def setUp(self):
     self.calc = Calculator()
Пример #31
0
 def test_pow_large(self):
     self.calculator = Calculator()
     calc_value = self.calculator.value
     self.assertEqual(self.calculator.power(12).value, calc_value**12)