ucon 0.3.4__tar.gz → 0.3.5rc1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ucon-0.3.5rc1/LICENSE +202 -0
- ucon-0.3.5rc1/NOTICE +28 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/PKG-INFO +4 -3
- {ucon-0.3.4 → ucon-0.3.5rc1}/noxfile.py +5 -1
- {ucon-0.3.4 → ucon-0.3.5rc1}/setup.py +6 -2
- ucon-0.3.5rc1/tests/__init__.py +3 -0
- ucon-0.3.5rc1/tests/ucon/__init__.py +3 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/tests/ucon/test_algebra.py +3 -1
- {ucon-0.3.4 → ucon-0.3.5rc1}/tests/ucon/test_core.py +202 -48
- {ucon-0.3.4 → ucon-0.3.5rc1}/tests/ucon/test_quantity.py +26 -19
- {ucon-0.3.4 → ucon-0.3.5rc1}/tests/ucon/test_units.py +3 -1
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon/__init__.py +4 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon/algebra.py +4 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon/core.py +155 -150
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon/quantity.py +23 -76
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon/units.py +4 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon.egg-info/PKG-INFO +4 -3
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon.egg-info/SOURCES.txt +1 -0
- ucon-0.3.4/LICENSE +0 -21
- ucon-0.3.4/tests/__init__.py +0 -0
- ucon-0.3.4/tests/ucon/__init__.py +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/.github/workflows/publish.yaml +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/.github/workflows/tests.yaml +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/.gitignore +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/README.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ROADMAP.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/decisions/composable-unit-algebra.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/decisions/composite-units.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/decisions/unit-algebra-naming.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/decisions/unity-distance-metric-for-nearest-scale.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/explainers/type-operation-matrix.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/explainers/why-algebraic-closure-matters.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/explainers/why-type-safety-matters.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/proposals/interface-unifying-the-value-layer.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/proposals/project_unified-algebraic-core.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/proposals/support-for-fractional-exponents.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/docs/proposals/unified-unit-presentation.md +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/requirements.txt +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/setup.cfg +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon.egg-info/dependency_links.txt +0 -0
- {ucon-0.3.4 → ucon-0.3.5rc1}/ucon.egg-info/top_level.txt +0 -0
ucon-0.3.5rc1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright © 2025 The Radiativity Company
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
ucon-0.3.5rc1/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
ucon — A dimensional analysis and unit algebra library
|
|
2
|
+
© 2025 The Radiativity Company
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0.
|
|
5
|
+
You may not use this project except in compliance with the License.
|
|
6
|
+
A copy of the License is included in the LICENSE file or at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
This NOTICE file is part of the ucon distribution.
|
|
11
|
+
|
|
12
|
+
ucon implements:
|
|
13
|
+
• A compositional unit algebra (UnitFactor, UnitProduct, UnitForm)
|
|
14
|
+
• A dimension algebra based on vector-space operations
|
|
15
|
+
• Expression-level scale separation for unit provenance
|
|
16
|
+
• A foundation for ConversionGraph-based unit transformations
|
|
17
|
+
|
|
18
|
+
Portions of this software may incorporate or depend upon
|
|
19
|
+
third-party libraries. Attribution notices for those components,
|
|
20
|
+
if required, are included here or in the accompanying documentation.
|
|
21
|
+
|
|
22
|
+
The Radiativity Company retains all trademark rights to the names:
|
|
23
|
+
• "ucon"
|
|
24
|
+
• "The Radiativity Company"
|
|
25
|
+
• "Project Calico"
|
|
26
|
+
|
|
27
|
+
This file is for attribution purposes only and does not modify
|
|
28
|
+
the terms of the Apache License, Version 2.0.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ucon
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5rc1
|
|
4
4
|
Summary: a tool for dimensional analysis: a "Unit CONverter"
|
|
5
5
|
Home-page: https://github.com/withtwoemms/ucon
|
|
6
6
|
Author: Emmanuel I. Obi
|
|
7
7
|
Maintainer: Emmanuel I. Obi
|
|
8
8
|
Maintainer-email: withtwoemms@gmail.com
|
|
9
|
-
License:
|
|
9
|
+
License: Apache-2.0
|
|
10
10
|
Classifier: Development Status :: 3 - Alpha
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Intended Audience :: Education
|
|
13
13
|
Classifier: Intended Audience :: Science/Research
|
|
14
14
|
Classifier: Topic :: Software Development :: Build Tools
|
|
15
|
-
Classifier: License :: OSI Approved ::
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.7
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.8
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -23,6 +23,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.14
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
|
+
License-File: NOTICE
|
|
26
27
|
Dynamic: author
|
|
27
28
|
Dynamic: classifier
|
|
28
29
|
Dynamic: description
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# © 2025 The Radiativity Company
|
|
2
|
+
# Licensed under the Apache License, Version 2.0
|
|
3
|
+
# See the LICENSE file for details.
|
|
4
|
+
|
|
1
5
|
import nox
|
|
2
6
|
import re
|
|
3
7
|
from subprocess import check_output
|
|
@@ -106,7 +110,7 @@ def install(session):
|
|
|
106
110
|
@nox.session(name="test", python=supported_python_versions)
|
|
107
111
|
def test(session):
|
|
108
112
|
"""Run the test suite (with coverage if enabled)."""
|
|
109
|
-
session.install(".")
|
|
113
|
+
#session.install(".")
|
|
110
114
|
session.install("coverage")
|
|
111
115
|
|
|
112
116
|
args = [
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# © 2025 The Radiativity Company
|
|
2
|
+
# Licensed under the Apache License, Version 2.0
|
|
3
|
+
# See the LICENSE file for details.
|
|
4
|
+
|
|
1
5
|
from os import environ as envvars
|
|
2
6
|
from pathlib import Path
|
|
3
7
|
from setuptools import find_packages, setup
|
|
@@ -9,7 +13,7 @@ setup(
|
|
|
9
13
|
long_description=Path(__file__).absolute().parent.joinpath('README.md').read_text(),
|
|
10
14
|
long_description_content_type='text/markdown',
|
|
11
15
|
use_scm_version={'local_scheme': 'no-local-version'} if envvars.get('LOCAL_VERSION_SCHEME') else True,
|
|
12
|
-
license='
|
|
16
|
+
license='Apache-2.0',
|
|
13
17
|
setup_requires=[
|
|
14
18
|
'setuptools_scm==6.3.2'
|
|
15
19
|
],
|
|
@@ -24,7 +28,7 @@ setup(
|
|
|
24
28
|
'Intended Audience :: Education',
|
|
25
29
|
'Intended Audience :: Science/Research',
|
|
26
30
|
'Topic :: Software Development :: Build Tools',
|
|
27
|
-
'License :: OSI Approved ::
|
|
31
|
+
'License :: OSI Approved :: Apache Software License',
|
|
28
32
|
'Programming Language :: Python :: 3.7',
|
|
29
33
|
'Programming Language :: Python :: 3.8',
|
|
30
34
|
'Programming Language :: Python :: 3.9',
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# © 2025 The Radiativity Company
|
|
2
|
+
# Licensed under the Apache License, Version 2.0
|
|
3
|
+
# See the LICENSE file for details.
|
|
4
|
+
|
|
1
5
|
import math
|
|
2
6
|
import unittest
|
|
3
7
|
|
|
@@ -9,7 +13,7 @@ from ucon import Dimension
|
|
|
9
13
|
from ucon import Unit
|
|
10
14
|
from ucon import units
|
|
11
15
|
from ucon.algebra import Vector
|
|
12
|
-
from ucon.core import
|
|
16
|
+
from ucon.core import UnitFactor, UnitProduct, ScaleDescriptor
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
class TestDimension(unittest.TestCase):
|
|
@@ -328,10 +332,11 @@ class TestScaleMultiplicationAdditional(unittest.TestCase):
|
|
|
328
332
|
self.assertIsInstance(result, Scale)
|
|
329
333
|
self.assertEqual(result.value.base, 10)
|
|
330
334
|
|
|
335
|
+
@unittest.skip("TODO: revamp: Unit.scale is deprecated.")
|
|
331
336
|
def test_scale_multiplication_with_unit(self):
|
|
332
|
-
meter =
|
|
337
|
+
meter = UnitFactor('m', name='meter', dimension=Dimension.length)
|
|
333
338
|
kilometer = Scale.kilo * meter
|
|
334
|
-
self.assertIsInstance(kilometer,
|
|
339
|
+
self.assertIsInstance(kilometer, UnitFactor)
|
|
335
340
|
self.assertEqual(kilometer.scale, Scale.kilo)
|
|
336
341
|
self.assertEqual(kilometer.dimension, Dimension.length)
|
|
337
342
|
self.assertIn('meter', kilometer.name)
|
|
@@ -467,70 +472,63 @@ class TestUnit(unittest.TestCase):
|
|
|
467
472
|
self.assertFalse(Unit("m", dimension=Dimension.length) == "meter")
|
|
468
473
|
|
|
469
474
|
|
|
470
|
-
class
|
|
475
|
+
class TestUnitProduct(unittest.TestCase):
|
|
476
|
+
|
|
477
|
+
mf = UnitFactor(unit=units.meter, scale=Scale.one)
|
|
478
|
+
sf = UnitFactor(unit=units.second, scale=Scale.one)
|
|
479
|
+
nf = UnitFactor(unit=units.none, scale=Scale.one)
|
|
480
|
+
velocity = UnitProduct({mf: 1, sf: -1})
|
|
481
|
+
acceleration = UnitProduct({mf: 1, sf: -2})
|
|
482
|
+
|
|
471
483
|
def test_composite_unit_collapses_to_unit(self):
|
|
472
|
-
|
|
473
|
-
cu = CompositeUnit({u: 1})
|
|
484
|
+
cu = UnitProduct({self.mf: 1})
|
|
474
485
|
# should anneal to Unit
|
|
475
|
-
self.assertIsInstance(cu,
|
|
476
|
-
self.assertEqual(cu.shorthand,
|
|
486
|
+
self.assertIsInstance(cu, UnitProduct)
|
|
487
|
+
self.assertEqual(cu.shorthand, self.mf.shorthand)
|
|
477
488
|
|
|
478
489
|
def test_merge_of_identical_units(self):
|
|
479
|
-
m = Unit("m", name="meter", dimension=Dimension.length)
|
|
480
490
|
# Inner composite that already has m^1
|
|
481
|
-
inner =
|
|
491
|
+
inner = UnitProduct({self.mf: 1, self.sf: -1})
|
|
482
492
|
# Outer composite sees both `m:1` and `inner:1`
|
|
483
|
-
|
|
493
|
+
up = UnitProduct({self.mf: 1, inner: 1})
|
|
484
494
|
# merge_unit should accumulate the exponents → m^(1 + 1) = m^2
|
|
485
|
-
self.assertIn(
|
|
486
|
-
self.assertEqual(
|
|
495
|
+
self.assertIn(self.mf, up.factors)
|
|
496
|
+
self.assertEqual(up.factors[self.mf], 2)
|
|
487
497
|
|
|
488
498
|
def test_merge_of_nested_composite_units(self):
|
|
489
|
-
m = Unit("m", dimension=Dimension.length)
|
|
490
|
-
s = Unit("s", dimension=Dimension.time)
|
|
491
|
-
velocity = CompositeUnit({m: 1, s: -1})
|
|
492
|
-
accel = CompositeUnit({velocity: 1, s: -1})
|
|
493
499
|
# expect m*s^-2
|
|
494
|
-
self.assertEqual(
|
|
495
|
-
self.assertEqual(
|
|
500
|
+
self.assertEqual(self.acceleration.factors[self.mf], 1)
|
|
501
|
+
self.assertEqual(self.acceleration.factors[self.sf], -2)
|
|
496
502
|
|
|
497
503
|
def test_drop_dimensionless_component(self):
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
self.
|
|
508
|
-
self.assertEqual(
|
|
504
|
+
up = UnitProduct({self.mf: 2, self.nf: 1})
|
|
505
|
+
self.assertIn(self.mf, up.factors)
|
|
506
|
+
self.assertNotIn(self.nf, up.factors)
|
|
507
|
+
|
|
508
|
+
def test_unitproduct_can_behave_like_single_unit(self):
|
|
509
|
+
"""
|
|
510
|
+
A UnitProduct with only one factor should seem like that factor.
|
|
511
|
+
"""
|
|
512
|
+
up = UnitProduct({self.mf: 1})
|
|
513
|
+
self.assertEqual(up.shorthand, self.mf.shorthand)
|
|
514
|
+
self.assertEqual(up.dimension, self.mf.dimension)
|
|
509
515
|
|
|
510
516
|
def test_composite_mul_with_scale(self):
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
cu = CompositeUnit({m: 1, s: -1})
|
|
514
|
-
result = Scale.kilo * cu
|
|
517
|
+
up = UnitProduct({self.mf: 1, self.sf: -1})
|
|
518
|
+
result = Scale.kilo * up
|
|
515
519
|
# equivalent to scale multiplication on RMUL path
|
|
516
520
|
self.assertIsNotNone(result)
|
|
517
521
|
self.assertIsNotNone(result.shorthand, "km/s")
|
|
518
522
|
|
|
519
523
|
def test_composite_div_dimensionless(self):
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
out = cu / none
|
|
524
|
-
self.assertEqual(out.components[m], 2)
|
|
524
|
+
up = UnitProduct({self.mf: 2})
|
|
525
|
+
out = up / UnitProduct({})
|
|
526
|
+
self.assertEqual(out.factors[self.mf], 2)
|
|
525
527
|
|
|
526
528
|
def test_truediv_composite_by_composite(self):
|
|
527
|
-
|
|
528
|
-
s = Unit("s", dimension=Dimension.time)
|
|
529
|
-
velocity = CompositeUnit({m: 1, s: -1})
|
|
530
|
-
accel = CompositeUnit({m: 1, s: -2})
|
|
531
|
-
jerk = accel / velocity
|
|
529
|
+
jerk = self.acceleration / self.velocity
|
|
532
530
|
# jerk = m^1 s^-2 / m^1 s^-1 = s^-1
|
|
533
|
-
self.assertEqual(list(jerk.
|
|
531
|
+
self.assertEqual(list(jerk.factors.values()), [-1])
|
|
534
532
|
|
|
535
533
|
|
|
536
534
|
class TestUnitEdgeCases(unittest.TestCase):
|
|
@@ -574,7 +572,7 @@ class TestUnitEdgeCases(unittest.TestCase):
|
|
|
574
572
|
m = Unit('m', name='meter', dimension=Dimension.length)
|
|
575
573
|
s = Unit('s', name='second', dimension=Dimension.time)
|
|
576
574
|
v = m / s
|
|
577
|
-
self.assertIsInstance(v,
|
|
575
|
+
self.assertIsInstance(v, UnitProduct)
|
|
578
576
|
self.assertEqual(v.dimension, Dimension.velocity)
|
|
579
577
|
self.assertIn('/', repr(v))
|
|
580
578
|
|
|
@@ -602,8 +600,8 @@ class TestUnitEdgeCases(unittest.TestCase):
|
|
|
602
600
|
m = Unit('m', name='meter', dimension=Dimension.length)
|
|
603
601
|
c = Unit('C', name='coulomb', dimension=Dimension.charge)
|
|
604
602
|
# The result of combination gives CompositeUnit
|
|
605
|
-
self.assertIsInstance(m / c,
|
|
606
|
-
self.assertIsInstance(m * c,
|
|
603
|
+
self.assertIsInstance(m / c, UnitProduct)
|
|
604
|
+
self.assertIsInstance(m * c, UnitProduct)
|
|
607
605
|
|
|
608
606
|
# --- equality, hashing, immutability ----------------------------------
|
|
609
607
|
|
|
@@ -672,3 +670,159 @@ class TestScaleEdgeCases(unittest.TestCase):
|
|
|
672
670
|
all_map = Scale.all()
|
|
673
671
|
by_val = Scale.by_value()
|
|
674
672
|
self.assertTrue(all((val in by_val.values()) for _, val in all_map.items()))
|
|
673
|
+
|
|
674
|
+
def test_descriptor_property(self):
|
|
675
|
+
self.assertIsInstance(Scale.kilo.descriptor, ScaleDescriptor)
|
|
676
|
+
self.assertEqual(Scale.kilo.descriptor, Scale.kilo.value)
|
|
677
|
+
|
|
678
|
+
def test_alias_property(self):
|
|
679
|
+
self.assertEqual(Scale.kilo.alias, "kilo")
|
|
680
|
+
self.assertEqual(Scale.one.alias, "")
|
|
681
|
+
|
|
682
|
+
def test_scale_descriptor_parts(self):
|
|
683
|
+
self.assertEqual(Scale.kilo.value.parts(), (10, 3))
|
|
684
|
+
self.assertEqual(Scale.kibi.value.parts(), (2, 10))
|
|
685
|
+
|
|
686
|
+
def test_scale_hash_used_in_sets(self):
|
|
687
|
+
s = {Scale.kilo, Scale.milli}
|
|
688
|
+
self.assertIn(Scale.kilo, s)
|
|
689
|
+
self.assertNotIn(Scale.one, s)
|
|
690
|
+
|
|
691
|
+
def test_scale_mul_nonmatching_falls_to_nearest(self):
|
|
692
|
+
# kilo * kibi → no exact match, falls through to Scale.nearest
|
|
693
|
+
result = Scale.kilo * Scale.kibi
|
|
694
|
+
self.assertIsInstance(result, Scale)
|
|
695
|
+
|
|
696
|
+
def test_scale_pow(self):
|
|
697
|
+
result = Scale.kilo ** 2
|
|
698
|
+
self.assertEqual(result, Scale.mega)
|
|
699
|
+
|
|
700
|
+
def test_scale_pow_binary(self):
|
|
701
|
+
result = Scale.kibi ** 2
|
|
702
|
+
self.assertEqual(result, Scale.mebi)
|
|
703
|
+
|
|
704
|
+
def test_scale_pow_nonmatching_falls_to_nearest(self):
|
|
705
|
+
result = Scale.kilo ** 0.5
|
|
706
|
+
self.assertIsInstance(result, Scale)
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
class TestUnitAlgebra(unittest.TestCase):
|
|
710
|
+
|
|
711
|
+
def test_unit_mul_unitproduct(self):
|
|
712
|
+
m = units.meter
|
|
713
|
+
velocity = UnitProduct({m: 1, units.second: -1})
|
|
714
|
+
result = m * velocity
|
|
715
|
+
self.assertIsInstance(result, UnitProduct)
|
|
716
|
+
# m * (m/s) = m²/s
|
|
717
|
+
self.assertEqual(result.dimension, Dimension.area / Dimension.time)
|
|
718
|
+
|
|
719
|
+
def test_unit_mul_non_unit_returns_not_implemented(self):
|
|
720
|
+
result = units.meter.__mul__("not a unit")
|
|
721
|
+
self.assertIs(result, NotImplemented)
|
|
722
|
+
|
|
723
|
+
def test_unit_truediv_non_unit_returns_not_implemented(self):
|
|
724
|
+
result = units.meter.__truediv__("not a unit")
|
|
725
|
+
self.assertIs(result, NotImplemented)
|
|
726
|
+
|
|
727
|
+
def test_unit_pow(self):
|
|
728
|
+
m = units.meter
|
|
729
|
+
result = m ** 2
|
|
730
|
+
self.assertIsInstance(result, UnitProduct)
|
|
731
|
+
self.assertEqual(result.dimension, Dimension.area)
|
|
732
|
+
|
|
733
|
+
def test_unit_pow_3(self):
|
|
734
|
+
m = units.meter
|
|
735
|
+
result = m ** 3
|
|
736
|
+
self.assertEqual(result.dimension, Dimension.volume)
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
class TestUnitFactorCoverage(unittest.TestCase):
|
|
740
|
+
|
|
741
|
+
def test_shorthand_name_fallback(self):
|
|
742
|
+
# UnitFactor where unit has no aliases but has a name
|
|
743
|
+
u = Unit(name='gram', dimension=Dimension.mass)
|
|
744
|
+
fu = UnitFactor(unit=u, scale=Scale.milli)
|
|
745
|
+
self.assertEqual(fu.shorthand, 'mgram')
|
|
746
|
+
|
|
747
|
+
def test_repr(self):
|
|
748
|
+
fu = UnitFactor(unit=units.meter, scale=Scale.kilo)
|
|
749
|
+
self.assertIn('UnitFactor', repr(fu))
|
|
750
|
+
self.assertIn('kilo', repr(fu))
|
|
751
|
+
|
|
752
|
+
def test_eq_non_unit_returns_not_implemented(self):
|
|
753
|
+
fu = UnitFactor(unit=units.meter, scale=Scale.one)
|
|
754
|
+
self.assertIs(fu.__eq__("string"), NotImplemented)
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
class TestUnitProductAlgebra(unittest.TestCase):
|
|
758
|
+
|
|
759
|
+
def test_mul_unitproduct_by_unitproduct(self):
|
|
760
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
761
|
+
time_sq = UnitProduct({units.second: 2})
|
|
762
|
+
result = velocity * time_sq
|
|
763
|
+
self.assertIsInstance(result, UnitProduct)
|
|
764
|
+
# (m/s) * s² = m·s
|
|
765
|
+
self.assertEqual(result.dimension, Dimension.length * Dimension.time)
|
|
766
|
+
|
|
767
|
+
def test_mul_unitproduct_by_scale_returns_not_implemented(self):
|
|
768
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
769
|
+
result = velocity.__mul__(Scale.kilo)
|
|
770
|
+
self.assertIs(result, NotImplemented)
|
|
771
|
+
|
|
772
|
+
def test_mul_unitproduct_by_non_unit_returns_not_implemented(self):
|
|
773
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
774
|
+
result = velocity.__mul__("string")
|
|
775
|
+
self.assertIs(result, NotImplemented)
|
|
776
|
+
|
|
777
|
+
def test_truediv_unitproduct_by_unitproduct(self):
|
|
778
|
+
acceleration = UnitProduct({units.meter: 1, units.second: -2})
|
|
779
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
780
|
+
result = acceleration / velocity
|
|
781
|
+
self.assertIsInstance(result, UnitProduct)
|
|
782
|
+
# (m/s²) / (m/s) = 1/s
|
|
783
|
+
self.assertEqual(result.dimension, Dimension.frequency)
|
|
784
|
+
|
|
785
|
+
def test_rmul_unit_times_unitproduct(self):
|
|
786
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
787
|
+
result = units.meter * velocity
|
|
788
|
+
self.assertIsInstance(result, UnitProduct)
|
|
789
|
+
|
|
790
|
+
def test_rmul_scale_on_empty_unitproduct(self):
|
|
791
|
+
empty = UnitProduct({})
|
|
792
|
+
result = Scale.kilo * empty
|
|
793
|
+
self.assertIs(result, empty)
|
|
794
|
+
|
|
795
|
+
def test_rmul_scale_applies_to_sink_unit(self):
|
|
796
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
797
|
+
result = Scale.kilo * velocity
|
|
798
|
+
self.assertIsInstance(result, UnitProduct)
|
|
799
|
+
self.assertIn('km', result.shorthand)
|
|
800
|
+
|
|
801
|
+
def test_rmul_scale_combines_with_existing_scale(self):
|
|
802
|
+
km_per_s = Scale.kilo * UnitProduct({units.meter: 1, units.second: -1})
|
|
803
|
+
# Apply another scale on top → should combine scales
|
|
804
|
+
result = Scale.milli * km_per_s
|
|
805
|
+
self.assertIsInstance(result, UnitProduct)
|
|
806
|
+
|
|
807
|
+
def test_rmul_non_unit_returns_not_implemented(self):
|
|
808
|
+
velocity = UnitProduct({units.meter: 1, units.second: -1})
|
|
809
|
+
result = velocity.__rmul__("string")
|
|
810
|
+
self.assertIs(result, NotImplemented)
|
|
811
|
+
|
|
812
|
+
def test_append_dimensionless_skipped(self):
|
|
813
|
+
# UnitProduct with only dimensionless factor → empty shorthand
|
|
814
|
+
up = UnitProduct({})
|
|
815
|
+
self.assertEqual(up.shorthand, "")
|
|
816
|
+
|
|
817
|
+
def test_shorthand_with_negative_non_unit_exponent(self):
|
|
818
|
+
# e.g. m/s² should show superscript on denominator
|
|
819
|
+
accel = UnitProduct({units.meter: 1, units.second: -2})
|
|
820
|
+
sh = accel.shorthand
|
|
821
|
+
self.assertIn('m', sh)
|
|
822
|
+
self.assertIn('s', sh)
|
|
823
|
+
|
|
824
|
+
def test_shorthand_numerator_exponent(self):
|
|
825
|
+
area = UnitProduct({units.meter: 2})
|
|
826
|
+
self.assertIn('m', area.shorthand)
|
|
827
|
+
# Should contain superscript 2
|
|
828
|
+
self.assertIn('²', area.shorthand)
|