-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specific area and specific volume quantities.
- Loading branch information
1 parent
5fd23fa
commit e051876
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! Specific area (base unit square meter per kilogram, m² · kg⁻¹). | ||
quantity! { | ||
/// Specific area (base unit square meter per kilogram, m² · kg⁻¹). | ||
quantity: SpecificArea; "specific area"; | ||
/// Dimension of specific area, L²M⁻¹ (base unit square meter per kilogram, m² · kg⁻¹). | ||
dimension: ISQ< | ||
P2, // length | ||
N1, // mass | ||
Z0, // time | ||
Z0, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@square_meter_per_kilogram: prefix!(none); "m²/kg", "square meter per kilogram", | ||
"square meters per kilogram"; | ||
@square_centimeter_per_kilogram: prefix!(centi) * prefix!(centi); "cm²/kg", | ||
"square centimeter per kilogram", "square centimeters per kilogram"; | ||
|
||
@square_meter_per_gram: prefix!(none) / prefix!(milli); "m²/g", "square meter per gram", | ||
"square meters per gram"; | ||
@square_centimeter_per_gram: prefix!(centi) * prefix!(centi) / prefix!(milli); "cm²/g", | ||
"square centimeter per gram", "square centimeters per gram"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use crate::num::One; | ||
use crate::si::area as a; | ||
use crate::si::mass as m; | ||
use crate::si::specific_area as sa; | ||
use crate::si::quantities::*; | ||
use crate::tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: SpecificArea<V> = Area::new::<a::square_meter>(V::one()) / Mass::new::<m::kilogram>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<a::square_meter, m::kilogram, sa::square_meter_per_kilogram>(); | ||
test::<a::square_centimeter, m::kilogram, sa::square_centimeter_per_kilogram>(); | ||
|
||
test::<a::square_meter, m::gram, sa::square_meter_per_gram>(); | ||
test::<a::square_centimeter, m::gram, sa::square_centimeter_per_gram>(); | ||
|
||
fn test<A: a::Conversion<V>, M: m::Conversion<V>, SA: sa::Conversion<V>, >() { | ||
Test::assert_eq(&SpecificArea::new::<SA>(V::one()), | ||
&(Area::new::<A>(V::one()) / Mass::new::<M>(V::one()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹). | ||
quantity! { | ||
/// Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹). | ||
quantity: SpecificVolume; "specific volume"; | ||
/// Dimension of specific volume, L³M⁻¹ (base unit cubic meter per kilogram, m³ · kg⁻¹). | ||
dimension: ISQ< | ||
P3, // length | ||
N1, // mass | ||
Z0, // time | ||
Z0, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@cubic_meter_per_kilogram: prefix!(none); "m³/kg", "cubic meter per kilogram", | ||
"cubic meters per kilogram"; | ||
@cubic_centimeter_per_kilogram: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³/kg", | ||
"cubic centimeter per kilogram", "cubic centimeters per kilogram"; | ||
|
||
@cubic_meter_per_gram: prefix!(none) / prefix!(milli); "m³/g", "cubic meter per gram", | ||
"cubic meters per gram"; | ||
@cubic_centimeter_per_gram: | ||
prefix!(centi) * prefix!(centi) * prefix!(centi) / prefix!(milli); "cm³/g", | ||
"cubic centimeter per gram", "cubic centimeters per gram"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use crate::num::One; | ||
use crate::si::volume as a; | ||
use crate::si::mass as m; | ||
use crate::si::specific_volume as sv; | ||
use crate::si::quantities::*; | ||
use crate::tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: SpecificVolume<V> = Volume::new::<a::cubic_meter>(V::one()) | ||
/ Mass::new::<m::kilogram>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<a::cubic_meter, m::kilogram, sv::cubic_meter_per_kilogram>(); | ||
test::<a::cubic_centimeter, m::kilogram, sv::cubic_centimeter_per_kilogram>(); | ||
test::<a::cubic_meter, m::gram, sv::cubic_meter_per_gram>(); | ||
test::<a::cubic_centimeter, m::gram, sv::cubic_centimeter_per_gram>(); | ||
|
||
fn test<A: a::Conversion<V>, M: m::Conversion<V>, SV: sv::Conversion<V>>() { | ||
Test::assert_eq(&SpecificVolume::new::<SV>(V::one()), | ||
&(Volume::new::<A>(V::one()) / Mass::new::<M>(V::one()))); | ||
} | ||
} | ||
} | ||
} |