diff --git a/src/main.rs b/src/main.rs index 06b8049..8096328 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use core::{panic, str}; use std::{ - collections::HashMap, + collections::BTreeMap, fmt::Display, fs::File, io::{BufRead, BufReader}, @@ -31,7 +31,7 @@ struct Args { } /// Layer -#[derive(Debug, PartialEq, Eq, Hash, Clone)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)] enum PositionLayer { A, B, @@ -61,7 +61,7 @@ impl FromStr for PositionLayer { /// Where PS Board is placed while QAQC. /// TODO: name -#[derive(Debug, PartialEq, Eq, Hash, Clone)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)] struct Position { major: PositionLayer, minor: u8, @@ -152,7 +152,7 @@ pub struct MasterLogResult { version: Version, datetime: DateTime, shifter: String, - board_results: HashMap, + board_results: BTreeMap, filename: String, } @@ -220,7 +220,7 @@ impl MasterLogResult { return Err(anyhow!("Invalid log format")); } - let mut assignments = HashMap::new(); + let mut assignments = BTreeMap::new(); // till 19 for `===========` for i in 0..19 { let line = lines.next().context("Unexpected EOF")??; @@ -265,7 +265,7 @@ impl MasterLogResult { return Err(anyhow!("Invalid log format(result Station0)")); } - let mut board_results = HashMap::new(); + let mut board_results = BTreeMap::new(); for station_minor in [0, 1] { info!("Result for {:?}", station_minor); for _ in 1..10 { @@ -507,6 +507,37 @@ mod test { extract_position_id, extract_shifter_line, extract_version, Position, PositionLayer, PsbId, }; + #[test] + fn positionlayer_ordering() { + assert!(PositionLayer::A < PositionLayer::B) + } + + #[test] + fn position_ordering() { + assert!( + Position { + major: PositionLayer::A, + minor: 1, + patch: 5 + } < Position { + major: PositionLayer::A, + minor: 1, + patch: 7 + } + ); + assert!( + Position { + major: PositionLayer::A, + minor: 1, + patch: 5 + } < Position { + major: PositionLayer::A, + minor: 2, + patch: 3 + } + ); + } + #[test] fn parse_position() { assert_eq!( diff --git a/tests/cli.rs b/tests/cli.rs index e998e39..35f77b4 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,5 +1,9 @@ mod integrated_test { - use std::path::PathBuf; + use std::{ + fs::File, + io::{BufRead, BufReader}, + path::PathBuf, + }; use anyhow::Result; use assert_cmd::{assert::OutputAssertExt, Command}; @@ -19,6 +23,15 @@ mod integrated_test { .success() .stdout(predicate::str::contains("Creating new file")); + // check output + { + let f = File::open(test_out.clone())?; + let r = BufReader::new(f); + assert!(r + .lines() + .any(|line| { line.unwrap().contains("8868,,A-0-1,0,1,1,0,1,8,1,") })); + } + // 2nd file let mut cmd = Command::cargo_bin("psb-qaqc-parse")?; cmd.current_dir("tests") diff --git a/tests/example_logs/valid/20240720_171418.log b/tests/example_logs/valid/20240720_171418.log index 4600537..abb6a49 100644 --- a/tests/example_logs/valid/20240720_171418.log +++ b/tests/example_logs/valid/20240720_171418.log @@ -5,23 +5,23 @@ Shifters: alice ---------------------- PBS Assignment: Position / assigned-ID : A-0-0 / PS008866 -Position / assigned-ID : A-1-0 / PS008866 -Position / assigned-ID : A-0-1 / PS008866 -Position / assigned-ID : A-1-1 / PS008866 -Position / assigned-ID : A-0-2 / PS008866 -Position / assigned-ID : A-1-2 / PS008866 -Position / assigned-ID : A-0-3 / PS008866 -Position / assigned-ID : A-1-3 / PS008866 -Position / assigned-ID : A-0-4 / PS008866 -Position / assigned-ID : A-1-4 / PS008866 -Position / assigned-ID : A-0-5 / PS008866 -Position / assigned-ID : A-1-5 / PS008866 -Position / assigned-ID : A-0-6 / PS008866 -Position / assigned-ID : A-1-6 / PS008866 -Position / assigned-ID : A-0-7 / PS008866 -Position / assigned-ID : A-1-7 / PS008866 -Position / assigned-ID : A-0-8 / PS008866 -Position / assigned-ID : A-1-8 / PS008866 +Position / assigned-ID : A-1-0 / PS008867 +Position / assigned-ID : A-0-1 / PS008868 +Position / assigned-ID : A-1-1 / PS008869 +Position / assigned-ID : A-0-2 / PS008870 +Position / assigned-ID : A-1-2 / PS008871 +Position / assigned-ID : A-0-3 / PS008872 +Position / assigned-ID : A-1-3 / PS008873 +Position / assigned-ID : A-0-4 / PS008874 +Position / assigned-ID : A-1-4 / PS008875 +Position / assigned-ID : A-0-5 / PS008876 +Position / assigned-ID : A-1-5 / PS008877 +Position / assigned-ID : A-0-6 / PS008878 +Position / assigned-ID : A-1-6 / PS008879 +Position / assigned-ID : A-0-7 / PS008880 +Position / assigned-ID : A-1-7 / PS008881 +Position / assigned-ID : A-0-8 / PS008882 +Position / assigned-ID : A-1-8 / PS008883 ====================== QAQC status| QSPIp | Recov | Power | Clock | ASDTP | Reset | Result | ----------------------------------------------------------------------