1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#[cfg(test)]
mod tree_tests {
use sgf_parser::Action::Move;
use sgf_parser::*;
#[test]
fn can_convert_game_tree_without_variations() {
let tree = GameTree {
nodes: vec![
GameNode {
tokens: vec![
SgfToken::PlayerName {
color: Color::Black,
name: "black".to_string(),
},
SgfToken::PlayerName {
color: Color::White,
name: "white".to_string(),
},
],
},
GameNode {
tokens: vec![SgfToken::Move {
color: Color::Black,
action: Move(3, 3),
}],
},
GameNode {
tokens: vec![SgfToken::Move {
color: Color::White,
action: Move(16, 16),
}],
},
],
variations: vec![],
};
let string_tree: String = tree.into();
assert_eq!(string_tree, "(;PB[black]PW[white];B[cc];W[pp])");
}
#[test]
fn can_convert_game_tree_with_variations() {
let tree = GameTree {
nodes: vec![
GameNode {
tokens: vec![
SgfToken::PlayerName {
color: Color::Black,
name: "black".to_string(),
},
SgfToken::PlayerName {
color: Color::White,
name: "white".to_string(),
},
],
},
GameNode {
tokens: vec![SgfToken::Move {
color: Color::Black,
action: Move(3, 3),
}],
},
GameNode {
tokens: vec![SgfToken::Move {
color: Color::White,
action: Move(16, 16),
}],
},
],
variations: vec![
GameTree {
nodes: vec![GameNode {
tokens: vec![SgfToken::Move {
color: Color::Black,
action: Move(4, 16),
}],
}],
variations: vec![],
},
GameTree {
nodes: vec![GameNode {
tokens: vec![SgfToken::Move {
color: Color::Black,
action: Move(16, 4),
}],
}],
variations: vec![],
},
],
};
let string_tree: String = tree.into();
assert_eq!(
string_tree,
"(;PB[black]PW[white];B[cc];W[pp](;B[dp])(;B[pd]))"
);
}
}