Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for time.rs #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ pub fn duration_between(earlier_micros: u32, later_micros: u32) -> Duration {
Duration::from_micros((later_micros - earlier_micros).into())
}
}

#[test]
fn test_now_duration() {
let micros_a = now_micros();
let micros_b = now_micros();

assert!(micros_a < micros_b);

let duration = duration_between(micros_a, micros_b);

let duration_micros = duration.as_micros();
assert!(duration_micros > 0);
assert!(duration_micros < 2000);
}

#[test]
fn test_wrapped_duration() {
// Max u32 value minus 10.
let earlier_micros: u32 = 4294967285;
// Wrapped around by 10.
let later_micros: u32 = 10;
// earlier_micros > later_micros
let duration = duration_between(earlier_micros, later_micros);
// With 10 microseconds on each side of the max, total should be 20 microseconds.
assert_eq!(duration.as_micros(), 20);
}