extends "res://bin/unittest.gd"
const Board = preload('res://scripts/board.gd')
var board
func tests():
case("check_placement method checks boundaries")
board = Board.new()
board.set_dimensions(13, 13)
assert_true(board.check_placement(0, 0, 0, 0), 'top left corner')
assert_true(board.check_placement(0, 0, 12, 12), 'bottom right corner')
assert_false(board.check_placement(0, 0, 13, 12), 'beyond right')
assert_false(board.check_placement(0, 0, 12, 13), 'beyond bottom')
assert_false(board.check_placement(0, 0, -1, 0), 'beyond left')
assert_false(board.check_placement(0, 0, 0, -1), 'beyond top')
endcase()
case("check_placement checks boundaries for different types")
board = Board.new()
board.set_dimensions(13, 13)
assert_true(board.check_placement(2, 0, 0, 0), 'top left corner')
assert_false(board.check_placement(2, 0, 11, 12), 'bottom right corner')
assert_false(board.check_placement(2, 0, 12, 11), 'bottom right corner')
endcase()
case("board can place pieces and check for collisions")
board = Board.new()
board.set_dimensions(13, 13)
board.add_block(0, 0, 1, 1)
assert_false(board.check_placement(0, 0, 1, 1), 'near top left corner')
assert_false(board.check_placement(2, 0, 0, 0), 'top left corner')
endcase()
case("board handles triangles when checking for collisions")
board = Board.new()
board.set_dimensions(13, 13)
assert_true(board.check_placement(1, 0, 1, 0), '')
board.add_block(1, 0, 1, 0)
assert_false(board.check_placement(1, 0, 1, 0), '')
assert_false(board.check_placement(0, 0, 1, 0), '')
assert_false(board.check_placement(2, 0, 0, 0), '')
assert_true(board.check_placement(3, 0, 0, 0), 'complimenting piece')
board.add_block(1, 0, 0, 1)
assert_false(board.check_placement(3, 0, 0, 0), 'not complimenting piece')
endcase()
case("board determines sawdust (points) for basic placements")
board = Board.new()
board.set_dimensions(13, 13)
assert_eq(board.get_points_for_placement(3, 0, 0, 0), 5, 'empty')
board.add_block(1, 0, 1, 0)
# Single complementing one:
assert_eq(board.get_points_for_placement(3, 0, 0, 0), 6, 'single complimenting triangle')
board = Board.new()
board.set_dimensions(5, 5)
board.add_block(0, 0, 2, 1)
board.add_block(0, 0, 1, 2)
assert_eq(board.get_points_for_placement(0, 0, 1, 1), 7, 'two adjacent')
board.add_block(0, 0, 0, 0)
assert_eq(board.get_points_for_placement(0, 0, 1, 1), 7, 'ignores catty-corner')
board.add_block(0, 0, 0, 1)
assert_eq(board.get_points_for_placement(0, 0, 1, 1), 8, 'three adjacent')
endcase()
case("board determines sawdust (points) for bonus placements")
board = Board.new()
board.set_dimensions(5, 5)
board.add_block(0, 0, 2, 1)
board.add_block(0, 0, 1, 2)
board.add_block(0, 0, 0, 1)
board.add_block(0, 0, 1, 0)
board.add_block(0, 0, 1, 0)
# Adjacent to 4 or more, gets 1 + 3 bonus
assert_eq(board.get_points_for_placement(0, 0, 1, 1), 12, 'bonus')
board = Board.new()
board.set_dimensions(10, 10)
board.add_block(0, 0, 0, 1)
board.add_block(0, 0, 1, 0)
assert_eq(board.get_points_for_placement(3, 0, 1, 1), 7, 'two adjacent')
board.add_block(0, 0, 2, 0)
assert_eq(board.get_points_for_placement(3, 0, 1, 1), 7, 'three')
board.add_block(0, 0, 2, 2)
assert_eq(board.get_points_for_placement(3, 0, 1, 1), 8, 'three')
board.add_block(1, 2, 1, 2)
assert_eq(board.get_points_for_placement(3, 0, 1, 1), 12, 'four')
board.add_block(1, 0, 2, 1)
assert_true(board.check_placement(3, 0, 1, 1), 'ensure placement')
assert_eq(board.get_points_for_placement(3, 0, 1, 1), 15, 'five')
endcase()