Skip to content

Commit

Permalink
fix: word pool larger constrains than word issue (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyadLaouissi authored Mar 21, 2024
1 parent 05aae75 commit d974a9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/board_generator_playground/lib/src/word_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ class WordPool {
}

// We remove the first constrain because we previously search
// with the first constrains.
// with the first constrains and we also need to remove constrains bigger
// than the characters available.
final updatedConstrains = <int, String>{
...constraints,
}..remove(firstConstrains.key);
}
..remove(firstConstrains.key)
..removeWhere((key, value) => key > i);

final word = words.firstWhere(
(word) {
Expand Down
31 changes: 31 additions & 0 deletions packages/board_generator_playground/test/src/word_pool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,37 @@ void main() {

expect(wordPool.firstMatch(constrains), equals('astrophotographers'));
});

test('constrains bigger than actual word found', () {
final words = [
'add',
'are',
'red',
'aunt',
'addy',
'adds',
'away',
'good',
'glad',
'apple',
'green',
'astrophotographers',
'stockspeoplelookup',
'glass',
];

final wordPool =
WordPool(maxLengthWord: 18, minLengthWord: 3, words: words);

final constrains = ConstrainedWordCandidate(
direction: Direction.down,
location: Location.zero,
constraints: {0: 'a', 2: 'e', 6: 'h', 10: 'g', 13: 'p', 15: 'e'},
invalidLengths: {},
);

expect(wordPool.firstMatch(constrains), equals('are'));
});
});

group('removeWord', () {
Expand Down

0 comments on commit d974a9b

Please sign in to comment.