Skip to content

Commit

Permalink
Implement PartialEq.
Browse files Browse the repository at this point in the history
Resolves #17.
  • Loading branch information
iliekturtles committed Dec 26, 2017
1 parent 2ea06fb commit d508971
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 190 deletions.
50 changes: 24 additions & 26 deletions src/si/acceleration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,32 @@ mod tests {

#[test]
fn check_units() {
test(l::yottameter, a::yottameter_per_second_squared);
test(l::zettameter, a::zettameter_per_second_squared);
test(l::exameter, a::exameter_per_second_squared);
test(l::petameter, a::petameter_per_second_squared);
test(l::terameter, a::terameter_per_second_squared);
test(l::gigameter, a::gigameter_per_second_squared);
test(l::megameter, a::megameter_per_second_squared);
test(l::kilometer, a::kilometer_per_second_squared);
test(l::hectometer, a::hectometer_per_second_squared);
test(l::decameter, a::decameter_per_second_squared);
test(l::meter, a::meter_per_second_squared);
test(l::decimeter, a::decimeter_per_second_squared);
test(l::centimeter, a::centimeter_per_second_squared);
test(l::millimeter, a::millimeter_per_second_squared);
test(l::micrometer, a::micrometer_per_second_squared);
test(l::nanometer, a::nanometer_per_second_squared);
test(l::picometer, a::picometer_per_second_squared);
test(l::femtometer, a::femtometer_per_second_squared);
test(l::attometer, a::attometer_per_second_squared);
test(l::zeptometer, a::zeptometer_per_second_squared);
test(l::yoctometer, a::yoctometer_per_second_squared);
test::<l::yottameter, a::yottameter_per_second_squared>();
test::<l::zettameter, a::zettameter_per_second_squared>();
test::<l::exameter, a::exameter_per_second_squared>();
test::<l::petameter, a::petameter_per_second_squared>();
test::<l::terameter, a::terameter_per_second_squared>();
test::<l::gigameter, a::gigameter_per_second_squared>();
test::<l::megameter, a::megameter_per_second_squared>();
test::<l::kilometer, a::kilometer_per_second_squared>();
test::<l::hectometer, a::hectometer_per_second_squared>();
test::<l::decameter, a::decameter_per_second_squared>();
test::<l::meter, a::meter_per_second_squared>();
test::<l::decimeter, a::decimeter_per_second_squared>();
test::<l::centimeter, a::centimeter_per_second_squared>();
test::<l::millimeter, a::millimeter_per_second_squared>();
test::<l::micrometer, a::micrometer_per_second_squared>();
test::<l::nanometer, a::nanometer_per_second_squared>();
test::<l::picometer, a::picometer_per_second_squared>();
test::<l::femtometer, a::femtometer_per_second_squared>();
test::<l::attometer, a::attometer_per_second_squared>();
test::<l::zeptometer, a::zeptometer_per_second_squared>();
test::<l::yoctometer, a::yoctometer_per_second_squared>();

// TODO #17 Convert to == once PartialEq is implemented.
fn test<L: l::Conversion<V>, A: a::Conversion<V>>(_l: L, a: A) {
Test::assert_eq(&V::one(),
fn test<L: l::Conversion<V>, A: a::Conversion<V>>() {
Test::assert_eq(&Acceleration::new::<A>(V::one()),
&(Length::new::<L>(V::one()) /
(Time::new::<t::second>(V::one()) * Time::new::<t::second>(V::one())))
.get(a));
(Time::new::<t::second>(V::one()) * Time::new::<t::second>(V::one()))));
}
}
}
Expand Down
49 changes: 24 additions & 25 deletions src/si/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,37 @@ mod tests {
fn check_units() {
// Values too large for f32.
if TypeId::of::<f64>() == TypeId::of::<V>() {
test(l::yottameter, a::square_yottameter);
test(l::zettameter, a::square_zettameter);
test::<l::yottameter, a::square_yottameter>();
test::<l::zettameter, a::square_zettameter>();
}

test(l::exameter, a::square_exameter);
test(l::petameter, a::square_petameter);
test(l::terameter, a::square_terameter);
test(l::gigameter, a::square_gigameter);
test(l::megameter, a::square_megameter);
test(l::kilometer, a::square_kilometer);
test(l::hectometer, a::square_hectometer);
test(l::decameter, a::square_decameter);
test(l::meter, a::square_meter);
test(l::decimeter, a::square_decimeter);
test(l::centimeter, a::square_centimeter);
test(l::millimeter, a::square_millimeter);
test(l::micrometer, a::square_micrometer);
test(l::nanometer, a::square_nanometer);
test(l::picometer, a::square_picometer);
test(l::femtometer, a::square_femtometer);
test(l::attometer, a::square_attometer);
test(l::zeptometer, a::square_zeptometer);
test::<l::exameter, a::square_exameter>();
test::<l::petameter, a::square_petameter>();
test::<l::terameter, a::square_terameter>();
test::<l::gigameter, a::square_gigameter>();
test::<l::megameter, a::square_megameter>();
test::<l::kilometer, a::square_kilometer>();
test::<l::hectometer, a::square_hectometer>();
test::<l::decameter, a::square_decameter>();
test::<l::meter, a::square_meter>();
test::<l::decimeter, a::square_decimeter>();
test::<l::centimeter, a::square_centimeter>();
test::<l::millimeter, a::square_millimeter>();
test::<l::micrometer, a::square_micrometer>();
test::<l::nanometer, a::square_nanometer>();
test::<l::picometer, a::square_picometer>();
test::<l::femtometer, a::square_femtometer>();
test::<l::attometer, a::square_attometer>();
test::<l::zeptometer, a::square_zeptometer>();

// Values too small for f32.
if TypeId::of::<f64>() == TypeId::of::<V>() {
test(l::yoctometer, a::square_yoctometer);
test::<l::yoctometer, a::square_yoctometer>();
}

// TODO #17 Convert to == once PartialEq is implemented.
fn test<L: l::Conversion<V>, A: a::Conversion<V>>(_l: L, a: A) {
Test::assert_eq(&V::one(),
&(Length::new::<L>(V::one()) * Length::new::<L>(V::one())).get(a));
fn test<L: l::Conversion<V>, A: a::Conversion<V>>() {
Test::assert_eq(&Area::new::<A>(V::one()),
&(Length::new::<L>(V::one()) * Length::new::<L>(V::one())));
}
}
}
Expand Down
109 changes: 52 additions & 57 deletions src/si/force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,71 +58,66 @@ mod tests {

#[test]
fn check_units() {
test(m::yottagram, l::meter, t::second, f::zettanewton);
test(m::zettagram, l::meter, t::second, f::exanewton);
test(m::exagram, l::meter, t::second, f::petanewton);
test(m::petagram, l::meter, t::second, f::teranewton);
test(m::teragram, l::meter, t::second, f::giganewton);
test(m::gigagram, l::meter, t::second, f::meganewton);
test(m::megagram, l::meter, t::second, f::kilonewton);
test(m::kilogram, l::meter, t::second, f::newton);
test(m::gram, l::meter, t::second, f::millinewton);
test(m::milligram, l::meter, t::second, f::micronewton);
test(m::microgram, l::meter, t::second, f::nanonewton);
test(m::nanogram, l::meter, t::second, f::piconewton);
test(m::picogram, l::meter, t::second, f::femtonewton);
test(m::femtogram, l::meter, t::second, f::attonewton);
test(m::attogram, l::meter, t::second, f::zeptonewton);
test(m::zeptogram, l::meter, t::second, f::yoctonewton);
test::<m::yottagram, l::meter, t::second, f::zettanewton>();
test::<m::zettagram, l::meter, t::second, f::exanewton>();
test::<m::exagram, l::meter, t::second, f::petanewton>();
test::<m::petagram, l::meter, t::second, f::teranewton>();
test::<m::teragram, l::meter, t::second, f::giganewton>();
test::<m::gigagram, l::meter, t::second, f::meganewton>();
test::<m::megagram, l::meter, t::second, f::kilonewton>();
test::<m::kilogram, l::meter, t::second, f::newton>();
test::<m::gram, l::meter, t::second, f::millinewton>();
test::<m::milligram, l::meter, t::second, f::micronewton>();
test::<m::microgram, l::meter, t::second, f::nanonewton>();
test::<m::nanogram, l::meter, t::second, f::piconewton>();
test::<m::picogram, l::meter, t::second, f::femtonewton>();
test::<m::femtogram, l::meter, t::second, f::attonewton>();
test::<m::attogram, l::meter, t::second, f::zeptonewton>();
test::<m::zeptogram, l::meter, t::second, f::yoctonewton>();

test(m::kilogram, l::yottameter, t::second, f::yottanewton);
test(m::kilogram, l::zettameter, t::second, f::zettanewton);
test(m::kilogram, l::exameter, t::second, f::exanewton);
test(m::kilogram, l::petameter, t::second, f::petanewton);
test(m::kilogram, l::terameter, t::second, f::teranewton);
test(m::kilogram, l::gigameter, t::second, f::giganewton);
test(m::kilogram, l::megameter, t::second, f::meganewton);
test(m::kilogram, l::kilometer, t::second, f::kilonewton);
test(m::kilogram, l::hectometer, t::second, f::hectonewton);
test(m::kilogram, l::decameter, t::second, f::decanewton);
test(m::kilogram, l::meter, t::second, f::newton);
test(m::kilogram, l::decimeter, t::second, f::decinewton);
test(m::kilogram, l::centimeter, t::second, f::centinewton);
test(m::kilogram, l::millimeter, t::second, f::millinewton);
test(m::kilogram, l::micrometer, t::second, f::micronewton);
test(m::kilogram, l::nanometer, t::second, f::nanonewton);
test(m::kilogram, l::picometer, t::second, f::piconewton);
test(m::kilogram, l::femtometer, t::second, f::femtonewton);
test(m::kilogram, l::attometer, t::second, f::attonewton);
test(m::kilogram, l::zeptometer, t::second, f::zeptonewton);
test(m::kilogram, l::meter, t::second, f::newton);
test::<m::kilogram, l::yottameter, t::second, f::yottanewton>();
test::<m::kilogram, l::zettameter, t::second, f::zettanewton>();
test::<m::kilogram, l::exameter, t::second, f::exanewton>();
test::<m::kilogram, l::petameter, t::second, f::petanewton>();
test::<m::kilogram, l::terameter, t::second, f::teranewton>();
test::<m::kilogram, l::gigameter, t::second, f::giganewton>();
test::<m::kilogram, l::megameter, t::second, f::meganewton>();
test::<m::kilogram, l::kilometer, t::second, f::kilonewton>();
test::<m::kilogram, l::hectometer, t::second, f::hectonewton>();
test::<m::kilogram, l::decameter, t::second, f::decanewton>();
test::<m::kilogram, l::meter, t::second, f::newton>();
test::<m::kilogram, l::decimeter, t::second, f::decinewton>();
test::<m::kilogram, l::centimeter, t::second, f::centinewton>();
test::<m::kilogram, l::millimeter, t::second, f::millinewton>();
test::<m::kilogram, l::micrometer, t::second, f::micronewton>();
test::<m::kilogram, l::nanometer, t::second, f::nanonewton>();
test::<m::kilogram, l::picometer, t::second, f::piconewton>();
test::<m::kilogram, l::femtometer, t::second, f::femtonewton>();
test::<m::kilogram, l::attometer, t::second, f::attonewton>();
test::<m::kilogram, l::zeptometer, t::second, f::zeptonewton>();
test::<m::kilogram, l::meter, t::second, f::newton>();

test(m::kilogram, l::meter, t::terasecond, f::yoctonewton);
test(m::kilogram, l::meter, t::gigasecond, f::attonewton);
test(m::kilogram, l::meter, t::megasecond, f::piconewton);
test(m::kilogram, l::meter, t::kilosecond, f::micronewton);
test(m::kilogram, l::meter, t::decasecond, f::centinewton);
test(m::kilogram, l::meter, t::decisecond, f::hectonewton);
test(m::kilogram, l::meter, t::millisecond, f::meganewton);
test(m::kilogram, l::meter, t::microsecond, f::teranewton);
test(m::kilogram, l::meter, t::nanosecond, f::exanewton);
test(m::kilogram, l::meter, t::picosecond, f::yottanewton);
test::<m::kilogram, l::meter, t::terasecond, f::yoctonewton>();
test::<m::kilogram, l::meter, t::gigasecond, f::attonewton>();
test::<m::kilogram, l::meter, t::megasecond, f::piconewton>();
test::<m::kilogram, l::meter, t::kilosecond, f::micronewton>();
test::<m::kilogram, l::meter, t::decasecond, f::centinewton>();
test::<m::kilogram, l::meter, t::decisecond, f::hectonewton>();
test::<m::kilogram, l::meter, t::millisecond, f::meganewton>();
test::<m::kilogram, l::meter, t::microsecond, f::teranewton>();
test::<m::kilogram, l::meter, t::nanosecond, f::exanewton>();
test::<m::kilogram, l::meter, t::picosecond, f::yottanewton>();

// TODO #17 Convert to == once PartialEq is implemented.
fn test<
M: m::Conversion<V>,
L: l::Conversion<V>,
T: t::Conversion<V>,
F: f::Conversion<V>
>(
_m: M,
_l: L,
_t: T,
f: F
) {
Test::assert_approx_eq(&V::one(), &((Mass::new::<M>(V::one())
F: f::Conversion<V>>()
{
Test::assert_approx_eq(&Force::new::<F>(V::one()),
&((Mass::new::<M>(V::one())
* Length::new::<L>(V::one()))
/ (Time::new::<T>(V::one()) * Time::new::<T>(V::one()))).get(f));
/ (Time::new::<T>(V::one()) * Time::new::<T>(V::one()))));
}
}
}
Expand Down
53 changes: 26 additions & 27 deletions src/si/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,33 @@ mod tests {

#[test]
fn check_units() {
test(t::yottasecond, f::yoctohertz);
test(t::zettasecond, f::zeptohertz);
test(t::exasecond, f::attohertz);
test(t::petasecond, f::femtohertz);
test(t::terasecond, f::picohertz);
test(t::gigasecond, f::nanohertz);
test(t::megasecond, f::microhertz);
test(t::kilosecond, f::millihertz);
test(t::hectosecond, f::centihertz);
test(t::decasecond, f::decihertz);
test(t::second, f::hertz);
test(t::decisecond, f::decahertz);
test(t::centisecond, f::hectohertz);
test(t::millisecond, f::kilohertz);
test(t::microsecond, f::megahertz);
test(t::nanosecond, f::gigahertz);
test(t::picosecond, f::terahertz);
test(t::femtosecond, f::petahertz);
test(t::attosecond, f::exahertz);
test(t::zeptosecond, f::zettahertz);
test(t::yoctosecond, f::yottahertz);
test::<t::yottasecond, f::yoctohertz>();
test::<t::zettasecond, f::zeptohertz>();
test::<t::exasecond, f::attohertz>();
test::<t::petasecond, f::femtohertz>();
test::<t::terasecond, f::picohertz>();
test::<t::gigasecond, f::nanohertz>();
test::<t::megasecond, f::microhertz>();
test::<t::kilosecond, f::millihertz>();
test::<t::hectosecond, f::centihertz>();
test::<t::decasecond, f::decihertz>();
test::<t::second, f::hertz>();
test::<t::decisecond, f::decahertz>();
test::<t::centisecond, f::hectohertz>();
test::<t::millisecond, f::kilohertz>();
test::<t::microsecond, f::megahertz>();
test::<t::nanosecond, f::gigahertz>();
test::<t::picosecond, f::terahertz>();
test::<t::femtosecond, f::petahertz>();
test::<t::attosecond, f::exahertz>();
test::<t::zeptosecond, f::zettahertz>();
test::<t::yoctosecond, f::yottahertz>();

// TODO #17 Convert to == once PartialEq is implemented.
fn test<T: t::Conversion<V>, F: f::Conversion<V>>(t: T, f: F) {
Test::assert_approx_eq(&(V::one() / Time::new::<T>(V::one())).get(f),
&Frequency::new::<F>(V::one()).get(f));
Test::assert_approx_eq(&Time::new::<T>(V::one()).get(t),
&(V::one() / Frequency::new::<F>(V::one())).get(t));
fn test<T: t::Conversion<V>, F: f::Conversion<V>>() {
Test::assert_approx_eq(&(V::one() / Time::new::<T>(V::one())),
&Frequency::new::<F>(V::one()));
Test::assert_approx_eq(&Time::new::<T>(V::one()),
&(V::one() / Frequency::new::<F>(V::one())));
}
}
}
Expand Down
Loading

0 comments on commit d508971

Please sign in to comment.