kyu_2.evaluate_mathematical_expression package

Submodules

kyu_2.evaluate_mathematical_expression.evaluate module

Evaluate mathematical expression.

Given a mathematical expression as a string you must return the result as a number.

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

kyu_2.evaluate_mathematical_expression.evaluate.bracket_end(strings: list, start: int) int[source]

Return index of last (close) bracket.

Parameters:
  • strings

  • start

Returns:

kyu_2.evaluate_mathematical_expression.evaluate.bracket_start(strings: list) int[source]

Return index of first (open) bracket.

Parameters:

strings – list

Returns:

int

kyu_2.evaluate_mathematical_expression.evaluate.calc(string: str) float[source]

Calculate math expression from input string.

Parameters:

string – str

Returns:

float

kyu_2.evaluate_mathematical_expression.evaluate.calculate(i: int, char: str, strings: list) None[source]

Calculate math expression.

Parameters:
  • i – int

  • char – str

  • strings – list

Returns:

None

kyu_2.evaluate_mathematical_expression.evaluate.check_conditions(strings: list, string: str, temp: str) tuple[str, str][source]

Test string normalization.

Normalize string input by checking conditions. :param strings: list :param string: str :param temp: str :return: tuple(str, str)

kyu_2.evaluate_mathematical_expression.evaluate.process_brackets(strings: list) str[source]

Test bracket processing.

Process brackets in order to convert input string into math expression. :param strings: list :return: str

kyu_2.evaluate_mathematical_expression.evaluate.process_duplicate_minus(string: str) str[source]

Eliminate duplicate minus.

Parameters:

string – str

Returns:

str

kyu_2.evaluate_mathematical_expression.evaluate.process_math_expression(string: str, operators: list) str[source]

Process math expression.

Parameters:
  • string – str

  • operators – list

Returns:

str

kyu_2.evaluate_mathematical_expression.test_evaluate module

Test for -> calc method.

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

class kyu_2.evaluate_mathematical_expression.test_evaluate.CalcTestCase(methodName='runTest')[source]

Bases: TestCase

Testing calc method.

_classSetupFailed = False
_class_cleanups = []
test_calc = None
test_calc_00_1_1(**kw)

Testing calc class [with string=’1 + 1’, expected=2].

Given a mathematical expression as a string you must return the result as a number.

test_calc_01_8_16(**kw)

Testing calc class [with string=’8/16’, expected=0.5].

Given a mathematical expression as a string you must return the result as a number.

test_calc_02_3_1_(**kw)

Testing calc class [with string=’3 -(-1)’, expected=4].

Given a mathematical expression as a string you must return the result as a number.

test_calc_03_2_2(**kw)

Testing calc class [with string=’2 + -2’, expected=0].

Given a mathematical expression as a string you must return the result as a number.

test_calc_04_10_2_5(**kw)

Testing calc class [with string=’10- 2- -5’, expected=13].

Given a mathematical expression as a string you must return the result as a number.

test_calc_05__10_(**kw)

Testing calc class [with string=’(((10)))’, expected=10].

Given a mathematical expression as a string you must return the result as a number.

test_calc_06_3_5(**kw)

Testing calc class [with string=’3 * 5’, expected=15].

Given a mathematical expression as a string you must return the result as a number.

test_calc_07__7_6_3_(**kw)

Testing calc class [with string=’-7 * -(6 / 3)’, expected=14].

Given a mathematical expression as a string you must return the result as a number.

test_calc_08_2_3_4_3_6_3_3_8(**kw)

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

Given a mathematical expression as a string you must return the result as a number.

test_calc_09_1_2_3_3_8(**kw)

Testing calc class [with string=’1 + 2 * 3 * 3 - 8’, expected=11].

Given a mathematical expression as a string you must return the result as a number.

test_calc_10_1_2_3_5_3_1_8(**kw)

Testing calc class [with string=’1 + 2 * 3 * (5 - (3 - 1)) - 8’, expected=11].

Given a mathematical expression as a string you must return the result as a number.

test_calc_11__1_(**kw)

Testing calc class [with string=’-(-(-(-1)))’, expected=1].

Given a mathematical expression as a string you must return the result as a number.

test_calc_12__1_(**kw)

Testing calc class [with string=’(((((-1)))))’, expected=-1].

Given a mathematical expression as a string you must return the result as a number.

test_calc_13_58_40_45_13_35_19_71_60(**kw)

Testing calc class [with string=’58 / 40 - -45 * 13 * 35 - -19 / -71 + 60’, expected=20536.1823943662].

Given a mathematical expression as a string you must return the result as a number.

test_calc_14_61_82_81_53_84_83_74_60(**kw)

Testing calc class [with string=’61 + 82 + -81 - -53 * 84 - -83 + -74 / 60’, expected=4595.766666666666].

Given a mathematical expression as a string you must return the result as a number.

test_calc_15__94_36_64_13_41_15_58_23_(**kw)

Testing calc class [with string=’-(94) * (36 / 64 + -(13)) - (41 - (((-(-15 - 58)))) - -23)’, expected=1178.125].

Given a mathematical expression as a string you must return the result as a number.

test_calc_16__91_92_2_13_42_90_30_53_(**kw)

Testing calc class [with string=’-(-91) - (92 - -2 / -(13)) / (-42 - -(((-(-90 - 30)))) * -53)’, expected=91.014346478264].

Given a mathematical expression as a string you must return the result as a number.

test_calc_17__93_36_26_18_7_67_95_9_(**kw)

Testing calc class [with string=’-(-93) / (-36 + 26 + -(18)) + (-7 * -(((-(-67 + -95)))) + -9)’, expected=1121.6785714285713].

Given a mathematical expression as a string you must return the result as a number.

test_calc_18__23_4_13_1_30_57_20_85_(**kw)

Testing calc class [with string=’-(-23) + (-4 * -13 + -(1)) - (-30 / (((-(57 + -20)))) + 85)’, expected=-11.810810810810807].

Given a mathematical expression as a string you must return the result as a number.

test_calc_19__72_82_93_88_18_60_97_79_(**kw)

Testing calc class [with string=’(72) / (-82 - -93 * -(88)) + (-18 - -(((-(60 * 97)))) + -79)’, expected=-5917.00871037987].

Given a mathematical expression as a string you must return the result as a number.

test_calc_20__77_7_76_59_98_74_47_5_(**kw)

Testing calc class [with string=’-(77) / (7 * -76 + (59)) + (98 / -(((-(-74 - -47)))) / -5)’, expected=0.8887166236003445].

Given a mathematical expression as a string you must return the result as a number.

Module contents

Codewars kyu_2 package: Evaluate mathematical expression.