kyu_3.calculator package

Submodules

kyu_3.calculator.calculator module

Solution for -> Calculator.

Create a simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces returns the value of that expression. Created by Egor Kostan. GitHub: https://github.com/ikostan

class kyu_3.calculator.calculator.Calculator[source]

Bases: object

Calculator class.

Given string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces. Returns the value of that expression.

__calculate(char: str, strings: list) None

Calculate method.

  1. Perform math operation.

  2. Reorganize math expression.

Parameters:
  • i – (int) math operation index

  • char – (str) math operation

  • strings – (list) math expression

Returns:

None

__process_math_expression(string: str, operators: list) str

Process math calculation.

Perform all operation with multiplications, divisions, additions and subtractions. :param string: str, input string :param operators: list, contains math operators :return: str, output string with no ‘*’, ‘/’, ‘+’, ‘-‘

evaluate(string: str) float[source]

Evaluate method.

Returns value of the given expression. :param string: str, input string to evaluate :return: (float) result

property result: float

Get result.

1. Set result value by converting string value to a float 2. Return result value

Returns:

float

kyu_3.calculator.test_calculator module

Testing for -> Calculator class.

Created by Egor Kostan. GitHub: https://github.com/ikostan

class kyu_3.calculator.test_calculator.CalculatorTestCase(methodName='runTest')[source]

Bases: TestCase

Testing Calculator class.

_classSetupFailed = False
_class_cleanups = []
test_calculator = None
test_calculator_0_127(**kw)

Testing Calculator class [with string=’127’, expected=127].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_1_2_3(**kw)

Testing Calculator class [with string=’2 + 3’, expected=5].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_2_2_3_4(**kw)

Testing Calculator class [with string=’2 - 3 - 4’, expected=-5].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_3_10_5_2(**kw)

Testing Calculator class [with string=’10 * 5 / 2’, expected=25].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_4_2_2_3_4_6(**kw)

Testing Calculator class [with string=’2 / 2 + 3 * 4 - 6’, expected=7].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_5_2_3_4_3_6_3_3_8(**kw)

Testing Calculator class [with string=’2 + 3 * 4 / 3 - 6 / 3 * 3 + 8’, expected=8].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_6_1_1_2_2_3_3(**kw)

Testing Calculator class [with string=’1.1 + 2.2 + 3.3’, expected=6.6].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_7_1_1_2_2_3_3(**kw)

Testing Calculator class [with string=’1.1 * 2.2 * 3.3’, expected=7.986000000000001].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

test_calculator_8_10_5_2(**kw)

Testing Calculator class [with string=’10 * 5 / 2’, expected=25].

A simple calculator that given a string of operators ‘()’, ‘+’, ‘-’, ‘*’, ‘/’ and numbers separated by spaces will return the value of that expression :return: None

Module contents

Codewars kyu_3 package: Calculator.