From ff4794cbf07d7ca8c0a95ddb7f778dc11a542891 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Mon, 15 Jun 2020 13:33:00 -0400 Subject: [PATCH] Moved stopwatch tests to the end of the file --- src/lib.rs | 67 +++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6cfdfb7..65f514c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)); + } +}