update: Strict ordering for outpu (use BTreeMap instead of HashMap)

This commit is contained in:
Wataru Otsubo 2024-07-21 20:29:42 +09:00
parent c4dd4161c7
commit bdb415e6e6
3 changed files with 68 additions and 24 deletions

View file

@ -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<Utc>,
shifter: String,
board_results: HashMap<Position, MasterBoardResult>,
board_results: BTreeMap<Position, MasterBoardResult>,
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!(