TestCenter Reference
Math.py
Go to the documentation of this file.
1
#
2
# Copyright 2010, MeVis Medical Solutions AG
3
#
4
# The user may use this file in accordance with the license agreement provided with
5
# the Software or, alternatively, in accordance with the terms contained in a
6
# written agreement between the user and MeVis Medical Solutions AG.
7
#
8
# For further information use the contact form at https://www.mevislab.de/contact
9
#
10
11
13
14
# -- system imports ----------------------------------------------------------------------------{{{-
15
from
numbers
import
Number
16
17
# ----------------------------------------------------------------------------------------------}}}-
18
19
20
def
_areInstancesOfNumber
(a, b):
21
return
isinstance(a, Number)
and
isinstance(b, Number)
22
23
24
def
_areOfTypeListOrTuple
(a, b):
25
return
(type(a)
in
(list, tuple))
and
(type(b)
in
(list, tuple))
26
27
28
def
_haveEqualLength
(a, b):
29
return
len(a) == len(b)
30
31
32
def
_areEqual
(a, b, epsilon):
33
return
abs(a - b) < epsilon
34
35
36
def
_isLessThan
(a, b):
37
return
a < b
38
39
40
# -- def compareFloatEqual ---------------------------------------------------------------------{{{-
41
46
def
compareFloatEqual(a, b, epsilon=0.0001):
47
result =
False
48
if
_areInstancesOfNumber
(a, b):
49
result =
_areEqual
(a, b, epsilon)
50
51
elif
_areOfTypeListOrTuple
(a, b):
52
if
_haveEqualLength
(a, b):
53
result =
True
54
for
i
in
range(0, len(a)):
55
result = compareFloatEqual(a[i], b[i], epsilon)
56
if
not
result:
57
break
58
59
else
:
60
Logging_error(
"Only lists or tuples of equal length can be compared!"
)
61
62
else
:
63
Logging_error(
"Only numbers can be compared!"
)
64
65
return
result
66
67
68
# ----------------------------------------------------------------------------------------------}}}-
69
70
71
# -- def compareFloatLessThan ------------------------------------------------------------------{{{-
72
76
def
compareFloatLessThan(a, b):
77
result =
False
78
if
_areInstancesOfNumber
(a, b):
79
result =
_isLessThan
(a, b)
80
81
elif
_areOfTypeListOrTuple
(a, b):
82
if
_haveEqualLength
(a, b):
83
for
i
in
range(0, len(a)):
84
result = compareFloatLessThan(a[i], b[i])
85
if
not
result:
86
break
87
88
else
:
89
Logging_error(
"Only lists or tuples of equal length can be compared!"
)
90
91
else
:
92
Logging_error(
"Only numbers can be compared!"
)
93
94
return
result
95
96
97
# ----------------------------------------------------------------------------------------------}}}-
98
99
100
# -- def compareFloatLessThanOrEqual -----------------------------------------------------------{{{-
101
107
def
compareFloatLessThanOrEqual(a, b, epsilon=0.0001):
108
return
compareFloatLessThan(a, b)
or
compareFloatEqual(a, b, epsilon)
109
110
111
# ----------------------------------------------------------------------------------------------}}}-
112
113
from
.Logging
import
error
as
Logging_error, warning
as
Logging_warning, info
as
Logging_info
TestSupport.Math._areOfTypeListOrTuple
_areOfTypeListOrTuple(a, b)
Definition
Math.py:24
TestSupport.Math._isLessThan
_isLessThan(a, b)
Definition
Math.py:36
TestSupport.Math._haveEqualLength
_haveEqualLength(a, b)
Definition
Math.py:28
TestSupport.Math._areInstancesOfNumber
_areInstancesOfNumber(a, b)
Definition
Math.py:20
TestSupport.Math._areEqual
_areEqual(a, b, epsilon)
Definition
Math.py:32
MeVisLab
Standard
Modules
Scripts
python
TestSupport
Math.py
Generated by
1.9.8