Compare commits

..

2 Commits

5 changed files with 69 additions and 11 deletions

View File

@ -307,11 +307,13 @@ impl<T> Tree<T> {
//
// indent represents the indentation that should be applied to all children in this tree. It
// amounts to the position of the parent node.
pub fn position(&self, indent: usize, idx: usize) -> (usize, usize) {
println!("[{}]", idx);
//
// When drawing nodes, I don't know how to persist the level of indent.
pub fn position(&self, idx: usize) -> (usize, usize) {
let node = &self.nodes[idx];
match node.parent {
Some(parent_idx) => {
let (_parent_row, parent_column) = self.position(parent_idx);
let parent = &self.nodes[parent_idx];
let sibling_width = parent
.children
@ -319,7 +321,7 @@ impl<T> Tree<T> {
.take_while(|n| **n != node.id)
.fold(0, |acc, n| acc + self.width(*n));
println!("[{}] sibling width {}", idx, sibling_width);
(node.depth, indent + sibling_width)
(node.depth, parent_column + sibling_width)
}
// Root nodes won't have a parent, so just put them in the first column
@ -538,13 +540,13 @@ mod test {
let tree = Tree::from(&game_tree);
assert_eq!(tree.position(0, 2), (2, 0));
assert_eq!(tree.position(0, 1), (1, 0));
assert_eq!(tree.position(0, 0), (0, 0));
assert_eq!(tree.position(0, 4), (3, 1));
assert_eq!(tree.position(0, 5), (3, 2));
assert_eq!(tree.position(0, 6), (1, 3));
assert_eq!(tree.position(0, 7), (1, 4));
assert_eq!(tree.position(2), (2, 0));
assert_eq!(tree.position(1), (1, 0));
assert_eq!(tree.position(0), (0, 0));
assert_eq!(tree.position(4), (3, 1));
assert_eq!(tree.position(5), (3, 2));
assert_eq!(tree.position(6), (1, 3));
assert_eq!(tree.position(7), (1, 4));
}
#[test]

View File

@ -77,7 +77,7 @@ impl ReviewTree {
// the parent? do I need to just make it more intrinsically a part of the position
// code?
ctx.set_source_rgb(0.7, 0.7, 0.7);
let (row, column) = tree.position(0, node.id);
let (row, column) = tree.position(node.id);
println!("[{}] {} x {}", node.id, row, column);
let y = (row as f64) * 20. + 10.;
let x = (column as f64) * 20. + 10.;

View File

@ -911,4 +911,40 @@ mod file_test {
},
);
}
#[ignore]
#[test]
fn it_handles_shuwa_genan_file() {
with_file(
std::path::Path::new("test_data/2019.02.15_shuwa_genan_annotated.sgf"),
|trees| {
assert_eq!(trees.len(), 1);
let game = &trees[0];
assert_eq!(game.game_type, GameType::Go);
assert_eq!(
game.board_size,
Size {
width: 19,
height: 19
}
);
assert_eq!(
game.black_player,
Player {
name: Some("Honinbo Shuwa".to_owned()),
rank: Some("7P".to_owned()),
team: None
}
);
assert_eq!(
game.white_player,
Player {
name: Some("Inoue(Genan)Inseki".to_owned()),
rank: Some("8P".to_owned()),
team: None
}
);
},
)
}
}

View File

@ -463,4 +463,15 @@ mod tests {
},
);
}
// This is a file
#[test]
fn it_handles_shuwa_genan_file() {
with_file(
std::path::Path::new("test_data/2020 USGO DDK, Round 1.sgf"),
|trees| {
assert_eq!(trees.len(), 2);
},
)
}
}

View File

@ -1252,6 +1252,15 @@ mod date_test {
Date::Date(NaiveDate::from_ymd_opt(1996, 12, 28).unwrap())
])
);
assert_matches!(
parse_date_field::<nom::error::VerboseError<&str>>().parse("1842-5-16-18"),
Ok((_, date)) => assert_eq!(date, vec![
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 16).unwrap()),
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 17).unwrap()),
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 18).unwrap()),
])
);
}
#[test]