Ejemplo n.º 1
0
 def test_str_check(self):
     str1 = '(((14-2)))'
     str2 = '-1'
     str3 = '-(-1,9)'
     str4 = '-((13+3   ))+(-12+4)'
     self.assertEqual(checking(str1), '(1*(1*(14-2)))')
     self.assertEqual(checking(str2), '0-1')
     self.assertEqual(checking(str3), '0-(0-1.9)')  
     self.assertEqual(checking(str4), '0-(1*(13+3))+(0-12+4)')  
Ejemplo n.º 2
0
def str_parse(inp):  #превращаем готовую строку в массив
    znaki = ('+', '-', '*', '/', '^', '(', ')')
    temp_arr = ['']
    if checking(inp) == False:
        temp_arr = ['=']
        return temp_arr
    else:
        inp = checking(inp)
    i = 0
    j = 0

    try:
        while i < len(inp):
            while i < len(inp) and inp[
                    i] in znaki:  #если это операция, то просто добавляем его в массив
                temp_arr[j] += inp[i]
                i += 1
                j += 1
                temp_arr.append('')
                if i >= len(inp):
                    break

            while i < len(inp) and inp[
                    i] not in znaki:  #если это число, то плюсуем строку
                temp_arr[j] += inp[i]
                i += 1
                if i >= len(inp):
                    break
            if i >= len(inp):
                break
            temp_arr[j] = float(
                temp_arr[j])  #переводим полученное число в тип float
            temp_arr.append('')
            j += 1
            if i >= len(inp):
                break
        for m in temp_arr:
            if m == '':
                temp_arr.remove('')
        if temp_arr[-1] not in znaki:
            temp_arr[-1] = float(temp_arr[-1])
        return temp_arr
    except:
        temp_arr = ['=']
        return temp_arr
Ejemplo n.º 3
0
def test_result3():
    inp = '(11)^(-2+4*(5-3*1-2^0))'
    out = 121
    assert final(str_parse(checking(inp))) == out
Ejemplo n.º 4
0
def test_result2():
    inp = '2^(456,0-456.0)'
    out = 1
    assert final(str_parse(checking(inp))) == out
Ejemplo n.º 5
0
def test_result1():
    inp = '(35)'
    out = 35
    assert final(str_parse(checking(inp))) == out
Ejemplo n.º 6
0
def test_result():
    inp = '(35-(44-(58*2^6)+13-14)/2)'
    out = 1869.5
    assert final(str_parse(checking(inp))) == out
Ejemplo n.º 7
0
def test_str7():
    inp = '(35-(44-(58*2^6)+13-14)/2)'
    out = '(35-(44-(58*2^6)+13-14)/2)'
    assert checking(inp) == out
Ejemplo n.º 8
0
def test_str6():
    inp = '--1'
    out = False
    assert checking(inp) == out
Ejemplo n.º 9
0
 def test_str_check_good(self):
     str = ['1+2', '(1+2)', '1+2*2', '1', '(3+(2*3)-4)', '2^(3-3)', '1+4/5-8+4^0.543', '5^0*(2^14)']
     for i in str:
         print(i, '  Tested ok ++++')
         self.assertEqual(checking(i), i)            
Ejemplo n.º 10
0
def test_str4():
    inp = ')1('
    out = False
    assert checking(inp) == out
Ejemplo n.º 11
0
def test_str3():
    inp = '(1)'
    out = '(1)'
    assert checking(inp) == out
Ejemplo n.º 12
0
def test_str2():
    inp = ''
    out = False
    assert checking(inp) == out
Ejemplo n.º 13
0
def test_str1():
    inp = '()'
    out = False
    assert checking(inp) == out
Ejemplo n.º 14
0
def test_str():
    inp = '1+2'
    out = '1+2'
    assert checking(inp) == out
Ejemplo n.º 15
0
def test_check_parse1():
    inp = '(258.0+(25/3))'
    res = ['(', 258.0, '+', '(', 25.0, '/', 3.0, ')', ')']
    assert str_parse(checking(inp)) == res
Ejemplo n.º 16
0
def test_str5():
    inp = '11111111111111111111111111111111111111111111111111111111111111111111111111111111.0+1.001'
    out = '11111111111111111111111111111111111111111111111111111111111111111111111111111111.0+1.001'
    assert checking(inp) == out
Ejemplo n.º 17
0
 def test_str_check_bad(self):
     str = ['((', '()', '-', '1++1', 'abc', '', '1+a', '1+1a', ' ']
     for i in str:
         print(i, '   Tested ok ++++')
         self.assertEqual(checking(i), False)