-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timer_unit_tests to separate file
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[cfg(all(test, not(feature = "mips64_timer_tests")))] | ||
mod timer_unit_tests { | ||
use martos::timer::Timer; | ||
use std::time::Duration; | ||
|
||
#[test] | ||
/// Tests setup timer function and getting counter value (bad unit test). | ||
fn test_setup_timer() { | ||
Timer::setup_timer(); | ||
let timer = Timer::get_timer(0) | ||
.expect("The timer is already active or a timer with this index does not exist."); | ||
assert_eq!(timer.get_time().as_micros(), 0); | ||
timer.release_timer(); | ||
} | ||
|
||
#[test] | ||
/// Tests loop timer function. | ||
fn test_loop_timer() { | ||
Timer::setup_timer(); | ||
let mut timer = Timer::get_timer(0) | ||
.expect("The timer is already active or a timer with this index does not exist."); | ||
timer.loop_timer(); | ||
assert_eq!(timer.get_time().as_micros(), 0); | ||
timer.release_timer(); | ||
} | ||
|
||
#[test] | ||
/// Tests stop condition timer function. | ||
fn test_stop_condition_timer() { | ||
let timer = Timer::get_timer(0) | ||
.expect("The timer is already active or a timer with this index does not exist."); | ||
timer.change_period_timer(Duration::new(10, 0)); | ||
timer.start_timer(); | ||
assert!(!timer.stop_condition_timer()); | ||
timer.release_timer(); | ||
} | ||
} |