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.
- package/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
//! Integration tests for integer scalar support.
|
|
2
|
+
//!
|
|
3
|
+
//! Tests that Quantity<U, iNN> works correctly for i8, i16, i32, i64, i128
|
|
4
|
+
//! with arithmetic, Display, lossy conversion, and derived units (Per).
|
|
5
|
+
|
|
6
|
+
use qtty_core::length::{Kilometer, Meter};
|
|
7
|
+
use qtty_core::scalar::{Exact, IntegerScalar};
|
|
8
|
+
use qtty_core::time::Second;
|
|
9
|
+
use qtty_core::{Per, Quantity, QuantityI32, QuantityI64, Simplify, Unitless};
|
|
10
|
+
|
|
11
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
12
|
+
// Basic construction and value access
|
|
13
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn test_i32_quantity_new_and_value() {
|
|
17
|
+
let m: Quantity<Meter, i32> = Quantity::new(42);
|
|
18
|
+
assert_eq!(m.value(), 42);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[test]
|
|
22
|
+
fn test_i64_quantity_new_and_value() {
|
|
23
|
+
let m: Quantity<Meter, i64> = Quantity::new(1_000_000_000);
|
|
24
|
+
assert_eq!(m.value(), 1_000_000_000);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#[test]
|
|
28
|
+
fn test_i8_quantity_new_and_value() {
|
|
29
|
+
let m: Quantity<Meter, i8> = Quantity::new(100);
|
|
30
|
+
assert_eq!(m.value(), 100);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[test]
|
|
34
|
+
fn test_i16_quantity_new_and_value() {
|
|
35
|
+
let m: Quantity<Meter, i16> = Quantity::new(30_000);
|
|
36
|
+
assert_eq!(m.value(), 30_000);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#[test]
|
|
40
|
+
fn test_i128_quantity_new_and_value() {
|
|
41
|
+
let m: Quantity<Meter, i128> = Quantity::new(i128::MAX);
|
|
42
|
+
assert_eq!(m.value(), i128::MAX);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[test]
|
|
46
|
+
fn test_zero_and_one() {
|
|
47
|
+
assert_eq!(Quantity::<Meter, i32>::zero().value(), 0);
|
|
48
|
+
assert_eq!(Quantity::<Meter, i32>::one().value(), 1);
|
|
49
|
+
assert_eq!(Quantity::<Meter, i64>::zero().value(), 0_i64);
|
|
50
|
+
assert_eq!(Quantity::<Meter, i64>::one().value(), 1_i64);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// Arithmetic operations
|
|
55
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
fn test_i32_add_sub() {
|
|
59
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
60
|
+
let b = Quantity::<Meter, i32>::new(3);
|
|
61
|
+
assert_eq!((a + b).value(), 13);
|
|
62
|
+
assert_eq!((a - b).value(), 7);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[test]
|
|
66
|
+
fn test_i32_mul_div_scalar() {
|
|
67
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
68
|
+
assert_eq!((a * 3).value(), 30);
|
|
69
|
+
assert_eq!((a / 3).value(), 3); // integer truncation: 10/3 = 3
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[test]
|
|
73
|
+
fn test_i32_neg() {
|
|
74
|
+
let a = Quantity::<Meter, i32>::new(5);
|
|
75
|
+
assert_eq!((-a).value(), -5);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[test]
|
|
79
|
+
fn test_i32_abs() {
|
|
80
|
+
let a = Quantity::<Meter, i32>::new(-7);
|
|
81
|
+
assert_eq!(a.abs().value(), 7);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#[test]
|
|
85
|
+
fn test_i32_min_max() {
|
|
86
|
+
let a = Quantity::<Meter, i32>::new(3);
|
|
87
|
+
let b = Quantity::<Meter, i32>::new(7);
|
|
88
|
+
assert_eq!(a.min(b).value(), 3);
|
|
89
|
+
assert_eq!(a.max(b).value(), 7);
|
|
90
|
+
assert_eq!(a.mean(b).value(), 5);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#[test]
|
|
94
|
+
fn test_i32_add_assign() {
|
|
95
|
+
let mut a = Quantity::<Meter, i32>::new(10);
|
|
96
|
+
a += Quantity::new(5);
|
|
97
|
+
assert_eq!(a.value(), 15);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[test]
|
|
101
|
+
fn test_i32_sub_assign() {
|
|
102
|
+
let mut a = Quantity::<Meter, i32>::new(10);
|
|
103
|
+
a -= Quantity::new(3);
|
|
104
|
+
assert_eq!(a.value(), 7);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
108
|
+
// Commutative multiplication: scalar * Quantity
|
|
109
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
#[test]
|
|
112
|
+
fn test_i32_commutative_mul() {
|
|
113
|
+
let a = Quantity::<Meter, i32>::new(5);
|
|
114
|
+
assert_eq!((3_i32 * a).value(), 15);
|
|
115
|
+
assert_eq!((a * 3_i32).value(), 15);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
#[test]
|
|
119
|
+
fn test_i64_commutative_mul() {
|
|
120
|
+
let a = Quantity::<Meter, i64>::new(5);
|
|
121
|
+
assert_eq!((3_i64 * a).value(), 15);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[test]
|
|
125
|
+
fn test_i8_commutative_mul() {
|
|
126
|
+
let a = Quantity::<Meter, i8>::new(5);
|
|
127
|
+
assert_eq!((3_i8 * a).value(), 15);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
131
|
+
// Rem (modulo) for integers
|
|
132
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
#[test]
|
|
135
|
+
fn test_i32_rem() {
|
|
136
|
+
let a = Quantity::<Meter, i32>::new(17);
|
|
137
|
+
assert_eq!((a % 5).value(), 2);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[test]
|
|
141
|
+
fn test_i64_rem() {
|
|
142
|
+
let a = Quantity::<Meter, i64>::new(17);
|
|
143
|
+
assert_eq!((a % 5_i64).value(), 2);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
147
|
+
// PartialEq and From
|
|
148
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
#[test]
|
|
151
|
+
fn test_i32_partial_eq_scalar() {
|
|
152
|
+
let a = Quantity::<Meter, i32>::new(42);
|
|
153
|
+
assert_eq!(a, 42);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#[test]
|
|
157
|
+
fn test_i32_from_scalar() {
|
|
158
|
+
let a: Quantity<Meter, i32> = 42.into();
|
|
159
|
+
assert_eq!(a.value(), 42);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
// Display
|
|
164
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
165
|
+
|
|
166
|
+
#[test]
|
|
167
|
+
fn test_i32_display() {
|
|
168
|
+
let m = Quantity::<Meter, i32>::new(100);
|
|
169
|
+
assert_eq!(format!("{}", m), "100 m");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#[test]
|
|
173
|
+
fn test_i64_display() {
|
|
174
|
+
let km = Quantity::<Kilometer, i64>::new(42);
|
|
175
|
+
assert_eq!(format!("{}", km), "42 km");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
179
|
+
// Per (derived units)
|
|
180
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
#[test]
|
|
183
|
+
fn test_i32_per_division() {
|
|
184
|
+
let distance = Quantity::<Meter, i32>::new(100);
|
|
185
|
+
let time = Quantity::<Second, i32>::new(10);
|
|
186
|
+
let velocity: Quantity<Per<Meter, Second>, i32> = distance / time;
|
|
187
|
+
assert_eq!(velocity.value(), 10);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#[test]
|
|
191
|
+
fn test_i32_per_multiplication() {
|
|
192
|
+
let velocity = Quantity::<Per<Meter, Second>, i32>::new(10);
|
|
193
|
+
let time = Quantity::<Second, i32>::new(5);
|
|
194
|
+
// Blanket Mul gives Quantity<Prod<Per<Meter,Second>, Second>, i32>
|
|
195
|
+
// which has the same dimension as Meter; to_lossy converts.
|
|
196
|
+
let distance: Quantity<Meter, i32> = (velocity * time).to_lossy();
|
|
197
|
+
assert_eq!(distance.value(), 50);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#[test]
|
|
201
|
+
fn test_i32_per_display() {
|
|
202
|
+
let v = Quantity::<Per<Meter, Second>, i32>::new(10);
|
|
203
|
+
assert_eq!(format!("{}", v), "10 m/s");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
207
|
+
// Simplify (Per<U,U> -> Unitless)
|
|
208
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
209
|
+
|
|
210
|
+
#[test]
|
|
211
|
+
fn test_i32_simplify() {
|
|
212
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
213
|
+
let b = Quantity::<Meter, i32>::new(2);
|
|
214
|
+
let ratio = a / b;
|
|
215
|
+
let unitless: Quantity<Unitless, i32> = ratio.simplify();
|
|
216
|
+
assert_eq!(unitless.value(), 5);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
220
|
+
// Lossy conversion (to_lossy)
|
|
221
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
222
|
+
|
|
223
|
+
#[test]
|
|
224
|
+
fn test_i32_to_lossy_meters_to_km() {
|
|
225
|
+
let m = Quantity::<Meter, i32>::new(1500);
|
|
226
|
+
let km: Quantity<Kilometer, i32> = m.to_lossy();
|
|
227
|
+
assert_eq!(km.value(), 1); // 1500m = 1.5km, truncated to 1
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#[test]
|
|
231
|
+
fn test_i32_to_lossy_km_to_meters() {
|
|
232
|
+
let km = Quantity::<Kilometer, i32>::new(2);
|
|
233
|
+
let m: Quantity<Meter, i32> = km.to_lossy();
|
|
234
|
+
assert_eq!(m.value(), 2000);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#[test]
|
|
238
|
+
fn test_i64_to_lossy_meters_to_km() {
|
|
239
|
+
let m = Quantity::<Meter, i64>::new(5_500_000);
|
|
240
|
+
let km: Quantity<Kilometer, i64> = m.to_lossy();
|
|
241
|
+
assert_eq!(km.value(), 5500);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#[test]
|
|
245
|
+
fn test_i32_to_lossy_exact_conversion() {
|
|
246
|
+
// 3000m = 3km exactly
|
|
247
|
+
let m = Quantity::<Meter, i32>::new(3000);
|
|
248
|
+
let km: Quantity<Kilometer, i32> = m.to_lossy();
|
|
249
|
+
assert_eq!(km.value(), 3);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
253
|
+
// Const methods
|
|
254
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
255
|
+
|
|
256
|
+
#[test]
|
|
257
|
+
fn test_i32_const_add() {
|
|
258
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
259
|
+
let b = Quantity::<Meter, i32>::new(5);
|
|
260
|
+
assert_eq!(a.const_add(b).value(), 15);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#[test]
|
|
264
|
+
fn test_i32_const_sub() {
|
|
265
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
266
|
+
let b = Quantity::<Meter, i32>::new(3);
|
|
267
|
+
assert_eq!(a.const_sub(b).value(), 7);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#[test]
|
|
271
|
+
fn test_i32_const_mul() {
|
|
272
|
+
let a = Quantity::<Meter, i32>::new(5);
|
|
273
|
+
assert_eq!(a.const_mul(3).value(), 15);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#[test]
|
|
277
|
+
fn test_i32_const_div() {
|
|
278
|
+
let a = Quantity::<Meter, i32>::new(15);
|
|
279
|
+
assert_eq!(a.const_div(3).value(), 5);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#[test]
|
|
283
|
+
fn test_i32_min_max_const() {
|
|
284
|
+
let a = Quantity::<Meter, i32>::new(3);
|
|
285
|
+
let b = Quantity::<Meter, i32>::new(7);
|
|
286
|
+
assert_eq!(a.min_const(b).value(), 3);
|
|
287
|
+
assert_eq!(a.max_const(b).value(), 7);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
#[test]
|
|
291
|
+
fn test_i64_const_methods() {
|
|
292
|
+
let a = Quantity::<Meter, i64>::new(100);
|
|
293
|
+
let b = Quantity::<Meter, i64>::new(200);
|
|
294
|
+
assert_eq!(a.const_add(b).value(), 300);
|
|
295
|
+
assert_eq!(a.const_mul(3).value(), 300);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
299
|
+
// Type aliases
|
|
300
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
301
|
+
|
|
302
|
+
#[test]
|
|
303
|
+
fn test_quantity_i32_alias() {
|
|
304
|
+
let m: QuantityI32<Meter> = QuantityI32::new(42);
|
|
305
|
+
assert_eq!(m.value(), 42);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#[test]
|
|
309
|
+
fn test_quantity_i64_alias() {
|
|
310
|
+
let m: QuantityI64<Meter> = QuantityI64::new(42);
|
|
311
|
+
assert_eq!(m.value(), 42);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
315
|
+
// Trait bounds verification
|
|
316
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
317
|
+
|
|
318
|
+
#[test]
|
|
319
|
+
fn test_integer_scalar_is_exact() {
|
|
320
|
+
fn accepts_exact<S: Exact>(_: S) {}
|
|
321
|
+
accepts_exact(42_i32);
|
|
322
|
+
accepts_exact(42_i64);
|
|
323
|
+
accepts_exact(42_i8);
|
|
324
|
+
accepts_exact(42_i16);
|
|
325
|
+
accepts_exact(42_i128);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
#[test]
|
|
329
|
+
fn test_integer_scalar_marker() {
|
|
330
|
+
fn accepts_integer<S: IntegerScalar>(_: S) {}
|
|
331
|
+
accepts_integer(42_i32);
|
|
332
|
+
accepts_integer(42_i64);
|
|
333
|
+
accepts_integer(42_i8);
|
|
334
|
+
accepts_integer(42_i16);
|
|
335
|
+
accepts_integer(42_i128);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
339
|
+
// Edge cases
|
|
340
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
341
|
+
|
|
342
|
+
#[test]
|
|
343
|
+
fn test_i32_integer_division_truncation() {
|
|
344
|
+
// Verify that integer division truncates toward zero
|
|
345
|
+
let a = Quantity::<Meter, i32>::new(10);
|
|
346
|
+
assert_eq!((a / 3).value(), 3); // 10/3 = 3
|
|
347
|
+
assert_eq!((a / 4).value(), 2); // 10/4 = 2
|
|
348
|
+
assert_eq!((-a / 3).value(), -3); // -10/3 = -3
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
#[test]
|
|
352
|
+
fn test_i32_negative_quantities() {
|
|
353
|
+
let a = Quantity::<Meter, i32>::new(-10);
|
|
354
|
+
let b = Quantity::<Meter, i32>::new(3);
|
|
355
|
+
assert_eq!((a + b).value(), -7);
|
|
356
|
+
assert_eq!((a - b).value(), -13);
|
|
357
|
+
assert_eq!(a.abs().value(), 10);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#[test]
|
|
361
|
+
fn test_i32_div_assign() {
|
|
362
|
+
let mut a = Quantity::<Meter, i32>::new(10);
|
|
363
|
+
a /= 5;
|
|
364
|
+
assert_eq!(a.value(), 2);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
368
|
+
// Additional coverage for exact conversions
|
|
369
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
370
|
+
|
|
371
|
+
#[test]
|
|
372
|
+
fn test_i8_exact_conversion() {
|
|
373
|
+
use qtty_core::scalar::Exact;
|
|
374
|
+
let val = 42_i8;
|
|
375
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
376
|
+
assert_eq!(f64_val, 42.0);
|
|
377
|
+
let back: i8 = Exact::from_f64_approx(f64_val);
|
|
378
|
+
assert_eq!(back, 42);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
#[test]
|
|
382
|
+
fn test_i16_exact_conversion() {
|
|
383
|
+
use qtty_core::scalar::Exact;
|
|
384
|
+
let val = 1000_i16;
|
|
385
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
386
|
+
assert_eq!(f64_val, 1000.0);
|
|
387
|
+
let back: i16 = Exact::from_f64_approx(f64_val);
|
|
388
|
+
assert_eq!(back, 1000);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
#[test]
|
|
392
|
+
fn test_i32_exact_conversion() {
|
|
393
|
+
use qtty_core::scalar::Exact;
|
|
394
|
+
let val = 100000_i32;
|
|
395
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
396
|
+
assert_eq!(f64_val, 100000.0);
|
|
397
|
+
let back: i32 = Exact::from_f64_approx(f64_val);
|
|
398
|
+
assert_eq!(back, 100000);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
#[test]
|
|
402
|
+
fn test_i64_exact_conversion() {
|
|
403
|
+
use qtty_core::scalar::Exact;
|
|
404
|
+
let val = 1_000_000_i64;
|
|
405
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
406
|
+
assert_eq!(f64_val, 1_000_000.0);
|
|
407
|
+
let back: i64 = Exact::from_f64_approx(f64_val);
|
|
408
|
+
assert_eq!(back, 1_000_000);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
#[test]
|
|
412
|
+
fn test_i128_exact_conversion() {
|
|
413
|
+
use qtty_core::scalar::Exact;
|
|
414
|
+
let val = 1_000_000_000_i128;
|
|
415
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
416
|
+
assert_eq!(f64_val, 1_000_000_000.0);
|
|
417
|
+
let back: i128 = Exact::from_f64_approx(f64_val);
|
|
418
|
+
assert_eq!(back, 1_000_000_000);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
#[test]
|
|
422
|
+
fn test_i8_rem_euclid() {
|
|
423
|
+
let val = 7_i8;
|
|
424
|
+
assert_eq!(val.rem_euclid(4), 3);
|
|
425
|
+
assert_eq!((-7_i8).rem_euclid(4), 1);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
#[test]
|
|
429
|
+
fn test_i16_rem_euclid() {
|
|
430
|
+
let val = 17_i16;
|
|
431
|
+
assert_eq!(val.rem_euclid(5), 2);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
#[test]
|
|
435
|
+
fn test_i128_rem_euclid() {
|
|
436
|
+
let val = 27_i128;
|
|
437
|
+
assert_eq!(val.rem_euclid(10), 7);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
441
|
+
// Const methods for i8, i16, i128
|
|
442
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
443
|
+
|
|
444
|
+
#[test]
|
|
445
|
+
fn test_i8_const_add_sub() {
|
|
446
|
+
let a = Quantity::<Meter, i8>::new(10);
|
|
447
|
+
let b = Quantity::<Meter, i8>::new(3);
|
|
448
|
+
assert_eq!(a.const_add(b).value(), 13_i8);
|
|
449
|
+
assert_eq!(a.const_sub(b).value(), 7_i8);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
#[test]
|
|
453
|
+
fn test_i8_const_mul_div() {
|
|
454
|
+
let a = Quantity::<Meter, i8>::new(10);
|
|
455
|
+
assert_eq!(a.const_mul(3).value(), 30_i8);
|
|
456
|
+
assert_eq!(a.const_div(5).value(), 2_i8);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
#[test]
|
|
460
|
+
fn test_i8_min_max_const() {
|
|
461
|
+
let a = Quantity::<Meter, i8>::new(3);
|
|
462
|
+
let b = Quantity::<Meter, i8>::new(7);
|
|
463
|
+
assert_eq!(a.min_const(b).value(), 3_i8);
|
|
464
|
+
assert_eq!(a.max_const(b).value(), 7_i8);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
#[test]
|
|
468
|
+
fn test_i16_const_add_sub() {
|
|
469
|
+
let a = Quantity::<Meter, i16>::new(1000);
|
|
470
|
+
let b = Quantity::<Meter, i16>::new(500);
|
|
471
|
+
assert_eq!(a.const_add(b).value(), 1500_i16);
|
|
472
|
+
assert_eq!(a.const_sub(b).value(), 500_i16);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
#[test]
|
|
476
|
+
fn test_i16_const_mul_div() {
|
|
477
|
+
let a = Quantity::<Meter, i16>::new(100);
|
|
478
|
+
assert_eq!(a.const_mul(3).value(), 300_i16);
|
|
479
|
+
assert_eq!(a.const_div(10).value(), 10_i16);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
#[test]
|
|
483
|
+
fn test_i16_min_max_const() {
|
|
484
|
+
let a = Quantity::<Meter, i16>::new(100);
|
|
485
|
+
let b = Quantity::<Meter, i16>::new(200);
|
|
486
|
+
assert_eq!(a.min_const(b).value(), 100_i16);
|
|
487
|
+
assert_eq!(a.max_const(b).value(), 200_i16);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
#[test]
|
|
491
|
+
fn test_i128_const_add_sub() {
|
|
492
|
+
let a = Quantity::<Meter, i128>::new(1_000_000);
|
|
493
|
+
let b = Quantity::<Meter, i128>::new(500_000);
|
|
494
|
+
assert_eq!(a.const_add(b).value(), 1_500_000_i128);
|
|
495
|
+
assert_eq!(a.const_sub(b).value(), 500_000_i128);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
#[test]
|
|
499
|
+
fn test_i128_const_mul_div() {
|
|
500
|
+
let a = Quantity::<Meter, i128>::new(1000);
|
|
501
|
+
assert_eq!(a.const_mul(3).value(), 3000_i128);
|
|
502
|
+
assert_eq!(a.const_div(10).value(), 100_i128);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
#[test]
|
|
506
|
+
fn test_i128_min_max_const() {
|
|
507
|
+
let a = Quantity::<Meter, i128>::new(100);
|
|
508
|
+
let b = Quantity::<Meter, i128>::new(200);
|
|
509
|
+
assert_eq!(a.min_const(b).value(), 100_i128);
|
|
510
|
+
assert_eq!(a.max_const(b).value(), 200_i128);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
514
|
+
// to_lossy for i8, i16, i128
|
|
515
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
516
|
+
|
|
517
|
+
#[test]
|
|
518
|
+
fn test_i8_to_lossy() {
|
|
519
|
+
// Using units where the ratio is small enough for i8
|
|
520
|
+
let km = Quantity::<Kilometer, i8>::new(1);
|
|
521
|
+
let m: Quantity<Meter, i8> = km.to_lossy();
|
|
522
|
+
// 1 km = 1000m, but i8 max is 127, so this overflows/saturates
|
|
523
|
+
// The result depends on `from_f64_approx` which does `value as i8`
|
|
524
|
+
// 1000.0 as i8 = -24 (wraps). This is expected lossy behavior.
|
|
525
|
+
let _ = m.value(); // Just ensure it doesn't panic
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
#[test]
|
|
529
|
+
fn test_i16_to_lossy() {
|
|
530
|
+
let km = Quantity::<Kilometer, i16>::new(2);
|
|
531
|
+
let m: Quantity<Meter, i16> = km.to_lossy();
|
|
532
|
+
assert_eq!(m.value(), 2000_i16);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
#[test]
|
|
536
|
+
fn test_i128_to_lossy() {
|
|
537
|
+
let km = Quantity::<Kilometer, i128>::new(5);
|
|
538
|
+
let m: Quantity<Meter, i128> = km.to_lossy();
|
|
539
|
+
assert_eq!(m.value(), 5000_i128);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
543
|
+
// Additional i16/i128 commutative mul
|
|
544
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
545
|
+
|
|
546
|
+
#[test]
|
|
547
|
+
fn test_i16_commutative_mul() {
|
|
548
|
+
let a = Quantity::<Meter, i16>::new(5);
|
|
549
|
+
assert_eq!((3_i16 * a).value(), 15_i16);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
#[test]
|
|
553
|
+
fn test_i128_commutative_mul() {
|
|
554
|
+
let a = Quantity::<Meter, i128>::new(5);
|
|
555
|
+
assert_eq!((3_i128 * a).value(), 15_i128);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
559
|
+
// i16/i128 Display, From, PartialEq, Rem
|
|
560
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
561
|
+
|
|
562
|
+
#[test]
|
|
563
|
+
fn test_i16_display() {
|
|
564
|
+
let m = Quantity::<Meter, i16>::new(100);
|
|
565
|
+
assert_eq!(format!("{}", m), "100 m");
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
#[test]
|
|
569
|
+
fn test_i128_display() {
|
|
570
|
+
let m = Quantity::<Meter, i128>::new(999);
|
|
571
|
+
assert_eq!(format!("{}", m), "999 m");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
#[test]
|
|
575
|
+
fn test_i16_from_scalar() {
|
|
576
|
+
let a: Quantity<Meter, i16> = 100_i16.into();
|
|
577
|
+
assert_eq!(a.value(), 100_i16);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
#[test]
|
|
581
|
+
fn test_i128_from_scalar() {
|
|
582
|
+
let a: Quantity<Meter, i128> = 999_i128.into();
|
|
583
|
+
assert_eq!(a.value(), 999_i128);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
#[test]
|
|
587
|
+
fn test_i16_partial_eq() {
|
|
588
|
+
let a = Quantity::<Meter, i16>::new(42);
|
|
589
|
+
assert_eq!(a, 42_i16);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
#[test]
|
|
593
|
+
fn test_i128_partial_eq() {
|
|
594
|
+
let a = Quantity::<Meter, i128>::new(42);
|
|
595
|
+
assert_eq!(a, 42_i128);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
#[test]
|
|
599
|
+
fn test_i16_rem() {
|
|
600
|
+
let a = Quantity::<Meter, i16>::new(17);
|
|
601
|
+
assert_eq!((a % 5_i16).value(), 2_i16);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
#[test]
|
|
605
|
+
fn test_i128_rem() {
|
|
606
|
+
let a = Quantity::<Meter, i128>::new(17);
|
|
607
|
+
assert_eq!((a % 5_i128).value(), 2_i128);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
#[test]
|
|
611
|
+
fn test_i8_display() {
|
|
612
|
+
let m = Quantity::<Meter, i8>::new(42);
|
|
613
|
+
assert_eq!(format!("{}", m), "42 m");
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
#[test]
|
|
617
|
+
fn test_i8_from_scalar() {
|
|
618
|
+
let a: Quantity<Meter, i8> = 42_i8.into();
|
|
619
|
+
assert_eq!(a.value(), 42_i8);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
#[test]
|
|
623
|
+
fn test_i8_partial_eq() {
|
|
624
|
+
let a = Quantity::<Meter, i8>::new(42);
|
|
625
|
+
assert_eq!(a, 42_i8);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
#[test]
|
|
629
|
+
fn test_i8_rem() {
|
|
630
|
+
let a = Quantity::<Meter, i8>::new(17);
|
|
631
|
+
assert_eq!((a % 5_i8).value(), 2_i8);
|
|
632
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#![cfg(not(feature = "cross-unit-ops"))]
|
|
2
|
+
|
|
3
|
+
use core::cmp::Ordering;
|
|
4
|
+
use qtty_core::length::{Kilometer, Kilometers, Meter, Meters};
|
|
5
|
+
use qtty_core::Quantity;
|
|
6
|
+
|
|
7
|
+
#[test]
|
|
8
|
+
fn from_and_to_still_work_without_cross_unit_ops() {
|
|
9
|
+
let km = Kilometers::new(1.25);
|
|
10
|
+
|
|
11
|
+
let m_via_to: Quantity<Meter> = km.to();
|
|
12
|
+
assert!((m_via_to.value() - 1250.0).abs() < 1e-12);
|
|
13
|
+
|
|
14
|
+
let m_via_from: Quantity<Meter> = km.into();
|
|
15
|
+
assert!((m_via_from.value() - 1250.0).abs() < 1e-12);
|
|
16
|
+
|
|
17
|
+
let km_roundtrip: Quantity<Kilometer> = m_via_from.into();
|
|
18
|
+
assert!((km_roundtrip.value() - 1.25).abs() < 1e-12);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[test]
|
|
22
|
+
fn eq_unit_and_cmp_unit_replace_cross_unit_operators() {
|
|
23
|
+
let km = Kilometers::new(2.0);
|
|
24
|
+
let m_less = Meters::new(1_500.0);
|
|
25
|
+
let m_eq = Meters::new(2_000.0);
|
|
26
|
+
let m_more = Meters::new(2_500.0);
|
|
27
|
+
|
|
28
|
+
assert!(!km.eq_unit(&m_less));
|
|
29
|
+
assert!(km.eq_unit(&m_eq));
|
|
30
|
+
assert!(!km.eq_unit(&m_more));
|
|
31
|
+
|
|
32
|
+
assert_eq!(km.cmp_unit(&m_less), Some(Ordering::Greater));
|
|
33
|
+
assert_eq!(km.cmp_unit(&m_eq), Some(Ordering::Equal));
|
|
34
|
+
assert_eq!(km.cmp_unit(&m_more), Some(Ordering::Less));
|
|
35
|
+
}
|