Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add board class similar to field but without the tuples #27

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Automatically reads the input files and provides different methods to parse it.

A place to store useful parsing operations, like creating a `List<int>` from a `List<String>`. There will be a lot of opportunities during AoC for you to extend this.

### Field Class
### Board Class

A helper class for 2D data, as often present in AoC. Any data can be represented. For Integers specifically, there are convenience methods in `IntegerField`. For all available methods, have a look at the abundantly-documented code.

Expand Down
87 changes: 87 additions & 0 deletions test/board_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Import the test package
import 'package:test/test.dart';
import '../utils/board.dart';

/// Board tests
/// Needs more tests
void main() {
// Group your tests together
group('Board Tests', () {
// Test case for addition of positive numbers
test('create a board and validate', () {
final board = Board<String>(
field: [
['00', '01', '02'],
['10', '11', '12'],
['20', '21', '22'],
],
); // Assuming Board is a class you want to test

expect(board.boardWidth, equals(3));
expect(board.boardHeight, equals(3));
expect(board.getValueAt(row: 1, col: 1), equals('11'));
expect(board.getRow(0), equals(['00', '01', '02']));
expect(board.getColumn(0), equals(['00', '10', '20']));
expect(
board.adjacent(const AbsoluteCoordinate(row: 0, col: 0)),
equals([
const AbsoluteCoordinate(row: 0, col: 1),
const AbsoluteCoordinate(row: 1, col: 0),
]),
);
});

test('AbsoluteCoordinate', () {
const coord = AbsoluteCoordinate(row: 2, col: 3);
expect(coord.row, equals(2));
expect(coord.col, equals(3));
const coord2 = AbsoluteCoordinate(row: 2, col: 3);
expect(coord, equals(coord2));
const coord3 = AbsoluteCoordinate(row: 3, col: 3);
expect(coord, isNot(coord3));

const coord4 = OffsetCoordinate(row: 2, col: 3);
expect(coord, isNot(coord4));
});

test('Offsetoordinate', () {
const coord = OffsetCoordinate(row: 2, col: 3);
expect(coord.row, equals(2));
expect(coord.col, equals(3));
const coord2 = OffsetCoordinate(row: 2, col: 3);
expect(coord, equals(coord2));
const coord3 = OffsetCoordinate(row: 3, col: 3);
expect(coord, isNot(coord3));

const coord4 = AbsoluteCoordinate(row: 2, col: 3);
expect(coord, isNot(coord4));

expect(
coord.absoluteFrom(const AbsoluteCoordinate(row: 1, col: 1)),
equals(const AbsoluteCoordinate(row: 3, col: 4)),
);
});
});

group('IntegerBoard Tests', () {
// Test case for addition of positive numbers
test('create integer board and increment', () {
final board = Board<int>(
field: [
[00, 01, 02],
[10, 11, 12],
[20, 21, 22],
],
); // Assuming Board is a class you want to test

expect(board.boardWidth, equals(3));
expect(board.boardHeight, equals(3));
expect(board.getValueAt(row: 1, col: 1), equals(11));
board.increment(
row: 1,
col: 1,
);
expect(board.getValueAt(row: 1, col: 1), equals(12));
});
});
}
Loading