1+ /************************************************************************
2+ * *
3+ * Copyright 2015 Igor Polyakov *
4+ * *
5+ * This file is part of Iomrascálaí. *
6+ * *
7+ * Iomrascálaí is free software: you can redistribute it and/or modify *
8+ * it under the terms of the GNU General Public License as published by *
9+ * the Free Software Foundation, either version 3 of the License, or *
10+ * (at your option) any later version. *
11+ * *
12+ * Iomrascálaí is distributed in the hope that it will be useful, *
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+ * GNU General Public License for more details. *
16+ * *
17+ * You should have received a copy of the GNU General Public License *
18+ * along with Iomrascálaí. If not, see <http://www.gnu.org/licenses/>. *
19+ * *
20+ ************************************************************************/
21+
22+ #![ cfg( test) ]
23+ use std:: path:: Path ;
24+ use board:: Black ;
25+ use board:: Coord ;
26+ use board:: Pass ;
27+ use board:: White ;
28+ use board:: movement:: Play ;
29+ use sgf:: Parser ;
30+
31+ #[ test]
32+ fn top_left_has_one_liberty ( ) {
33+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
34+ let game = parser. game ( ) . unwrap ( ) ;
35+ let board = game. board ( ) ;
36+ assert_eq ! ( 1 , board. liberty_count( Coord :: new( 1 , 19 ) ) ) ;
37+ }
38+
39+ #[ test]
40+ fn one_below_top_left_has_two_liberties ( ) {
41+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
42+ let game = parser. game ( ) . unwrap ( ) ;
43+ let board = game. board ( ) ;
44+ assert_eq ! ( 2 , board. liberty_count( Coord :: new( 1 , 18 ) ) ) ;
45+ }
46+
47+ #[ test]
48+ fn two_below_top_left_has_three_liberties ( ) {
49+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
50+ let game = parser. game ( ) . unwrap ( ) ;
51+ let board = game. board ( ) ;
52+ assert_eq ! ( 3 , board. liberty_count( Coord :: new( 1 , 17 ) ) ) ;
53+ }
54+
55+ #[ test]
56+ fn first_square_surrounded_by_four_liberties_in_top_left ( ) {
57+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
58+ let game = parser. game ( ) . unwrap ( ) ;
59+ let board = game. board ( ) ;
60+ assert_eq ! ( 4 , board. liberty_count( Coord :: new( 5 , 16 ) ) ) ;
61+ }
62+
63+ #[ test]
64+ fn removes_one_stone ( ) {
65+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
66+ let game = parser. game ( ) . unwrap ( ) ;
67+ let board = game. board ( ) ;
68+ assert_eq ! ( 1 , board. removes_enemy_neighbouring_stones( Play ( Black , 4 , 19 ) ) ) ;
69+ }
70+
71+ #[ test]
72+ fn removes_two_stones ( ) {
73+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
74+ let game = parser. game ( ) . unwrap ( ) ;
75+ let board = game. board ( ) ;
76+ assert_eq ! ( 2 , board. removes_enemy_neighbouring_stones( Play ( Black , 4 , 15 ) ) ) ;
77+ }
78+
79+ #[ test]
80+ fn removes_three_stones ( ) {
81+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
82+ let game = parser. game ( ) . unwrap ( ) ;
83+ let board = game. board ( ) ;
84+ assert_eq ! ( 3 , board. removes_enemy_neighbouring_stones( Play ( Black , 4 , 10 ) ) ) ;
85+ }
86+
87+ #[ test]
88+ fn removes_four_stones ( ) {
89+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
90+ let game = parser. game ( ) . unwrap ( ) ;
91+ let board = game. board ( ) ;
92+ assert_eq ! ( 4 , board. removes_enemy_neighbouring_stones( Play ( Black , 4 , 4 ) ) ) ;
93+ }
94+
95+ #[ test]
96+ fn removes_three_neighbours ( ) {
97+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
98+ let game = parser. game ( ) . unwrap ( ) ;
99+ let board = game. board ( ) ;
100+ assert_eq ! ( 3 , board. removes_enemy_neighbouring_stones( Play ( Black , 9 , 18 ) ) ) ;
101+ }
102+
103+ #[ test]
104+ fn removes_two_neighbours ( ) {
105+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
106+ let game = parser. game ( ) . unwrap ( ) ;
107+ let board = game. board ( ) ;
108+ assert_eq ! ( 2 , board. removes_enemy_neighbouring_stones( Play ( Black , 9 , 15 ) ) ) ;
109+ }
110+
111+ #[ test]
112+ fn two_stones_have_six_liberties ( ) {
113+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
114+ let game = parser. game ( ) . unwrap ( ) ;
115+ let board = game. board ( ) ;
116+
117+ let play = Play ( Black , 10 , 12 ) ;
118+ assert_eq ! ( 2 , board. new_chain_length( play) ) ;
119+ assert_eq ! ( 6 , board. new_chain_liberties( play) ) ;
120+ }
121+
122+ #[ test]
123+ fn three_stones_have_eight_liberties ( ) {
124+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
125+ let game = parser. game ( ) . unwrap ( ) ;
126+ let board = game. board ( ) ;
127+ let play = Play ( Black , 10 , 10 ) ;
128+ assert_eq ! ( 3 , board. new_chain_length( play) ) ;
129+ assert_eq ! ( 8 , board. new_chain_liberties( play) ) ;
130+ }
131+
132+ #[ test]
133+ fn four_stones_have_eight_liberties ( ) {
134+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
135+ let game = parser. game ( ) . unwrap ( ) ;
136+ let board = game. board ( ) ;
137+ let play = Play ( Black , 10 , 7 ) ;
138+ assert_eq ! ( 4 , board. new_chain_length( play) ) ;
139+ assert_eq ! ( 8 , board. new_chain_liberties( play) ) ;
140+ }
141+
142+ #[ test]
143+ fn five_stones_have_eight_liberties ( ) {
144+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
145+ let game = parser. game ( ) . unwrap ( ) ;
146+ let board = game. board ( ) ;
147+ let play = Play ( Black , 10 , 4 ) ;
148+ assert_eq ! ( 5 , board. new_chain_length( play) ) ;
149+ assert_eq ! ( 8 , board. new_chain_liberties( play) ) ;
150+ }
151+
152+ #[ test]
153+ fn six_stones_have_nine_liberties ( ) {
154+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
155+ let game = parser. game ( ) . unwrap ( ) ;
156+ let board = game. board ( ) ;
157+ let play = Play ( Black , 15 , 17 ) ;
158+ assert_eq ! ( 6 , board. new_chain_length( play) ) ;
159+ assert_eq ! ( 9 , board. new_chain_liberties( play) ) ;
160+ }
161+
162+ #[ test]
163+ fn seven_stones_have_ten_liberties ( ) {
164+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
165+ let game = parser. game ( ) . unwrap ( ) ;
166+ let board = game. board ( ) ;
167+ let play = Play ( Black , 15 , 13 ) ;
168+ assert_eq ! ( 7 , board. new_chain_length( play) ) ;
169+ assert_eq ! ( 10 , board. new_chain_liberties( play) ) ;
170+ }
171+
172+ #[ test]
173+ fn nine_stones_have_twelve_liberties ( ) {
174+ let parser = Parser :: from_path ( Path :: new ( "fixtures/sgf/hypothetical-plays.sgf" ) ) ;
175+ let game = parser. game ( ) . unwrap ( ) ;
176+ let board = game. board ( ) ;
177+ let play = Play ( Black , 15 , 9 ) ;
178+ assert_eq ! ( 9 , board. new_chain_length( play) ) ;
179+ assert_eq ! ( 12 , board. new_chain_liberties( play) ) ;
180+ }
0 commit comments