Moved stopwatch tests to the end of the file

This commit is contained in:
2020-06-15 13:33:00 -04:00
parent fafbb61288
commit ff4794cbf0

View File

@@ -10,39 +10,6 @@ pub mod Stopwatch;
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)]
mod AlgorithmsTests{
#[test]
@@ -105,3 +72,37 @@ mod AlgorithmsTests{
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));
}
}