Skip to content

Commit

Permalink
馃尡 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Mar 24, 2024
0 parents commit ac9a6f9
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "pub"
directory: "/"
schedule:
interval: "weekly"
60 changes: 60 additions & 0 deletions .github/workflows/analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Analysis CI

on:
push:
branches: [main]

pull_request:
branches: [main]
types: [opened, synchronize, reopened]

env:
DART_SDK_VERSION: "3.3"

permissions:
contents: read

jobs:
build:
name: Analyze
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Cache dependencies
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
id: cache
with:
path: ~/.pub-cache/hosted
key: ${{ runner.os }}-pubspec-${{ env.DART_SDK_VERSION }}-${{ hashFiles('**/pubspec.yaml') }}
restore-keys: |
${{ runner.os }}-pubspec-${{ env.DART_SDK_VERSION }}-
${{ runner.os }}-pubspec-
${{ runner.os }}-
- name: Set up Dart
uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3 # v1.6.2
with:
sdk: ${{ env.DART_SDK_VERSION }}

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze --fatal-infos

- name: Run tests
run: |
dart pub global activate coverage
dart test test/main.dart --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
- name: Coveralls upload
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://www.dartlang.org/guides/libraries/private-files

tool/

# IntelliJ
*.iml
*.ipr
*.iws
.idea/

# macOS
.DS_Store

# Files and directories created by pub
.dart_tool/
.packages
build/
pubspec.lock

# Coverage
coverage/
test/.test_coverage.dart
.coveralls.yaml

doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map

.flutter-plugins
.flutter-plugins-dependencies
15 changes: 15 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include: package:very_good_analysis/analysis_options.yaml

linter:
rules:
- annotate_redeclares
- avoid_classes_with_only_static_members
- avoid_types_on_closure_parameters
- type_literal_in_constant_pattern
- unnecessary_null_aware_operator_on_extension_on_nullable

analyzer:
errors:
# Style decisions
always_use_package_imports: ignore
sort_constructors_first: ignore
49 changes: 49 additions & 0 deletions lib/string_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:math' show Random;

import 'package:collection/collection.dart' show IterableExtension;
import 'package:diacritic/diacritic.dart' show removeDiacritics;

final _random = Random.secure();

/// A string extension.
extension StringExtension on String {
/// Returns an anagram of this [String].
String get anagram {
const space = ' ';
final words = split(space).map((word) => word.split(''));

final letters = words.expand((word) => word).toList();
final vowels = letters.where(_isVowel).toList()..shuffle(_random);
final consonants = letters.whereNot(_isVowel).toList()..shuffle(_random);

String mapLetter(String letter) =>
(letter.isVowel ? vowels : consonants).removeAt(0);

return words.map((word) => word.map(mapLetter).join()).join(space);
}

static final _wordsOnlyRegExp = RegExp('[a-z]+');

String get _sortedLettersOnly => (_wordsOnlyRegExp
.allMatches(removeDiacritics(toLowerCase()))
.expand((match) => [match[0].toString()])
.join()
.split('')
..sort())
.join();

/// Whether this [String] is an [anagram] of [other].
bool isAnagramOf(String other) =>
_sortedLettersOnly == other._sortedLettersOnly;

static bool _isVowel(String s) => s.isVowel;

/// Whether this [String] is a vowel.
bool get isVowel {
if (removeDiacritics(this) case 'a' || 'e' || 'i' || 'o' || 'u') {
return true;
}

return false;
}
}
16 changes: 16 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: tacirupeca
description: A simple utility to generate anagrams.
version: 0.1.0

repository: https://github.com/albertms10/tacirupeca.git

environment:
sdk: ">=3.3.0 <4.0.0"

dependencies:
collection: ^1.18.0
diacritic: ^0.1.5

dev_dependencies:
test: ^1.25.2
very_good_analysis: ^5.1.0
5 changes: 5 additions & 0 deletions test/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'string_extension_test.dart' as string_extension_test;

void main() {
string_extension_test.main();
}
42 changes: 42 additions & 0 deletions test/string_extension_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:tacirupeca/string_extension.dart';
import 'package:test/test.dart';

void main() {
group('StringExtension', () {
group('.anagram', () {
test('returns an anagram of this String', () {
const input = 'caperucita roja';
expect(input.anagram.isAnagramOf(input), isTrue);
});
});

group('.isAnagramOf()', () {
test('returns whether this String is an anagram of other', () {
expect('tacirupeca jaro'.isAnagramOf('Caperucita roja'), isTrue);
expect('tacirup膿ca j谩ro'.isAnagramOf('Caperucita roja'), isTrue);

expect('a'.isAnagramOf('Caperucita roja'), isFalse);
expect('tacirupeca jaro'.isAnagramOf('a'), isFalse);
expect('tacirupeca jare'.isAnagramOf('Caperucita roja'), isFalse);
});
});

group('.isVowel', () {
test('returns whether this String is a vowel', () {
expect('a'.isVowel, isTrue);
expect('脿'.isVowel, isTrue);
expect('e'.isVowel, isTrue);
expect('茅'.isVowel, isTrue);
expect('i'.isVowel, isTrue);
expect('茂'.isVowel, isTrue);
expect('o'.isVowel, isTrue);
expect('么'.isVowel, isTrue);
expect('奴'.isVowel, isTrue);

expect('b'.isVowel, isFalse);
expect('y'.isVowel, isFalse);
expect('aa'.isVowel, isFalse);
});
});
});
}

0 comments on commit ac9a6f9

Please sign in to comment.