#![feature(plugin)] #![plugin(stainless)] extern crate num; extern crate quant; #[cfg(test)] mod test { describe! stainless_tests { it "makes it easy to work w/ metres" { use quant::Metre; let metre: Metre = 1.0f64 * Metre::new(); assert_eq!(metre.to_string(), "1 metre".to_string()); } it "makes it easy to convert to other units such as angstroms" { use quant::{BigExponentiation, Metre}; use num::bigint::{Sign}; let metre = BigExponentiation::new_base10(Sign::Minus, 10) * Metre::new(); assert_eq!(metre.as_angstrom(), "1 angstrom".to_string()); } describe! derived_units { it "makes it super simple to work w/ derived units" { use quant::{kilogram, metre, second}; let kilogram = kilogram(); let distance = metre(); let time = second(); let interval = time.clone(); let f = format!("One newton (N) is the force needed to accelerate \ {} of mass at the rate of {} per {} per {}.", kilogram, distance, time, interval); assert_eq!(f, "One newton (N) is the force needed to accelerate \ 1 kilogram of mass at the rate of 1 metre per 1 second per 1 second." ) } it "makes it simple to work w/ derived units such as newtons" { use quant::{kilogram, metre, second}; let newton = 1.0f64 * kilogram() * metre() * second().pow(-2); assert_eq!(newton.to_string(), "1 kilogram * metre * second^-2".to_string()) } it "also makes it simple to work w/ named derived units such as newtons" { use quant::{kilogram, metre, second}; let newton = 1.0f64 * kilogram() * metre() * second().pow(-2); assert_eq!(newton.named(), "1 newton".to_string()) } } } }