Example #1
0
func ExampleNewAllCellsIterator() {
	for _, coordinates := range TicTacToe.NewAllCellsIterator() {
		fmt.Println(coordinates)
	}
	// Output:
	// {0 0}
	// {0 1}
	// {0 2}
	// {1 0}
	// {1 1}
	// {1 2}
	// {2 0}
	// {2 1}
	// {2 2}
}
Example #2
0
// TestAllCellsIterator checks that the iterator actually goes through all cells
func TestAllCellsIterator(t *testing.T) {
	expected := []TicTacToe.Coordinates{
		{0, 0},
		{0, 1},
		{0, 2},
		{1, 0},
		{1, 1},
		{1, 2},
		{2, 0},
		{2, 1},
		{2, 2},
	}

	iterator := TicTacToe.NewAllCellsIterator()
	assert.Len(t, iterator, len(expected))

	for i, coordinates := range iterator {
		if !assert.True(t, len(expected) > i, "Cell #%d", i) {
			break
		}

		assert.Equal(t, expected[i], coordinates, "Line #%d, cell #%d", i)
	}
}