TestCenter Reference
Math.py
Go to the documentation of this file.
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 ----------------------------------------------------------------------------{{{-
15from numbers import Number
16
17# ----------------------------------------------------------------------------------------------}}}-
18
19
21 return isinstance(a, Number) and isinstance(b, Number)
22
23
25 return (type(a) in (list, tuple)) and (type(b) in (list, tuple))
26
27
29 return len(a) == len(b)
30
31
32def _areEqual(a, b, epsilon):
33 return abs(a - b) < epsilon
34
35
36def _isLessThan(a, b):
37 return a < b
38
39
40# -- def compareFloatEqual ---------------------------------------------------------------------{{{-
41
46def 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
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
107def compareFloatLessThanOrEqual(a, b, epsilon=0.0001):
108 return compareFloatLessThan(a, b) or compareFloatEqual(a, b, epsilon)
109
110
111# ----------------------------------------------------------------------------------------------}}}-
112
113from .Logging import error as Logging_error, warning as Logging_warning, info as Logging_info
_areOfTypeListOrTuple(a, b)
Definition Math.py:24
_isLessThan(a, b)
Definition Math.py:36
compareFloatLessThanOrEqual(a, b, epsilon=0.0001)
Compare the two given float values if the first is less than or equal to the second.
Definition Math.py:107
compareFloatLessThan(a, b)
Compare the two given float values if the first is less than the second.
Definition Math.py:76
compareFloatEqual(a, b, epsilon=0.0001)
Compare the given float values or lists of float values for equality.
Definition Math.py:46
_haveEqualLength(a, b)
Definition Math.py:28
_areInstancesOfNumber(a, b)
Definition Math.py:20
_areEqual(a, b, epsilon)
Definition Math.py:32