-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from gwbres/timescale_fmt
timecale.rs: introduce format/display
- Loading branch information
Showing
2 changed files
with
80 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
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,45 @@ | ||
extern crate hifitime; | ||
use hifitime::TimeScale; | ||
use std::str::FromStr; | ||
|
||
#[test] | ||
fn test_from_str() { | ||
let values = vec![ | ||
("TAI", TimeScale::TAI), | ||
("UTC", TimeScale::UTC), | ||
("TT", TimeScale::TT), | ||
("TDB", TimeScale::TDB), | ||
("GPST", TimeScale::GPST), | ||
("GST", TimeScale::GST), | ||
("BDT", TimeScale::BDT), | ||
]; | ||
for value in values { | ||
let (descriptor, expected) = value; | ||
let ts = TimeScale::from_str(descriptor); | ||
assert_eq!(ts.is_ok(), true); | ||
let ts = ts.unwrap(); | ||
assert_eq!(ts, expected); | ||
// test to_str()/format() | ||
assert_eq!(format!("{}", ts), descriptor); | ||
// test format(0x) | ||
let expected: &str = match ts { | ||
TimeScale::GPST => "GPS", | ||
TimeScale::GST => "GAL", | ||
TimeScale::BDT => "BDS", | ||
_ => descriptor, // untouched | ||
}; | ||
assert_eq!(format!("{:x}", ts), expected); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_is_gnss() { | ||
let ts = TimeScale::GPST; | ||
assert!(ts.is_gnss()); | ||
let ts = TimeScale::GST; | ||
assert!(ts.is_gnss()); | ||
let ts = TimeScale::UTC; | ||
assert!(!ts.is_gnss()); | ||
let ts = TimeScale::TAI; | ||
assert!(!ts.is_gnss()); | ||
} |