Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrei Trukhan #37

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ce183f0
Add files via upload
AngrySamaritan May 21, 2019
423dcd0
Add files via upload
AngrySamaritan May 21, 2019
063e5c2
Add files via upload
AngrySamaritan May 21, 2019
2e39d83
Add files via upload
AngrySamaritan May 21, 2019
7d05a51
Add files via upload
AngrySamaritan May 21, 2019
abb2cd1
Power priority fixed. log10 function fixed
AngrySamaritan May 21, 2019
03ff6cc
Bug fixes
AngrySamaritan May 21, 2019
ecccb49
Add files via upload
AngrySamaritan May 21, 2019
3039a52
Add files via upload
AngrySamaritan May 22, 2019
b1b7255
Bug fixes
AngrySamaritan May 22, 2019
1af2856
Add files via upload
AngrySamaritan May 22, 2019
bd14636
Add files via upload
AngrySamaritan May 22, 2019
f0b180e
bug fixes
AngrySamaritan May 22, 2019
343ee6b
Bug fixes
AngrySamaritan May 22, 2019
19d8b5a
Add files via upload
AngrySamaritan May 22, 2019
a19e84b
Add files via upload
AngrySamaritan May 22, 2019
1677f79
Bug fixed. Input defense requred.
AngrySamaritan May 22, 2019
64ef8ce
Bug fixed
AngrySamaritan May 22, 2019
972a9db
Adding error checking in process
AngrySamaritan May 22, 2019
8743ec1
Update .travis.yml
AngrySamaritan May 22, 2019
d2d457f
Add files via upload
AngrySamaritan May 22, 2019
1807f5a
Add files via upload
AngrySamaritan May 22, 2019
121f868
Add files via upload
AngrySamaritan May 22, 2019
690c0e8
Add files via upload
AngrySamaritan May 22, 2019
9b2c0be
Add files via upload
AngrySamaritan May 22, 2019
ee72ea2
Add files via upload
AngrySamaritan May 22, 2019
8413fb6
Update setup.py
AngrySamaritan May 22, 2019
c4fdce8
Add files via upload
AngrySamaritan May 22, 2019
adccf54
Delete start.py
AngrySamaritan May 22, 2019
51fc48c
Delete stack.py
AngrySamaritan May 22, 2019
8d70965
Delete main.py
AngrySamaritan May 22, 2019
73b5be7
Delete main.cpython-36.pyc
AngrySamaritan May 22, 2019
a6f66f1
Delete stack.cpython-36.pyc
AngrySamaritan May 22, 2019
ad9ffe6
Delete stack.cpython-37.pyc
AngrySamaritan May 22, 2019
27d0a1f
Delete setup.py
AngrySamaritan May 22, 2019
a6b659f
Add files via upload
AngrySamaritan May 22, 2019
63a3c3b
Add files via upload
AngrySamaritan May 22, 2019
0e7fc07
Add files via upload
AngrySamaritan May 22, 2019
ea8c2c6
Calculation worked. Input defense requred
AngrySamaritan May 22, 2019
42d53e2
Add files via upload
AngrySamaritan May 22, 2019
76b31ed
Add files via upload
AngrySamaritan May 22, 2019
527ee21
Add files via upload
AngrySamaritan May 22, 2019
8b2a42d
Input defense in progress
AngrySamaritan May 22, 2019
dc82757
Add files via upload
AngrySamaritan May 22, 2019
eaa17b7
Add files via upload
AngrySamaritan May 23, 2019
9ca56bf
Add files via upload
AngrySamaritan May 23, 2019
d7652fd
Input defense in process
AngrySamaritan May 23, 2019
8c2c009
Add files via upload
AngrySamaritan May 23, 2019
8ff0bbe
Almost release
AngrySamaritan May 23, 2019
b5735e4
Almost release. Tests required
AngrySamaritan May 23, 2019
c2c5444
PEP8
AngrySamaritan May 23, 2019
656a841
PEP8
AngrySamaritan May 23, 2019
d723055
Add files via upload
AngrySamaritan May 23, 2019
38d6481
Add files via upload
AngrySamaritan May 23, 2019
fd06e50
Bug fixes
AngrySamaritan May 23, 2019
6e6b475
Add files via upload
AngrySamaritan May 23, 2019
c647660
Fixed
AngrySamaritan May 23, 2019
2a24d89
PEP8 fix
AngrySamaritan May 23, 2019
89624e4
Bug fixed. UnitTests in process
AngrySamaritan May 23, 2019
61c8a11
Uploaded tests
AngrySamaritan May 23, 2019
1161036
PEP8
AngrySamaritan May 23, 2019
9d29022
PEP8
AngrySamaritan May 23, 2019
22c1374
PEP8
AngrySamaritan May 23, 2019
df2c3ed
PEP8
AngrySamaritan May 23, 2019
45813ed
Some tests added
AngrySamaritan May 23, 2019
dd25125
Add files via upload
AngrySamaritan May 23, 2019
214cdac
Delete check_mistakes.py
AngrySamaritan May 23, 2019
cd0a9e1
Add files via upload
AngrySamaritan May 23, 2019
80d1571
Update .travis.yml
AngrySamaritan May 23, 2019
f5a28ef
Попытка настроить тестирование
AngrySamaritan May 23, 2019
86faab3
Настроить не получилось
AngrySamaritan May 23, 2019
752abc8
Update .travis.yml
AngrySamaritan May 23, 2019
cee6243
Create test_main.py
AngrySamaritan May 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ script:
- cd final_task
- pip install .
- nosetests --cover-branches --with-coverage .
- pycodestyle --max-line-length=120 .
- pycodestyle --ignore=W605 --max-line-length=120 .
- python ./../pycalc_checker.py
- cd -
- python ./test_main.py
- cd -
Binary file added final_task/dist/pycalc-0.1.tar.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions final_task/pycalc.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: pycalc
Version: 0.1
Summary: Alpha version pure-python command-line calculator
Home-page: UNKNOWN
Author: Andrei Trukhan
Author-email: [email protected]
License: free
Description: UNKNOWN
Platform: UNKNOWN
10 changes: 10 additions & 0 deletions final_task/pycalc.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
setup.py
pycalc/main.py
pycalc/stack.py
pycalc/start.py
pycalc.egg-info/PKG-INFO
pycalc.egg-info/SOURCES.txt
pycalc.egg-info/dependency_links.txt
pycalc.egg-info/entry_points.txt
pycalc.egg-info/not-zip-safe
pycalc.egg-info/top_level.txt
1 change: 1 addition & 0 deletions final_task/pycalc.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions final_task/pycalc.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[console_scripts]
pycalc = pycalc.start:main

1 change: 1 addition & 0 deletions final_task/pycalc.egg-info/not-zip-safe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions final_task/pycalc.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pycalc
Binary file not shown.
Binary file added final_task/pycalc/__pycache__/consts.cpython-36.pyc
Binary file not shown.
Binary file added final_task/pycalc/__pycache__/main.cpython-36.pyc
Binary file not shown.
Binary file added final_task/pycalc/__pycache__/stack.cpython-36.pyc
Binary file not shown.
Binary file added final_task/pycalc/__pycache__/stack.cpython-37.pyc
Binary file not shown.
105 changes: 105 additions & 0 deletions final_task/pycalc/check_mistakes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from pycalc.main import Stack
from pycalc.consts import *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Импорт через звездочку -- это зло



def check_mistakes(expression, functions={}, mode=0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Крайне не рекомендуется использование изменяемых типов данных в качестве аргумента по умолчанию в функциях. Такие объекты создаются лишь единожды при создании объека функции, а не каждый раз при ее выполнении.


def is_number(part):
for char in part:
if not char.isnumeric() and char != '.':
return False
return True

if len(expression) == 0:
if mode == 0:
return "ERROR: empty expression"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для этих целей нужно использовать исключения, а не возвращаемые значения

elif mode == 1:
return "ERROR: empty brackets"
elif mode == 2:
return ''

begin = -1
brackets_stack = Stack.Stack()

for index, element in enumerate(expression):
if element == '(':
brackets_stack.push('(')
if begin == -1:
begin = index
elif element == ')':
if brackets_stack.is_empty():
return "ERROR: brackets are not paired"
brackets_stack.pop()
if brackets_stack.is_empty():
if expression[begin - 1].isalpha() and not expression[begin - 1] in math_consts:
error = check_mistakes(expression[begin + 1: index], functions, 2)
else:
error = check_mistakes(expression[begin + 1: index], functions, 1)
begin = -1

if error != '':
return error

elif element == " ":
expression.remove(element)
if not brackets_stack.is_empty():
return "ERROR: brackets are not paired"

if expression[len(expression) - 1] in signs:
return "ERROR: no number after operator"

main_sign_count = 0
l_sign_count = 0
number_count = 0
logical_sign_pos = 0

for index in range(len(expression)):

if expression[index] in ['+', '-']:
main_sign_count += 1

elif expression[index] in ['*', '/', '^', '%', '//']:
if number_count == 0:
return "ERROR: no numbers before sign"

if index != len(expression) - 1 and expression[index + 1] in ['*', '/', '^', '%', '//']:
return "ERROR: duplicate multiply or div sign"

elif expression[index] in logical_signs:
l_sign_count += 1
logical_sign_pos = index
if l_sign_count > 1:
return "ERROR: more than one logical operator"

elif expression[index] == '=':
return "ERROR: illegal usage '='"

elif is_number(expression[index]):
number_count += 1
if index != len(expression) - 1 and is_number(expression[index + 1]):
return "ERROR: no sign between expression"

elif expression[index].isalpha():
if expression[index] in math_consts:
number_count += 1
elif expression[index] in functions:
if index == len(expression) - 1 or expression[index + 1] != '(':
return "ERROR: no brackets after function"

else:
return "ERROR: function does not exist"

elif expression[index] == '(':
if expression[index - 1] not in functions and expression[index - 1] not in signs \
and index != 0:
return "ERROR: no sign or function before brackets"

if l_sign_count == 1:
if (len(expression[:logical_sign_pos])) == 0 or (len(expression[logical_sign_pos:])) == 0 \
or logical_sign_pos in [0, len(expression) - 1]:
return "ERROR: one of expressions around logical operator is empty"

if number_count == 0:
return "ERROR: no numbers in expression"

return ''
32 changes: 32 additions & 0 deletions final_task/pycalc/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import operator
import math

signs = ['+', '-', '*', '/', '^', '%', '>', '<', '=', '//', '!']

logical_signs = {
'>': operator.gt,
'>=': operator.ge,
'==': operator.eq,
'!=': operator.ne,
"<=": operator.le,
"<": operator.le
}


operators_type1 = {
'*': operator.mul,
'/': operator.truediv,
'//': operator.floordiv,
'%': operator.mod
}

operators_main = {
'+': operator.add,
'-': operator.sub
}

math_consts = {
"pi": math.pi,
"e": math.e

}
Loading