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

feat: add crossword board generator #9

Merged
merged 3 commits into from
Feb 28, 2024
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/board_generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: board_generator

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
paths:
- "packages/board_generator/**"
- ".github/workflows/board_generator.yaml"
branches:
- main

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
with:
dart_sdk: stable
working_directory: packages/board_generator
coverage_excludes: "**/*.g.dart"
7 changes: 7 additions & 0 deletions packages/board_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
pubspec.lock
43 changes: 43 additions & 0 deletions packages/board_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Board Generator

[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)
[![License: MIT][license_badge]][license_link]

Crossword board generator.

## Usage 💻

**❗ In order to start using Board Generator you must have the [Dart SDK][dart_install_link] installed on your machine.**

Run it as a dart program:

```sh
dart main.dart
```

## Running Tests 🧪

To run all unit tests:

```sh
dart pub global activate coverage 1.2.0
dart test --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
```

To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov).

```sh
# Generate Coverage Report
genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
open coverage/index.html
```

[dart_install_link]: https://dart.dev/get-dart
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
1 change: 1 addition & 0 deletions packages/board_generator/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.5.1.0.yaml
20 changes: 20 additions & 0 deletions packages/board_generator/coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions packages/board_generator/lib/board_generator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:collection';

import 'package:board_generator/models/data_model.dart';

/// Generates a crossword.
Iterable<Crossword> generateCrosswords(List<String> wordList) sync* {
final queue = Queue<Iterator<Crossword>>()
..addFirst(
Crossword(
(b) => b..candidates.addAll(wordList),
).generate().iterator,
);

while (queue.isNotEmpty) {
final iterator = queue.removeFirst();
if (iterator.moveNext()) {
final crossword = iterator.current;
yield crossword;
queue
..addFirst(iterator)
..addFirst(crossword.generate().iterator);
}
}
}
16 changes: 16 additions & 0 deletions packages/board_generator/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:board_generator/board_generator.dart';

/// The list of all words that can be used to generate a crossword.
final allWords = [
'winter',
'spring',
'summer',
];

void main(List<String> args) {
final iter = generateCrosswords(allWords);
final completeCrossword = iter.last;

// ignore: avoid_print
print(completeCrossword);
}
Loading
Loading