Merge pull request #34 from stscoundrel/main

This commit is contained in:
Vincent Velociter
2024-03-29 09:06:51 +01:00
committed by GitHub
+159 -5
View File
@@ -16,6 +16,20 @@ void main() {
expect(kingAttacks(21), attacks);
});
test('King attacks near edges', () {
final attacks = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . 1 1
. . . . . . 1 .
''');
expect(kingAttacks(7), attacks);
});
test('Knight attacks', () {
final attacks = makeSquareSet('''
. . . . . . . .
@@ -30,6 +44,20 @@ void main() {
expect(knightAttacks(35), attacks);
});
test('Knight attacks near edges', () {
final attacks = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . 1 . 1
. . . . 1 . . .
. . . . . . . .
. . . . 1 . . .
''');
expect(knightAttacks(14), attacks);
});
test('White pawn attacks', () {
final attacks = makeSquareSet('''
. . . . . . . .
@@ -44,6 +72,20 @@ void main() {
expect(pawnAttacks(Side.white, 11), attacks);
});
test('White pawn attacks near edges', () {
final attacks = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. 1 . . . . . .
. . . . . . . .
. . . . . . . .
''');
expect(pawnAttacks(Side.white, 8), attacks);
});
test('Black pawn attacks', () {
final attacks = makeSquareSet('''
. . . . . . . .
@@ -58,7 +100,21 @@ void main() {
expect(pawnAttacks(Side.black, 36), attacks);
});
test('bishop attacks, empty board', () {
test('Black pawn attacks near edges', () {
final attacks = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . 1 .
. . . . . . . .
. . . . . . . .
. . . . . . . .
''');
expect(pawnAttacks(Side.black, 39), attacks);
});
test('Bishop attacks, empty board', () {
expect(bishopAttacks(27, SquareSet.empty), makeSquareSet('''
. . . . . . . 1
1 . . . . . 1 .
@@ -94,7 +150,30 @@ void main() {
'''));
});
test('rook attacks, empty board', () {
test('Bishop attacks, surrounded in occupied board', () {
final occupied = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . 1 1 1 . .
. . . 1 . 1 . .
. . . 1 1 1 . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
''');
expect(bishopAttacks(36, occupied), makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . 1 . 1 . .
. . . . . . . .
. . . 1 . 1 . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
'''));
});
test('Rook attacks, empty board', () {
expect(rookAttacks(10, SquareSet.empty), makeSquareSet('''
. . 1 . . . . .
. . 1 . . . . .
@@ -107,7 +186,7 @@ void main() {
'''));
});
test('rook attacks, occupied board', () {
test('Rook attacks, occupied board', () {
final occupied = makeSquareSet('''
. . . . . . . .
. . . . . . . .
@@ -130,7 +209,30 @@ void main() {
'''));
});
test('queen attacks, empty board', () {
test('Rook attacks, surrounded in occupied board', () {
final occupied = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . 1 1 1 . .
. . . 1 . 1 . .
. . . 1 1 1 . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
''');
expect(rookAttacks(36, occupied), makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . . 1 . . .
. . . 1 . 1 . .
. . . . 1 . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
'''));
});
test('Queen attacks, empty board', () {
expect(queenAttacks(37, SquareSet.empty), makeSquareSet('''
. . 1 . . 1 . .
. . . 1 . 1 . 1
@@ -143,7 +245,7 @@ void main() {
'''));
});
test('queen attacks, occupied board', () {
test('Queen attacks, occupied board', () {
final occupied = makeSquareSet('''
. . . . . . . .
. . . . . . . .
@@ -165,4 +267,56 @@ void main() {
. . . . . . . .
'''));
});
test('Queen attacks, surrounded in occupied board', () {
final occupied = makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . 1 1 1 . .
. . . 1 . 1 . .
. . . 1 1 1 . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
''');
expect(queenAttacks(36, occupied), makeSquareSet('''
. . . . . . . .
. . . . . . . .
. . . 1 1 1 . .
. . . 1 . 1 . .
. . . 1 1 1 . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
'''));
});
test('Legal board position asserts for attacks', () {
const illegalBoardPosition = 65;
const emptySquareSet = SquareSet.empty;
expect(() {
kingAttacks(illegalBoardPosition);
}, throwsA(isA<AssertionError>()));
expect(() {
pawnAttacks(Side.white, illegalBoardPosition);
}, throwsA(isA<AssertionError>()));
expect(() {
knightAttacks(illegalBoardPosition);
}, throwsA(isA<AssertionError>()));
expect(() {
bishopAttacks(illegalBoardPosition, emptySquareSet);
}, throwsA(isA<AssertionError>()));
expect(() {
rookAttacks(illegalBoardPosition, emptySquareSet);
}, throwsA(isA<AssertionError>()));
expect(() {
queenAttacks(illegalBoardPosition, emptySquareSet);
}, throwsA(isA<AssertionError>()));
});
}