Learning Dart
This commit is contained in:
23
dart/scrabble-score/.exercism/config.json
Normal file
23
dart/scrabble-score/.exercism/config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"authors": [
|
||||
"jvarness"
|
||||
],
|
||||
"contributors": [
|
||||
"Stargator",
|
||||
"kytrinyx"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"lib/scrabble_score.dart"
|
||||
],
|
||||
"test": [
|
||||
"test/scrabble_score_test.dart"
|
||||
],
|
||||
"example": [
|
||||
".meta/lib/example.dart"
|
||||
]
|
||||
},
|
||||
"blurb": "Given a word, compute the Scrabble score for that word.",
|
||||
"source": "Inspired by the Extreme Startup game",
|
||||
"source_url": "https://github.com/rchatley/extreme_startup"
|
||||
}
|
1
dart/scrabble-score/.exercism/metadata.json
Normal file
1
dart/scrabble-score/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"dart","exercise":"scrabble-score","id":"bb5e20e260e046ec8304134db5bfeed8","url":"https://exercism.org/tracks/dart/exercises/scrabble-score","handle":"br0xen","is_requester":true,"auto_approve":false}
|
37
dart/scrabble-score/HELP.md
Normal file
37
dart/scrabble-score/HELP.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests:
|
||||
|
||||
```sh
|
||||
$ dart test
|
||||
```
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit lib/scrabble_score.dart` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [Dart track's documentation](https://exercism.org/docs/tracks/dart)
|
||||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, you can use one of the following resources:
|
||||
|
||||
- [Dart API Documentation](https://api.dart.dev/)
|
||||
- [Dart Gitter Chat](https://gitter.im/dart-lang/home)
|
||||
- [Community Information](https://www.dart.dev/community)
|
||||
- [/r/dartlang](https://www.reddit.com/r/dartlang) is the Dart subreddit.
|
||||
- [StackOverflow](https://stackoverflow.com/questions/tagged/dart) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
|
60
dart/scrabble-score/README.md
Normal file
60
dart/scrabble-score/README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Scrabble Score
|
||||
|
||||
Welcome to Scrabble Score on Exercism's Dart Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
Given a word, compute the Scrabble score for that word.
|
||||
|
||||
## Letter Values
|
||||
|
||||
You'll need these:
|
||||
|
||||
```text
|
||||
Letter Value
|
||||
A, E, I, O, U, L, N, R, S, T 1
|
||||
D, G 2
|
||||
B, C, M, P 3
|
||||
F, H, V, W, Y 4
|
||||
K 5
|
||||
J, X 8
|
||||
Q, Z 10
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
"cabbage" should be scored as worth 14 points:
|
||||
|
||||
- 3 points for C
|
||||
- 1 point for A, twice
|
||||
- 3 points for B, twice
|
||||
- 2 points for G
|
||||
- 1 point for E
|
||||
|
||||
And to total:
|
||||
|
||||
- `3 + 2*1 + 2*3 + 2 + 1`
|
||||
- = `3 + 2 + 6 + 3`
|
||||
- = `5 + 9`
|
||||
- = 14
|
||||
|
||||
## Extensions
|
||||
|
||||
- You can play a double or a triple letter.
|
||||
- You can play a double or a triple word.
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @jvarness
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @Stargator
|
||||
- @kytrinyx
|
||||
|
||||
### Based on
|
||||
|
||||
Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup
|
18
dart/scrabble-score/analysis_options.yaml
Normal file
18
dart/scrabble-score/analysis_options.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
errors:
|
||||
unused_element: error
|
||||
unused_import: error
|
||||
unused_local_variable: error
|
||||
dead_code: error
|
||||
|
||||
linter:
|
||||
rules:
|
||||
# Error Rules
|
||||
- avoid_relative_lib_imports
|
||||
- avoid_types_as_parameter_names
|
||||
- literal_only_boolean_expressions
|
||||
- no_adjacent_strings_in_list
|
||||
- valid_regexps
|
18
dart/scrabble-score/lib/scrabble_score.dart
Normal file
18
dart/scrabble-score/lib/scrabble_score.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
class ScrabbleScore {
|
||||
Map letterScores = Map<rune, int>.of({
|
||||
'a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1, 'l': 1, 'n': 1, 'r': 1, 's': 1, 't': 1,
|
||||
'd': 2, 'g': 2,
|
||||
'b': 3, 'c': 3, 'm': 3, 'p': 3,
|
||||
'f': 4, 'h': 4, 'v': 4, 'w': 4, 'y': 4,
|
||||
'k': 5,
|
||||
'j': 8, 'x': 8,
|
||||
'q': 10, 'z': 10
|
||||
});
|
||||
|
||||
int score(String word) {
|
||||
word = word.toLowerCase();
|
||||
int ret = 0;
|
||||
word.runes.forEach(r => ret += letterScores[r]);
|
||||
return ret;
|
||||
}
|
||||
}
|
5
dart/scrabble-score/pubspec.yaml
Normal file
5
dart/scrabble-score/pubspec.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: 'scrabble_score'
|
||||
environment:
|
||||
sdk: '>=2.18.0 <3.0.0'
|
||||
dev_dependencies:
|
||||
test: '<2.0.0'
|
61
dart/scrabble-score/test/scrabble_score_test.dart
Normal file
61
dart/scrabble-score/test/scrabble_score_test.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:scrabble_score/scrabble_score.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('ScrabbleScore', () {
|
||||
test('lowercase letter', () {
|
||||
final result = score('a');
|
||||
expect(result, equals(1));
|
||||
}, skip: false);
|
||||
|
||||
test('uppercase letter', () {
|
||||
final result = score('A');
|
||||
expect(result, equals(1));
|
||||
}, skip: true);
|
||||
|
||||
test('valuable letter', () {
|
||||
final result = score('f');
|
||||
expect(result, equals(4));
|
||||
}, skip: true);
|
||||
|
||||
test('short word', () {
|
||||
final result = score('at');
|
||||
expect(result, equals(2));
|
||||
}, skip: true);
|
||||
|
||||
test('short, valuable word', () {
|
||||
final result = score('zoo');
|
||||
expect(result, equals(12));
|
||||
}, skip: true);
|
||||
|
||||
test('medium word', () {
|
||||
final result = score('street');
|
||||
expect(result, equals(6));
|
||||
}, skip: true);
|
||||
|
||||
test('medium, valuable word', () {
|
||||
final result = score('quirky');
|
||||
expect(result, equals(22));
|
||||
}, skip: true);
|
||||
|
||||
test('long, mixed-case word', () {
|
||||
final result = score('OxyphenButazone');
|
||||
expect(result, equals(41));
|
||||
}, skip: true);
|
||||
|
||||
test('english-like word', () {
|
||||
final result = score('pinata');
|
||||
expect(result, equals(8));
|
||||
}, skip: true);
|
||||
|
||||
test('empty input', () {
|
||||
final result = score('');
|
||||
expect(result, equals(0));
|
||||
}, skip: true);
|
||||
|
||||
test('entire alphabet available', () {
|
||||
final result = score('abcdefghijklmnopqrstuvwxyz');
|
||||
expect(result, equals(87));
|
||||
}, skip: true);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user