mirror of
https://bitbucket.org/Mattrixwv/rustclasses.git
synced 2026-02-04 03:32:29 -05:00
Moved stopwatch tests to the end of the file
This commit is contained in:
67
src/lib.rs
67
src/lib.rs
@@ -10,39 +10,6 @@ pub mod Stopwatch;
|
|||||||
pub mod Algorithms;
|
pub mod Algorithms;
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod StopwatchTests{
|
|
||||||
#[test]
|
|
||||||
fn testStartStop(){
|
|
||||||
let mut timer = super::Stopwatch::Stopwatch::new();
|
|
||||||
timer.start();
|
|
||||||
timer.stop();
|
|
||||||
//If it gets to here without panicing everything went well
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn testConversion(){
|
|
||||||
let mut timer = super::Stopwatch::Stopwatch::new();
|
|
||||||
let mut sum = 0i64;
|
|
||||||
//Start the timer
|
|
||||||
timer.start();
|
|
||||||
//Do something to run some time
|
|
||||||
for cnt in 0..100_000{
|
|
||||||
sum += cnt;
|
|
||||||
}
|
|
||||||
//Stop the timer
|
|
||||||
timer.stop();
|
|
||||||
//Asser something so the sum isn't ignored during compile
|
|
||||||
assert_ne!(sum, 0);
|
|
||||||
//Check that the different resolutions work out correctly
|
|
||||||
let nano = timer.getNano();
|
|
||||||
assert_eq!(timer.getMicro(), (nano / 1000));
|
|
||||||
assert_eq!(timer.getMilli(), (nano / 1000000));
|
|
||||||
assert_eq!(timer.getSeconds(), (nano / 1000000000) as u64);
|
|
||||||
super::assert_approx_eq::assert_approx_eq!(timer.getMinutes(), (nano as f64 / 60000000000.0));
|
|
||||||
super::assert_approx_eq::assert_approx_eq!(timer.getHours(), (nano as f64 / 3600000000000.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod AlgorithmsTests{
|
mod AlgorithmsTests{
|
||||||
#[test]
|
#[test]
|
||||||
@@ -105,3 +72,37 @@ mod AlgorithmsTests{
|
|||||||
assert_eq!(correctAnswer3, answer3);
|
assert_eq!(correctAnswer3, answer3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod StopwatchTests{
|
||||||
|
#[test]
|
||||||
|
fn testStartStop(){
|
||||||
|
let mut timer = super::Stopwatch::Stopwatch::new();
|
||||||
|
timer.start();
|
||||||
|
timer.stop();
|
||||||
|
//If it gets to here without panicing everything went well
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn testConversion(){
|
||||||
|
let mut timer = super::Stopwatch::Stopwatch::new();
|
||||||
|
let mut sum = 0i64;
|
||||||
|
//Start the timer
|
||||||
|
timer.start();
|
||||||
|
//Do something to run some time
|
||||||
|
for cnt in 0..100_000{
|
||||||
|
sum += cnt;
|
||||||
|
}
|
||||||
|
//Stop the timer
|
||||||
|
timer.stop();
|
||||||
|
//Asser something so the sum isn't ignored during compile
|
||||||
|
assert_ne!(sum, 0);
|
||||||
|
//Check that the different resolutions work out correctly
|
||||||
|
let nano = timer.getNano();
|
||||||
|
assert_eq!(timer.getMicro(), (nano / 1000));
|
||||||
|
assert_eq!(timer.getMilli(), (nano / 1000000));
|
||||||
|
assert_eq!(timer.getSeconds(), (nano / 1000000000) as u64);
|
||||||
|
super::assert_approx_eq::assert_approx_eq!(timer.getMinutes(), (nano as f64 / 60000000000.0));
|
||||||
|
super::assert_approx_eq::assert_approx_eq!(timer.getHours(), (nano as f64 / 3600000000000.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user