siderust-js 0.1.0

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.
Files changed (272) hide show
  1. package/.github/workflows/ci.yml +166 -0
  2. package/.gitmodules +9 -0
  3. package/CHANGELOG.md +26 -0
  4. package/LICENSE +661 -0
  5. package/README.md +138 -0
  6. package/package.json +12 -0
  7. package/qtty-js/.github/workflows/ci.yml +151 -0
  8. package/qtty-js/.gitmodules +3 -0
  9. package/qtty-js/CHANGELOG.md +31 -0
  10. package/qtty-js/LICENSE +661 -0
  11. package/qtty-js/README.md +132 -0
  12. package/qtty-js/package.json +20 -0
  13. package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
  14. package/qtty-js/qtty/CHANGELOG.md +120 -0
  15. package/qtty-js/qtty/Cargo.lock +1462 -0
  16. package/qtty-js/qtty/Cargo.toml +12 -0
  17. package/qtty-js/qtty/LICENSE +661 -0
  18. package/qtty-js/qtty/README.md +9 -0
  19. package/qtty-js/qtty/qtty/Cargo.toml +41 -0
  20. package/qtty-js/qtty/qtty/README.md +8 -0
  21. package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
  22. package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
  23. package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
  24. package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
  25. package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
  26. package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
  27. package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
  28. package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
  29. package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
  30. package/qtty-js/qtty/qtty/src/f32.rs +108 -0
  31. package/qtty-js/qtty/qtty/src/f64.rs +30 -0
  32. package/qtty-js/qtty/qtty/src/i128.rs +111 -0
  33. package/qtty-js/qtty/qtty/src/i16.rs +111 -0
  34. package/qtty-js/qtty/qtty/src/i32.rs +111 -0
  35. package/qtty-js/qtty/qtty/src/i64.rs +111 -0
  36. package/qtty-js/qtty/qtty/src/i8.rs +111 -0
  37. package/qtty-js/qtty/qtty/src/lib.rs +238 -0
  38. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
  39. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
  40. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
  41. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
  42. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
  43. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
  44. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
  45. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
  46. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
  47. package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
  48. package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
  49. package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
  50. package/qtty-js/qtty/qtty-core/README.md +8 -0
  51. package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
  52. package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
  53. package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
  54. package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
  55. package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
  56. package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
  57. package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
  58. package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
  59. package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
  60. package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
  61. package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
  62. package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
  63. package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
  64. package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
  65. package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
  66. package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
  67. package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
  68. package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
  69. package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
  70. package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
  71. package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
  72. package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
  73. package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
  74. package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
  75. package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
  76. package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
  77. package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
  78. package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
  79. package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
  80. package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
  81. package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
  82. package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
  83. package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
  84. package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
  85. package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
  86. package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
  87. package/qtty-js/qtty/qtty-derive/README.md +8 -0
  88. package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
  89. package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
  90. package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
  91. package/qtty-js/qtty/qtty-ffi/README.md +9 -0
  92. package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
  93. package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
  94. package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
  95. package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
  96. package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
  97. package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
  98. package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
  99. package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
  100. package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
  101. package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
  102. package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
  103. package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
  104. package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
  105. package/qtty-js/qtty-node/.prettierignore +6 -0
  106. package/qtty-js/qtty-node/.prettierrc.json +6 -0
  107. package/qtty-js/qtty-node/README.md +250 -0
  108. package/qtty-js/qtty-node/c8.config.json +11 -0
  109. package/qtty-js/qtty-node/eslint.config.js +31 -0
  110. package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
  111. package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
  112. package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
  113. package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
  114. package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
  115. package/qtty-js/qtty-node/index.d.ts +219 -0
  116. package/qtty-js/qtty-node/index.js +323 -0
  117. package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
  118. package/qtty-js/qtty-node/lib/Quantity.js +151 -0
  119. package/qtty-js/qtty-node/lib/backend.js +25 -0
  120. package/qtty-js/qtty-node/native.cjs +306 -0
  121. package/qtty-js/qtty-node/package-lock.json +3223 -0
  122. package/qtty-js/qtty-node/package.json +70 -0
  123. package/qtty-js/qtty-node/units.d.ts +299 -0
  124. package/qtty-js/qtty-node/units.js +210 -0
  125. package/qtty-js/qtty-web/Cargo.lock +767 -0
  126. package/qtty-js/qtty-web/Cargo.toml +21 -0
  127. package/qtty-js/qtty-web/index.d.ts +140 -0
  128. package/qtty-js/qtty-web/index.js +20 -0
  129. package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
  130. package/qtty-js/qtty-web/lib/Quantity.js +75 -0
  131. package/qtty-js/qtty-web/lib/backend.js +80 -0
  132. package/qtty-js/qtty-web/package.json +45 -0
  133. package/qtty-js/qtty-web/src/lib.rs +111 -0
  134. package/qtty-js/scripts/ci.sh +73 -0
  135. package/scripts/ci.sh +123 -0
  136. package/siderust-core/Cargo.lock +787 -0
  137. package/siderust-core/Cargo.toml +18 -0
  138. package/siderust-core/DEDUPLICATION.md +124 -0
  139. package/siderust-core/src/body.rs +120 -0
  140. package/siderust-core/src/events.rs +184 -0
  141. package/siderust-core/src/lib.rs +20 -0
  142. package/siderust-core/src/observer.rs +55 -0
  143. package/siderust-core/src/position.rs +213 -0
  144. package/siderust-node/.prettierignore +7 -0
  145. package/siderust-node/.prettierrc.json +6 -0
  146. package/siderust-node/Cargo.lock +906 -0
  147. package/siderust-node/Cargo.toml +29 -0
  148. package/siderust-node/README.md +109 -0
  149. package/siderust-node/__test__/index.test.mjs +248 -0
  150. package/siderust-node/build.rs +5 -0
  151. package/siderust-node/c8.config.json +3 -0
  152. package/siderust-node/eslint.config.js +31 -0
  153. package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
  154. package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
  155. package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
  156. package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
  157. package/siderust-node/examples/05_target_tracking.mjs +22 -0
  158. package/siderust-node/examples/06_night_events.mjs +18 -0
  159. package/siderust-node/examples/07_moon_properties.mjs +21 -0
  160. package/siderust-node/examples/08_solar_system.mjs +19 -0
  161. package/siderust-node/examples/09_star_observability.mjs +22 -0
  162. package/siderust-node/examples/10_time_periods.mjs +9 -0
  163. package/siderust-node/examples/11_serialization.mjs +31 -0
  164. package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
  165. package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
  166. package/siderust-node/index.d.ts +623 -0
  167. package/siderust-node/index.js +79 -0
  168. package/siderust-node/lib/Observer.js +112 -0
  169. package/siderust-node/lib/Star.js +118 -0
  170. package/siderust-node/lib/backend.js +63 -0
  171. package/siderust-node/lib/wrappers.js +566 -0
  172. package/siderust-node/main.js +20 -0
  173. package/siderust-node/native.cjs +360 -0
  174. package/siderust-node/package-lock.json +3261 -0
  175. package/siderust-node/package.json +71 -0
  176. package/siderust-node/src/body.rs +74 -0
  177. package/siderust-node/src/coordinates.rs +372 -0
  178. package/siderust-node/src/ephemeris.rs +462 -0
  179. package/siderust-node/src/events.rs +577 -0
  180. package/siderust-node/src/lib.rs +43 -0
  181. package/siderust-node/src/observer.rs +132 -0
  182. package/siderust-node/src/phase.rs +218 -0
  183. package/siderust-node/src/position.rs +292 -0
  184. package/siderust-node/src/star.rs +200 -0
  185. package/siderust-web/Cargo.lock +855 -0
  186. package/siderust-web/Cargo.toml +34 -0
  187. package/siderust-web/README.md +100 -0
  188. package/siderust-web/__test__/index.test.mjs +118 -0
  189. package/siderust-web/examples/github-pages/README.md +31 -0
  190. package/siderust-web/examples/github-pages/index.html +135 -0
  191. package/siderust-web/index.d.ts +311 -0
  192. package/siderust-web/index.js +66 -0
  193. package/siderust-web/lib/Observer.js +103 -0
  194. package/siderust-web/lib/Star.js +116 -0
  195. package/siderust-web/lib/backend.js +400 -0
  196. package/siderust-web/lib/wrappers.js +512 -0
  197. package/siderust-web/package.json +55 -0
  198. package/siderust-web/src/body.rs +69 -0
  199. package/siderust-web/src/coordinates.rs +302 -0
  200. package/siderust-web/src/ephemeris.rs +456 -0
  201. package/siderust-web/src/events.rs +520 -0
  202. package/siderust-web/src/lib.rs +51 -0
  203. package/siderust-web/src/observer.rs +117 -0
  204. package/siderust-web/src/phase.rs +190 -0
  205. package/siderust-web/src/position.rs +291 -0
  206. package/siderust-web/src/star.rs +178 -0
  207. package/tempoch-js/.github/workflows/ci.yml +142 -0
  208. package/tempoch-js/.gitmodules +3 -0
  209. package/tempoch-js/CHANGELOG.md +25 -0
  210. package/tempoch-js/LICENSE +661 -0
  211. package/tempoch-js/README.md +126 -0
  212. package/tempoch-js/package.json +20 -0
  213. package/tempoch-js/scripts/ci.sh +73 -0
  214. package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
  215. package/tempoch-js/tempoch/CHANGELOG.md +82 -0
  216. package/tempoch-js/tempoch/Cargo.lock +947 -0
  217. package/tempoch-js/tempoch/Cargo.toml +3 -0
  218. package/tempoch-js/tempoch/LICENSE +661 -0
  219. package/tempoch-js/tempoch/README.md +76 -0
  220. package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
  221. package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
  222. package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
  223. package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
  224. package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
  225. package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
  226. package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
  227. package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
  228. package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
  229. package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
  230. package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
  231. package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
  232. package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
  233. package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
  234. package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
  235. package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
  236. package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
  237. package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
  238. package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
  239. package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
  240. package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
  241. package/tempoch-js/tempoch-node/.prettierignore +6 -0
  242. package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
  243. package/tempoch-js/tempoch-node/Cargo.lock +496 -0
  244. package/tempoch-js/tempoch-node/Cargo.toml +29 -0
  245. package/tempoch-js/tempoch-node/README.md +265 -0
  246. package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
  247. package/tempoch-js/tempoch-node/build.rs +5 -0
  248. package/tempoch-js/tempoch-node/c8.config.json +3 -0
  249. package/tempoch-js/tempoch-node/eslint.config.js +31 -0
  250. package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
  251. package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
  252. package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
  253. package/tempoch-js/tempoch-node/index.d.ts +280 -0
  254. package/tempoch-js/tempoch-node/index.js +32 -0
  255. package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
  256. package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
  257. package/tempoch-js/tempoch-node/lib/Period.js +133 -0
  258. package/tempoch-js/tempoch-node/lib/backend.js +38 -0
  259. package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
  260. package/tempoch-js/tempoch-node/native.cjs +317 -0
  261. package/tempoch-js/tempoch-node/package-lock.json +3223 -0
  262. package/tempoch-js/tempoch-node/package.json +56 -0
  263. package/tempoch-js/tempoch-node/src/lib.rs +573 -0
  264. package/tempoch-js/tempoch-web/Cargo.toml +23 -0
  265. package/tempoch-js/tempoch-web/index.d.ts +95 -0
  266. package/tempoch-js/tempoch-web/index.js +27 -0
  267. package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
  268. package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
  269. package/tempoch-js/tempoch-web/lib/Period.js +121 -0
  270. package/tempoch-js/tempoch-web/lib/backend.js +118 -0
  271. package/tempoch-js/tempoch-web/package.json +46 -0
  272. package/tempoch-js/tempoch-web/src/lib.rs +184 -0
@@ -0,0 +1,334 @@
1
+ #![cfg(feature = "pyo3")]
2
+
3
+ use pyo3::prelude::*;
4
+ use pyo3::types::PyFloat;
5
+ use qtty_core::*;
6
+
7
+ // Use Length as the test dimension.
8
+ type TestDim = Length;
9
+
10
+ #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
11
+ pub enum TestUnit {}
12
+ impl Unit for TestUnit {
13
+ const RATIO: f64 = 1.0;
14
+ type Dim = TestDim;
15
+ const SYMBOL: &'static str = "tu";
16
+ }
17
+
18
+ #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
19
+ pub enum DoubleTestUnit {}
20
+ impl Unit for DoubleTestUnit {
21
+ const RATIO: f64 = 2.0;
22
+ type Dim = TestDim;
23
+ const SYMBOL: &'static str = "dtu";
24
+ }
25
+
26
+ #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
27
+ pub enum HalfTestUnit {}
28
+ impl Unit for HalfTestUnit {
29
+ const RATIO: f64 = 0.5;
30
+ type Dim = TestDim;
31
+ const SYMBOL: &'static str = "htu";
32
+ }
33
+
34
+ type TU = Quantity<TestUnit>;
35
+ type Dtu = Quantity<DoubleTestUnit>;
36
+
37
+ /// Helper to initialize Python once for tests
38
+ fn with_py<F, R>(f: F) -> R
39
+ where
40
+ F: for<'py> FnOnce(Python<'py>) -> R,
41
+ {
42
+ Python::initialize();
43
+ Python::attach(f)
44
+ }
45
+
46
+ #[test]
47
+ fn into_pyobject_basic() {
48
+ with_py(|py| {
49
+ let q = TU::new(42.5);
50
+ let py_obj = q.into_pyobject(py).unwrap();
51
+ let value: f64 = py_obj.extract().unwrap();
52
+ assert_eq!(value, 42.5);
53
+ });
54
+ }
55
+
56
+ #[test]
57
+ fn into_pyobject_negative() {
58
+ with_py(|py| {
59
+ let q = TU::new(-123.456);
60
+ let py_obj = q.into_pyobject(py).unwrap();
61
+ let value: f64 = py_obj.extract().unwrap();
62
+ assert_eq!(value, -123.456);
63
+ });
64
+ }
65
+
66
+ #[test]
67
+ fn into_pyobject_zero() {
68
+ with_py(|py| {
69
+ let q = TU::new(0.0);
70
+ let py_obj = q.into_pyobject(py).unwrap();
71
+ let value: f64 = py_obj.extract().unwrap();
72
+ assert_eq!(value, 0.0);
73
+ });
74
+ }
75
+
76
+ #[test]
77
+ fn into_pyobject_infinity() {
78
+ with_py(|py| {
79
+ let q = TU::new(f64::INFINITY);
80
+ let py_obj = q.into_pyobject(py).unwrap();
81
+ let value: f64 = py_obj.extract().unwrap();
82
+ assert!(value.is_infinite() && value.is_sign_positive());
83
+ });
84
+ }
85
+
86
+ #[test]
87
+ fn into_pyobject_neg_infinity() {
88
+ with_py(|py| {
89
+ let q = TU::new(f64::NEG_INFINITY);
90
+ let py_obj = q.into_pyobject(py).unwrap();
91
+ let value: f64 = py_obj.extract().unwrap();
92
+ assert!(value.is_infinite() && value.is_sign_negative());
93
+ });
94
+ }
95
+
96
+ #[test]
97
+ fn into_pyobject_nan() {
98
+ with_py(|py| {
99
+ let q = TU::new(f64::NAN);
100
+ let py_obj = q.into_pyobject(py).unwrap();
101
+ let value: f64 = py_obj.extract().unwrap();
102
+ assert!(value.is_nan());
103
+ });
104
+ }
105
+
106
+ #[test]
107
+ fn into_pyobject_very_large() {
108
+ with_py(|py| {
109
+ let q = TU::new(1e100);
110
+ let py_obj = q.into_pyobject(py).unwrap();
111
+ let value: f64 = py_obj.extract().unwrap();
112
+ assert_eq!(value, 1e100);
113
+ });
114
+ }
115
+
116
+ #[test]
117
+ fn into_pyobject_very_small() {
118
+ with_py(|py| {
119
+ let q = TU::new(1e-100);
120
+ let py_obj = q.into_pyobject(py).unwrap();
121
+ let value: f64 = py_obj.extract().unwrap();
122
+ assert_eq!(value, 1e-100);
123
+ });
124
+ }
125
+
126
+ #[test]
127
+ fn from_pyobject_basic() {
128
+ with_py(|py| {
129
+ let py_float = PyFloat::new(py, 42.5);
130
+ let q: TU = py_float.extract().unwrap();
131
+ assert_eq!(q.value(), 42.5);
132
+ });
133
+ }
134
+
135
+ #[test]
136
+ fn from_pyobject_negative() {
137
+ with_py(|py| {
138
+ let py_float = PyFloat::new(py, -123.456);
139
+ let q: TU = py_float.extract().unwrap();
140
+ assert_eq!(q.value(), -123.456);
141
+ });
142
+ }
143
+
144
+ #[test]
145
+ fn from_pyobject_zero() {
146
+ with_py(|py| {
147
+ let py_float = PyFloat::new(py, 0.0);
148
+ let q: TU = py_float.extract().unwrap();
149
+ assert_eq!(q.value(), 0.0);
150
+ });
151
+ }
152
+
153
+ #[test]
154
+ fn from_pyobject_infinity() {
155
+ with_py(|py| {
156
+ let py_float = PyFloat::new(py, f64::INFINITY);
157
+ let q: TU = py_float.extract().unwrap();
158
+ assert!(q.value().is_infinite() && q.value().is_sign_positive());
159
+ });
160
+ }
161
+
162
+ #[test]
163
+ fn from_pyobject_neg_infinity() {
164
+ with_py(|py| {
165
+ let py_float = PyFloat::new(py, f64::NEG_INFINITY);
166
+ let q: TU = py_float.extract().unwrap();
167
+ assert!(q.value().is_infinite() && q.value().is_sign_negative());
168
+ });
169
+ }
170
+
171
+ #[test]
172
+ fn from_pyobject_nan() {
173
+ with_py(|py| {
174
+ let py_float = PyFloat::new(py, f64::NAN);
175
+ let q: TU = py_float.extract().unwrap();
176
+ assert!(q.value().is_nan());
177
+ });
178
+ }
179
+
180
+ #[test]
181
+ fn from_pyobject_very_large() {
182
+ with_py(|py| {
183
+ let py_float = PyFloat::new(py, 1e100);
184
+ let q: TU = py_float.extract().unwrap();
185
+ assert_eq!(q.value(), 1e100);
186
+ });
187
+ }
188
+
189
+ #[test]
190
+ fn from_pyobject_very_small() {
191
+ with_py(|py| {
192
+ let py_float = PyFloat::new(py, 1e-100);
193
+ let q: TU = py_float.extract().unwrap();
194
+ assert_eq!(q.value(), 1e-100);
195
+ });
196
+ }
197
+
198
+ #[test]
199
+ fn roundtrip_basic() {
200
+ with_py(|py| {
201
+ let original = TU::new(123.456);
202
+ let py_obj = original.into_pyobject(py).unwrap();
203
+ let restored: TU = py_obj.extract().unwrap();
204
+ assert!((restored.value() - original.value()).abs() < 1e-12);
205
+ });
206
+ }
207
+
208
+ #[test]
209
+ fn roundtrip_negative() {
210
+ with_py(|py| {
211
+ let original = TU::new(-987.654);
212
+ let py_obj = original.into_pyobject(py).unwrap();
213
+ let restored: TU = py_obj.extract().unwrap();
214
+ assert!((restored.value() - original.value()).abs() < 1e-12);
215
+ });
216
+ }
217
+
218
+ #[test]
219
+ fn roundtrip_zero() {
220
+ with_py(|py| {
221
+ let original = TU::new(0.0);
222
+ let py_obj = original.into_pyobject(py).unwrap();
223
+ let restored: TU = py_obj.extract().unwrap();
224
+ assert_eq!(restored.value(), original.value());
225
+ });
226
+ }
227
+
228
+ #[test]
229
+ fn roundtrip_very_large() {
230
+ with_py(|py| {
231
+ let original = TU::new(1e100);
232
+ let py_obj = original.into_pyobject(py).unwrap();
233
+ let restored: TU = py_obj.extract().unwrap();
234
+ assert_eq!(restored.value(), original.value());
235
+ });
236
+ }
237
+
238
+ #[test]
239
+ fn roundtrip_very_small() {
240
+ with_py(|py| {
241
+ let original = TU::new(1e-100);
242
+ let py_obj = original.into_pyobject(py).unwrap();
243
+ let restored: TU = py_obj.extract().unwrap();
244
+ assert_eq!(restored.value(), original.value());
245
+ });
246
+ }
247
+
248
+ #[test]
249
+ fn roundtrip_different_unit_types() {
250
+ with_py(|py| {
251
+ // Test with DoubleTestUnit
252
+ let original_dtu = Dtu::new(42.5);
253
+ let py_obj = original_dtu.into_pyobject(py).unwrap();
254
+ let restored_dtu: Dtu = py_obj.extract().unwrap();
255
+ assert!((restored_dtu.value() - original_dtu.value()).abs() < 1e-12);
256
+
257
+ // Test with HalfTestUnit
258
+ let original_htu = Quantity::<HalfTestUnit>::new(99.9);
259
+ let py_obj = original_htu.into_pyobject(py).unwrap();
260
+ let restored_htu: Quantity<HalfTestUnit> = py_obj.extract().unwrap();
261
+ assert!((restored_htu.value() - original_htu.value()).abs() < 1e-12);
262
+ });
263
+ }
264
+
265
+ #[test]
266
+ fn roundtrip_preserves_precision() {
267
+ with_py(|py| {
268
+ // Test that precision is preserved through conversion
269
+ let original = TU::new(core::f64::consts::PI);
270
+ let py_obj = original.into_pyobject(py).unwrap();
271
+ let restored: TU = py_obj.extract().unwrap();
272
+ assert_eq!(restored.value(), original.value());
273
+ });
274
+ }
275
+
276
+ #[test]
277
+ fn into_pyobject_returns_pyfloat() {
278
+ with_py(|py| {
279
+ let q = TU::new(42.5);
280
+ let py_obj = q.into_pyobject(py).unwrap();
281
+ // Verify it's actually a PyFloat
282
+ assert!(py_obj.is_instance_of::<PyFloat>());
283
+ });
284
+ }
285
+
286
+ #[test]
287
+ fn from_pyobject_from_int() {
288
+ with_py(|py| {
289
+ // Python integers can be converted to f64
290
+ let py_int = py.eval(c"42", None, None).unwrap();
291
+ let q: TU = py_int.extract().unwrap();
292
+ assert_eq!(q.value(), 42.0);
293
+ });
294
+ }
295
+
296
+ #[test]
297
+ fn from_pyobject_from_calculation() {
298
+ with_py(|py| {
299
+ // Extract from a Python calculation result
300
+ let py_result = py.eval(c"2.5 * 10.0", None, None).unwrap();
301
+ let q: TU = py_result.extract().unwrap();
302
+ assert_eq!(q.value(), 25.0);
303
+ });
304
+ }
305
+
306
+ #[test]
307
+ fn from_pyobject_error_on_string() {
308
+ with_py(|py| {
309
+ // Should fail to extract from a string
310
+ let py_str = py.eval(c"'not a number'", None, None).unwrap();
311
+ let result: PyResult<TU> = py_str.extract();
312
+ assert!(result.is_err());
313
+ });
314
+ }
315
+
316
+ #[test]
317
+ fn from_pyobject_error_on_none() {
318
+ with_py(|py| {
319
+ // Should fail to extract from None
320
+ let py_none = py.eval(c"None", None, None).unwrap();
321
+ let result: PyResult<TU> = py_none.extract();
322
+ assert!(result.is_err());
323
+ });
324
+ }
325
+
326
+ #[test]
327
+ fn from_pyobject_error_on_list() {
328
+ with_py(|py| {
329
+ // Should fail to extract from a list
330
+ let py_list = py.eval(c"[1, 2, 3]", None, None).unwrap();
331
+ let result: PyResult<TU> = py_list.extract();
332
+ assert!(result.is_err());
333
+ });
334
+ }
@@ -0,0 +1,276 @@
1
+ //! Tests for Quantity<U, f32> methods (coverage for quantity.rs f32 paths).
2
+
3
+ use qtty_core::*;
4
+
5
+ // Use Length as the test dimension.
6
+ type TestDim = Length;
7
+
8
+ #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
9
+ pub enum TestUnit {}
10
+ impl Unit for TestUnit {
11
+ const RATIO: f64 = 1.0;
12
+ type Dim = TestDim;
13
+ const SYMBOL: &'static str = "tu";
14
+ }
15
+
16
+ #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
17
+ pub enum DoubleTestUnit {}
18
+ impl Unit for DoubleTestUnit {
19
+ const RATIO: f64 = 2.0;
20
+ type Dim = TestDim;
21
+ const SYMBOL: &'static str = "dtu";
22
+ }
23
+
24
+ type TU32 = Quantity<TestUnit, f32>;
25
+
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ // Const methods for f32
28
+ // ─────────────────────────────────────────────────────────────────────────────
29
+
30
+ #[test]
31
+ fn f32_const_add() {
32
+ let a = TU32::new(3.0);
33
+ let b = TU32::new(7.0);
34
+ assert_eq!(a.const_add(b).value(), 10.0_f32);
35
+ }
36
+
37
+ #[test]
38
+ fn f32_const_sub() {
39
+ let a = TU32::new(10.0);
40
+ let b = TU32::new(3.0);
41
+ assert_eq!(a.const_sub(b).value(), 7.0_f32);
42
+ }
43
+
44
+ #[test]
45
+ fn f32_const_mul() {
46
+ let a = TU32::new(4.0);
47
+ assert_eq!(a.const_mul(5.0).value(), 20.0_f32);
48
+ }
49
+
50
+ #[test]
51
+ fn f32_const_div() {
52
+ let a = TU32::new(20.0);
53
+ assert_eq!(a.const_div(4.0).value(), 5.0_f32);
54
+ }
55
+
56
+ #[test]
57
+ fn f32_to_const() {
58
+ let q = TU32::new(10.0);
59
+ let converted: Quantity<DoubleTestUnit, f32> = q.to_const();
60
+ assert!((converted.value() - 5.0).abs() < 1e-6);
61
+ }
62
+
63
+ #[test]
64
+ fn f32_min_const() {
65
+ let a = TU32::new(3.0);
66
+ let b = TU32::new(7.0);
67
+ assert_eq!(a.min_const(b).value(), 3.0_f32);
68
+ assert_eq!(b.min_const(a).value(), 3.0_f32);
69
+ }
70
+
71
+ #[test]
72
+ fn f32_max_const() {
73
+ let a = TU32::new(3.0);
74
+ let b = TU32::new(7.0);
75
+ assert_eq!(a.max_const(b).value(), 7.0_f32);
76
+ assert_eq!(b.max_const(a).value(), 7.0_f32);
77
+ }
78
+
79
+ // ─────────────────────────────────────────────────────────────────────────────
80
+ // Real-specific Quantity methods for f32
81
+ // ─────────────────────────────────────────────────────────────────────────────
82
+
83
+ #[test]
84
+ fn f32_quantity_nan_constant() {
85
+ assert!(TU32::NAN.value().is_nan());
86
+ }
87
+
88
+ #[test]
89
+ fn f32_quantity_infinity() {
90
+ assert!(TU32::INFINITY.value().is_infinite());
91
+ assert!(TU32::NEG_INFINITY.value().is_infinite());
92
+ }
93
+
94
+ #[test]
95
+ fn f32_quantity_is_nan() {
96
+ assert!(TU32::NAN.is_nan());
97
+ assert!(!TU32::new(42.0).is_nan());
98
+ }
99
+
100
+ #[test]
101
+ fn f32_quantity_is_infinite() {
102
+ assert!(TU32::INFINITY.is_infinite());
103
+ assert!(!TU32::new(42.0).is_infinite());
104
+ }
105
+
106
+ #[test]
107
+ fn f32_quantity_is_finite() {
108
+ assert!(TU32::new(42.0).is_finite());
109
+ assert!(!TU32::INFINITY.is_finite());
110
+ assert!(!TU32::NAN.is_finite());
111
+ }
112
+
113
+ #[test]
114
+ fn f32_quantity_signum() {
115
+ assert_eq!(TU32::new(42.0).signum(), 1.0_f32);
116
+ assert_eq!(TU32::new(-42.0).signum(), -1.0_f32);
117
+ }
118
+
119
+ #[test]
120
+ fn f32_quantity_sqrt() {
121
+ let q = TU32::new(16.0);
122
+ assert!((q.sqrt().value() - 4.0).abs() < 1e-6);
123
+ }
124
+
125
+ #[test]
126
+ fn f32_quantity_ceil() {
127
+ assert_eq!(TU32::new(3.2).ceil().value(), 4.0_f32);
128
+ assert_eq!(TU32::new(-3.2).ceil().value(), -3.0_f32);
129
+ assert_eq!(TU32::new(5.0).ceil().value(), 5.0_f32);
130
+ }
131
+
132
+ #[test]
133
+ fn f32_quantity_cast() {
134
+ let q = TU32::new(42.5);
135
+ let q_f64: Quantity<TestUnit, f64> = q.cast();
136
+ assert!((q_f64.value() - 42.5).abs() < 1e-6);
137
+ }
138
+
139
+ #[test]
140
+ fn f32_quantity_to() {
141
+ let q = TU32::new(10.0);
142
+ let converted: Quantity<DoubleTestUnit, f32> = q.to();
143
+ assert!((converted.value() - 5.0).abs() < 1e-6);
144
+ }
145
+
146
+ #[test]
147
+ fn f32_quantity_abs() {
148
+ assert_eq!(TU32::new(-5.0).abs().value(), 5.0_f32);
149
+ }
150
+
151
+ #[test]
152
+ fn f32_quantity_min_max() {
153
+ let a = TU32::new(3.0);
154
+ let b = TU32::new(7.0);
155
+ assert_eq!(a.min(b).value(), 3.0_f32);
156
+ assert_eq!(a.max(b).value(), 7.0_f32);
157
+ assert_eq!(a.mean(b).value(), 5.0_f32);
158
+ }
159
+
160
+ // ─────────────────────────────────────────────────────────────────────────────
161
+ // Commutative multiplication: f32 * Quantity
162
+ // ─────────────────────────────────────────────────────────────────────────────
163
+
164
+ #[test]
165
+ fn f32_commutative_mul() {
166
+ let q = TU32::new(5.0);
167
+ assert_eq!((3.0_f32 * q).value(), 15.0_f32);
168
+ assert_eq!((q * 3.0_f32).value(), 15.0_f32);
169
+ }
170
+
171
+ // ─────────────────────────────────────────────────────────────────────────────
172
+ // Operators: Add/Sub/Neg/Div/Rem
173
+ // ─────────────────────────────────────────────────────────────────────────────
174
+
175
+ #[test]
176
+ fn f32_quantity_add_sub() {
177
+ let a = TU32::new(10.0);
178
+ let b = TU32::new(3.0);
179
+ assert_eq!((a + b).value(), 13.0_f32);
180
+ assert_eq!((a - b).value(), 7.0_f32);
181
+ }
182
+
183
+ #[test]
184
+ fn f32_quantity_neg() {
185
+ assert_eq!((-TU32::new(5.0)).value(), -5.0_f32);
186
+ }
187
+
188
+ #[test]
189
+ fn f32_quantity_div_scalar() {
190
+ assert_eq!((TU32::new(15.0) / 3.0_f32).value(), 5.0_f32);
191
+ }
192
+
193
+ #[test]
194
+ fn f32_quantity_rem() {
195
+ assert_eq!((TU32::new(10.0) % 3.0_f32).value(), 1.0_f32);
196
+ }
197
+
198
+ #[test]
199
+ fn f32_quantity_partial_eq() {
200
+ let q = TU32::new(42.0);
201
+ assert!(q == 42.0_f32);
202
+ }
203
+
204
+ #[test]
205
+ fn f32_quantity_from() {
206
+ let q: TU32 = 42.0_f32.into();
207
+ assert_eq!(q.value(), 42.0_f32);
208
+ }
209
+
210
+ #[test]
211
+ fn f32_quantity_zero_one() {
212
+ assert_eq!(TU32::zero().value(), 0.0_f32);
213
+ assert_eq!(TU32::one().value(), 1.0_f32);
214
+ }
215
+
216
+ // ─────────────────────────────────────────────────────────────────────────────
217
+ // Division producing Per type with f32
218
+ // ─────────────────────────────────────────────────────────────────────────────
219
+
220
+ #[test]
221
+ fn f32_division_creates_per() {
222
+ let num = TU32::new(100.0);
223
+ let den = Quantity::<DoubleTestUnit, f32>::new(20.0);
224
+ let ratio: Quantity<Per<TestUnit, DoubleTestUnit>, f32> = num / den;
225
+ assert!((ratio.value() - 5.0).abs() < 1e-6);
226
+ }
227
+
228
+ #[test]
229
+ fn f32_per_mul_recovers_numerator() {
230
+ let rate: Quantity<Per<TestUnit, DoubleTestUnit>, f32> = Quantity::new(5.0);
231
+ let den = Quantity::<DoubleTestUnit, f32>::new(4.0);
232
+ let result: TU32 = (rate * den).to();
233
+ assert!((result.value() - 20.0).abs() < 1e-6);
234
+ }
235
+
236
+ #[test]
237
+ fn f32_simplify() {
238
+ let ratio: Quantity<Per<TestUnit, TestUnit>, f32> = Quantity::new(2.5);
239
+ let unitless: Quantity<Unitless, f32> = ratio.simplify();
240
+ assert!((unitless.value() - 2.5).abs() < 1e-6);
241
+ }
242
+
243
+ // ─────────────────────────────────────────────────────────────────────────────
244
+ // Assign ops
245
+ // ─────────────────────────────────────────────────────────────────────────────
246
+
247
+ #[test]
248
+ fn f32_add_assign() {
249
+ let mut q = TU32::new(5.0);
250
+ q += TU32::new(3.0);
251
+ assert_eq!(q.value(), 8.0_f32);
252
+ }
253
+
254
+ #[test]
255
+ fn f32_sub_assign() {
256
+ let mut q = TU32::new(10.0);
257
+ q -= TU32::new(3.0);
258
+ assert_eq!(q.value(), 7.0_f32);
259
+ }
260
+
261
+ #[test]
262
+ fn f32_div_assign() {
263
+ let mut q = TU32::new(20.0);
264
+ q /= 4.0_f32;
265
+ assert_eq!(q.value(), 5.0_f32);
266
+ }
267
+
268
+ // ─────────────────────────────────────────────────────────────────────────────
269
+ // value_ref
270
+ // ─────────────────────────────────────────────────────────────────────────────
271
+
272
+ #[test]
273
+ fn f32_value_ref() {
274
+ let q = TU32::new(42.5);
275
+ assert_eq!(*q.value_ref(), 42.5_f32);
276
+ }