function [] = testBoardClass()
close all
clear all

board1 = Board(5);
if (~isa(board1,'Board') || board1.size ~= 5 || any(size(board1.hexes) ~= [5 5]))
    disp('error in Board constructor');
end

%make this work for cell array of hexes
if(isa(board1.hexes,'cell'))
  boardhexes = reshape([board1.hexes{:}],board1.size,board1.size);
else
  boardhexes = board1.hexes;
end

% test if all of the hexes were created correctly
for row = 1:5
    for col = 1:5
        hex = boardhexes(row,col);
        if (~isa(hex, 'Hex') || hex.xcoord ~= col || hex.ycoord ~= row || hex.player ~= 0)
            fprintf('Hex not created correctly in Board constructor at location %d %d\n',...
                row,col);
        end
        if (~board1.isEmpty([row col]))
            fprintf('board.isEmpty function not correct at location %d %d\n',...
                row,col);
        end
    end
end

% test basic drawing
figure(1);
board1.draw();
player1.color = 'red';
player1.index = 1;
player2.color = 'blue';
player2.index = 2;
board1.drawBoundaries(player1,player2);
fprintf('Testing the board.draw and board.drawBoundaries functions.\n Figure 1 should have a 5x5 hex board with all white tiles and red and blue player boundaries\n');

% test a winning and non-winning board setup
boardhexes(1,1).player = 2;
boardhexes(1,2).player = 2;
boardhexes(1,3).player = 2;
boardhexes(1,4).player = 2;
boardhexes(1,5).player = 2;
boardhexes(3,3).player = 2;
boardhexes(2,5).player = 1;
%disp(board1.getConnectedPaths(2));
winningPath = board1.getWinningPath([1 5]);
if (isempty(winningPath))
    disp('board.getWinningPath does not correctly detect the winning path for player 2');
elseif (~isempty(board1.getWinningPath([2 5])))
    disp('board.getWinningPath does not correctly detect no winning path for player 1');
elseif ((size(winningPath,2) == 1 && any(winningPath' ~= [1 6 11 16 21])) || ...
        (size(winningPath,2) > 1 && any(winningPath ~= [1 6 11 16 21])))
    disp('incorrect winning path for test, expecting [1 6 11 16 21]');
    disp(winningPath);
end

fprintf('Testing the board.showPath function, \nthe bottom row of Figure 1 should be highlighted as a winning path\n');
board1.showPath(winningPath);

% finally test playing a hex, both winning and not winning
figure(2)
board2 = Board(2);
board2.draw();
board2.drawBoundaries(player1, player2);
if (board2.play(player1, [1 1]))
    disp('board.play function incorrectly identifies [1 1] as a winning move');
end
if (board2.play(player2, [1 2]))
    disp('board.play function incorrectly identifies [1 2] as a winning move');
end
if (~board2.play(player1, [2 1]))
     disp('board.play function fails to identify [2 1] as a winning move');
end
close 2