Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sem3-ivt19-task1-1-mozgovoy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Мозговой Никита Александрович
sem3-ivt19-task1-1-mozgovoy
Commits
5da40977
Commit
5da40977
authored
Dec 24, 2020
by
Мозговой Никита Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final
parent
c8b70977
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
21 deletions
+88
-21
calcprint.cpython-38.pyc
__pycache__/calcprint.cpython-38.pyc
+0
-0
calculate.cpython-38.pyc
__pycache__/calculate.cpython-38.pyc
+0
-0
calc-history.log.txt
calc-history.log.txt
+57
-0
calcprint.py
calcprint.py
+7
-3
calculate.py
calculate.py
+17
-9
tests.py
tests.py
+7
-9
No files found.
__pycache__/calcprint.cpython-38.pyc
View file @
5da40977
No preview for this file type
__pycache__/calculate.cpython-38.pyc
View file @
5da40977
No preview for this file type
calc-history.log.txt
View file @
5da40977
...
...
@@ -49,3 +49,60 @@
2020-12-24 12:35:56.157801 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 12:35:56.158796 : + : (3.2, 5.4, 1.0, 6) = 15.6
2020-12-24 13:08:11.592307 : + : (3.0, 4.0) = 7.0
2020-12-24 13:24:43.055152 : + : (1.0, 5.0, 8.0, 2.6) = 16.6
2020-12-24 13:25:06.881371 : * : (4.0, 0.5, 7.0, 8.12) = 113.68
2020-12-24 13:28:50.739547 : - : (2, 10.34) = -8.34
2020-12-24 13:28:50.740545 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:28:50.741573 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:28:50.744532 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 13:28:50.745532 : + : (3.2, 5.4, 1.0, 6) = 15.6
2020-12-24 13:30:44.266659 : - : (2, 10.34) = -8.34
2020-12-24 13:30:44.267654 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:30:44.268652 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:40:42.439985 : ^ : (5.0, 3.0) = 125.0
2020-12-24 13:52:28.571393 : - : (2, 10.34) = -8.34
2020-12-24 13:52:28.571393 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:52:28.572393 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:55:41.445078 : - : (2, 10.34) = -8.34
2020-12-24 13:55:41.446076 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 13:55:41.449111 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 13:56:15.861004 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:06:36.751973 : - : (2, 10.34) = -8.34
2020-12-24 14:06:36.752938 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:06:36.754965 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:07:04.374024 : - : (2, 10.34) = -8.34
2020-12-24 14:07:04.375022 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:07:04.376019 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:17:03.490601 : - : (2, 10.34) = -8.34
2020-12-24 14:17:03.491599 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:17:03.492597 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:17:20.245140 : - : (2, 10.34) = -8.34
2020-12-24 14:17:20.247205 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:17:20.248132 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:22:57.873281 : - : (2, 10.34) = -8.34
2020-12-24 14:22:57.874282 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:22:57.877240 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:36:04.816856 : - : (2, 10.34) = -8.34
2020-12-24 14:36:04.816856 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:36:04.820849 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:38:46.424016 : - : (2, 10.34) = -8.34
2020-12-24 14:38:46.424016 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:38:46.428009 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:40:48.845155 : - : (2, 10.34) = -8.34
2020-12-24 14:40:48.849180 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:40:48.849180 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:42:41.346920 : - : (2, 10.34) = -8.34
2020-12-24 14:42:41.346920 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:42:41.350908 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:18.246659 : - : (2, 10.34) = -8.34
2020-12-24 14:43:18.246659 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:43:18.266632 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:18.270628 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:43:18.270628 : * : (5, 3) = 15.0
2020-12-24 14:43:44.909308 : ^ : (5.0, 3.0) = 125.0
2020-12-24 14:43:56.104507 : - : (2, 10.34) = -8.34
2020-12-24 14:43:56.108501 : - : (8, 2.3, 0, 4.55) = 1.15
2020-12-24 14:43:56.108501 : / : (25, 5.0, 2.5) = 2.0
2020-12-24 14:43:56.112465 : * : (3.2, 5.6, 1) = 17.92
2020-12-24 14:43:56.112465 : ^ : (5, 3) = 125.0
2020-12-24 14:43:56.112465 : + : (3.2, 5.4, 1.0, 6) = 15.6
calcprint.py
View file @
5da40977
...
...
@@ -34,6 +34,10 @@ def print_results(*args, action=None, result=None):
def
write_log
(
*
args
,
action
=
None
,
result
=
None
,
file
=
'calc-history.log.txt'
):
from
datetime
import
datetime
try
:
f
=
open
(
file
,
mode
=
'a'
,
errors
=
'ignore'
)
f
.
write
(
f
"{datetime.now()} : {action} : {args} = {result}
\n
"
)
f
.
close
()
except
:
print
(
"Невозможно открыть или создать файл"
)
\ No newline at end of file
calculate.py
View file @
5da40977
...
...
@@ -40,6 +40,7 @@ def convert_precision(prec):
>>> convert_precision('s')
None
'''
try
:
prec
=
str
(
prec
)
for
i
in
prec
:
if
i
==
'e'
:
...
...
@@ -48,6 +49,8 @@ def convert_precision(prec):
if
i
==
"."
:
x
=
prec
.
split
(
'.'
)
return
int
(
len
(
x
[
1
]))
except
ValueError
:
print
(
"Неверно указана точность, проверьте данные"
)
def
user_input
():
...
...
@@ -70,7 +73,7 @@ def user_input():
if
len
(
args
)
<=
1
:
return
print
(
"Введите один из знаков действия: +, -, *, / "
)
print
(
"Введите один из знаков действия: +, -, *, /
, ^
"
)
action
=
input
(
"action: "
)
try
:
...
...
@@ -121,6 +124,11 @@ def calculate(*args, action=None, **kwargs):
for
n
in
args
[
1
:(
len
(
list
(
args
)))]:
result
/=
n
if
action
==
'^'
:
result
=
args
[
0
]
for
n
in
args
[
1
:
len
(
args
)]:
result
=
result
**
n
if
type
(
result
)
is
not
output_type
:
result
=
output_type
(
result
)
...
...
tests.py
View file @
5da40977
...
...
@@ -5,12 +5,10 @@ if __name__=="__main__":
load_params
()
class
TestCalculator
(
unittest
.
TestCase
):
def
test_summ
(
self
):
self
.
assertEqual
(
(
calculate
(
*
(
3.2
,
5.4
,
1.0
,
6
),
action
=
"+"
,
**
PARAMS
)),
15.6
)
self
.
assertEqual
((
calculate
(
*
(
3.2
,
5.4
,
1.0
,
6
),
action
=
"+"
,
**
PARAMS
)),
15.6
)
def
test_diff_pos
(
self
):
self
.
assertEqual
(
(
calculate
(
*
(
8
,
2.3
,
0
,
4.55
),
action
=
"-"
,
**
PARAMS
)),
1.15
)
self
.
assertEqual
((
calculate
(
*
(
8
,
2.3
,
0
,
4.55
),
action
=
"-"
,
**
PARAMS
)),
1.15
)
def
test_diff_neg
(
self
):
self
.
assertEqual
((
calculate
(
*
(
2
,
10.34
),
action
=
"-"
,
**
PARAMS
)),
-
8.34
)
...
...
@@ -18,17 +16,17 @@ if __name__=="__main__":
def
test_mult
(
self
):
self
.
assertEqual
((
calculate
(
*
(
3.2
,
5.6
,
1
),
action
=
"*"
,
**
PARAMS
)),
17.92
)
def
test_power
(
self
):
self
.
assertEqual
((
calculate
(
*
(
5
,
3
),
action
=
"^"
,
**
PARAMS
)),
125.0
)
def
test_div
(
self
):
self
.
assertEqual
(
(
calculate
(
*
(
25
,
5.0
,
2.5
),
action
=
"/"
,
**
PARAMS
)),
2.0
)
self
.
assertEqual
((
calculate
(
*
(
25
,
5.0
,
2.5
),
action
=
"/"
,
**
PARAMS
)),
2.0
)
def
test_precision
(
self
):
self
.
assertEqual
(
convert_precision
(
0.0000001
),
7
)
self
.
assertEqual
(
convert_precision
(
0.001
),
3
)
def
test_error
(
self
):
with
self
.
assertRaises
(
Exception
):
calculate
(
*
(
5
,
0
),
action
=
"/"
,
**
PARAMS
)
calculate
(
*
(
'yes'
,
5
),
action
=
"+"
,
**
PARAMS
)
self
.
assertEqual
(
calculate
(
*
(
5
,
0
),
action
=
"/"
,
**
PARAMS
),
'Деление невозможно'
)
unittest
.
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment