Tests for Dart code
This commit is contained in:
parent
497a087270
commit
20220a30fa
4 changed files with 96 additions and 3 deletions
|
@ -12,9 +12,11 @@ The webapp can be accessed at [marcel-kapfer.de/writtenmorse/morseconverter](htt
|
|||
|
||||
1. Fork it
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create New Pull Request
|
||||
3. Write your code and the tests for it.
|
||||
4. Check if the code passes the tests. (`pub run text`). A code which does not passes the tests will not merged.
|
||||
5. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
6. Push to the branch (`git push origin my-new-feature`)
|
||||
7. Create New Pull Request
|
||||
|
||||
## Build
|
||||
|
||||
|
|
9
pubspec.yaml
Normal file
9
pubspec.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
name: morse_converter_web
|
||||
version: 0.3.0
|
||||
description: >
|
||||
A Morse and writtenMorse converter for the web using modern technologies like Dart and Polymer.
|
||||
author: Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
homepage: https://mmk2410.org/writtenmorse/
|
||||
documentation: https://mmk2410.org/writtenmorse/
|
||||
dependencies:
|
||||
test: "^0.12.13+4"
|
19
test/CodeRecognization_test.dart
Normal file
19
test/CodeRecognization_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import "package:test/test.dart";
|
||||
|
||||
import '../app/scripts/CodeRecognization.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
group("writtenMorse", () {
|
||||
|
||||
test("CodeRecognization.isMorse() check if text is morse code", () {
|
||||
expect(CodeRecognization.isMorseCode(".-.. --- .-. . --"), isTrue);
|
||||
});
|
||||
|
||||
test("CodeRecognization.isMorse() check if text is not morse code", () {
|
||||
expect(CodeRecognization.isMorseCode("message1238170"), isFalse);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
63
test/Convert_test.dart
Normal file
63
test/Convert_test.dart
Normal file
|
@ -0,0 +1,63 @@
|
|||
import 'package:test/test.dart';
|
||||
|
||||
import '../app/scripts/Convert.dart';
|
||||
|
||||
String text = """
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in varius augue. Suspendisse non elit tristique est fringilla tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vestibulum dui eu neque efficitur consequat. Donec ornare congue facilisis. Duis consequat est lectus, sit amet hendrerit erat euismod vel.
|
||||
Maecenas nisi leo, commodo eget vehicula a, aliquet nec purus. Aenean eget dictum turpis. In sit amet volutpat nisl, et ornare urna. Etiam eget cursus ipsum. Vestibulum et magna id metus cursus ullamcorper. Donec ornare libero ac enim consectetur, sit amet malesuada odio dignissim. Aenean dui nisl, posuere a orci sed, bibendum fringilla lectus.""";
|
||||
|
||||
String writtenMorse = """
|
||||
0100#111#010#0#11+00#0110#000#001#11+100#111#0100#111#010+000#00#1+01#11#0#1#110011+1010#111#10#000#0#1010#1#0#1#001#010+01#100#00#0110#00#000#1010#00#10#110+0#0100#00#1#010101+0110#0#0100#0100#0#10#1#0#000#1101#001#0+00#10+0001#01#010#00#001#000+01#001#110#001#0#010101+000#001#000#0110#0#10#100#00#000#000#0+10#111#10+0#0100#00#1+1#010#00#000#1#00#1101#001#0+0#000#1+0010#010#00#10#110#00#0100#0100#01+1#0#11#0110#111#010#010101+0100#111#010#0#11+00#0110#000#001#11+100#111#0100#111#010+000#00#1+01#11#0#1#110011+1010#111#10#000#0#1010#1#0#1#001#010+01#100#00#0110#00#000#1010#00#10#110+0#0100#00#1#010101+10#001#0100#0100#01+0001#0#000#1#00#1000#001#0100#001#11+100#001#00+0#001+10#0#1101#001#0+0#0010#0010#00#1010#00#1#001#010+1010#111#10#000#0#1101#001#01#1#010101+100#111#10#0#1010+111#010#10#01#010#0+1010#111#10#110#001#0+0010#01#1010#00#0100#00#000#00#000#010101+100#001#00#000+1010#111#10#000#0#1101#001#01#1+0#000#1+0100#0#1010#1#001#000#110011+000#00#1+01#11#0#1+0000#0#10#100#010#0#010#00#1+0#010#01#1+0#001#00#000#11#111#100+0001#0#0100#010101#<br>#11#01#0#1010#0#10#01#000+10#00#000#00+0100#0#111#110011+1010#111#11#11#111#100#111+0#110#0#1+0001#0#0000#00#1010#001#0100#01+01#110011+01#0100#00#1101#001#0#1+10#0#1010+0110#001#010#001#000#010101+01#0#10#0#01#10+0#110#0#1+100#00#1010#1#001#11+1#001#010#0110#00#000#010101+00#10+000#00#1+01#11#0#1+0001#111#0100#001#1#0110#01#1+10#00#000#0100#110011+0#1+111#010#10#01#010#0+001#010#10#01#010101+0#1#00#01#11+0#110#0#1+1010#001#010#000#001#000+00#0110#000#001#11#010101+0001#0#000#1#00#1000#001#0100#001#11+0#1+11#01#110#10#01+00#100+11#0#1#001#000+1010#001#010#000#001#000+001#0100#0100#01#11#1010#111#010#0110#0#010#010101+100#111#10#0#1010+111#010#10#01#010#0+0100#00#1000#0#010#111+01#1010+0#10#00#11+1010#111#10#000#0#1010#1#0#1#001#010#110011+000#00#1+01#11#0#1+11#01#0100#0#000#001#01#100#01+111#100#00#111+100#00#110#10#00#000#000#00#11#010101+01#0#10#0#01#10+100#001#00+10#00#000#0100#110011+0110#111#000#001#0#010#0+01+111#010#1010#00+000#0#100#110011+1000#00#1000#0#10#100#001#11+0010#010#00#10#110#00#0100#0100#01+0100#0#1010#1#001#000#010101""";
|
||||
|
||||
String morse = """
|
||||
.-.. --- .-. . -- .. .--. ... ..- -- -.. --- .-.. --- .-. ... .. - .- -- . - --..-- -.-. --- -. ... . -.-. - . - ..- .-. .- -.. .. .--. .. ... -.-. .. -. --. . .-.. .. - .-.-.- .--. . .-.. .-.. . -. - . ... --.- ..- . .. -. ...- .- .-. .. ..- ... .- ..- --. ..- . .-.-.- ... ..- ... .--. . -. -.. .. ... ... . -. --- -. . .-.. .. - - .-. .. ... - .. --.- ..- . . ... - ..-. .-. .. -. --. .. .-.. .-.. .- - . -- .--. --- .-. .-.-.- .-.. --- .-. . -- .. .--. ... ..- -- -.. --- .-.. --- .-. ... .. - .- -- . - --..-- -.-. --- -. ... . -.-. - . - ..- .-. .- -.. .. .--. .. ... -.-. .. -. --. . .-.. .. - .-.-.- -. ..- .-.. .-.. .- ...- . ... - .. -... ..- .-.. ..- -- -.. ..- .. . ..- -. . --.- ..- . . ..-. ..-. .. -.-. .. - ..- .-. -.-. --- -. ... . --.- ..- .- - .-.-.- -.. --- -. . -.-. --- .-. -. .- .-. . -.-. --- -. --. ..- . ..-. .- -.-. .. .-.. .. ... .. ... .-.-.- -.. ..- .. ... -.-. --- -. ... . --.- ..- .- - . ... - .-.. . -.-. - ..- ... --..-- ... .. - .- -- . - .... . -. -.. .-. . .-. .. - . .-. .- - . ..- .. ... -- --- -.. ...- . .-.. .-.-.- <br> -- .- . -.-. . -. .- ... -. .. ... .. .-.. . --- --..-- -.-. --- -- -- --- -.. --- . --. . - ...- . .... .. -.-. ..- .-.. .- .- --..-- .- .-.. .. --.- ..- . - -. . -.-. .--. ..- .-. ..- ... .-.-.- .- . -. . .- -. . --. . - -.. .. -.-. - ..- -- - ..- .-. .--. .. ... .-.-.- .. -. ... .. - .- -- . - ...- --- .-.. ..- - .--. .- - -. .. ... .-.. --..-- . - --- .-. -. .- .-. . ..- .-. -. .- .-.-.- . - .. .- -- . --. . - -.-. ..- .-. ... ..- ... .. .--. ... ..- -- .-.-.- ...- . ... - .. -... ..- .-.. ..- -- . - -- .- --. -. .- .. -.. -- . - ..- ... -.-. ..- .-. ... ..- ... ..- .-.. .-.. .- -- -.-. --- .-. .--. . .-. .-.-.- -.. --- -. . -.-. --- .-. -. .- .-. . .-.. .. -... . .-. --- .- -.-. . -. .. -- -.-. --- -. ... . -.-. - . - ..- .-. --..-- ... .. - .- -- . - -- .- .-.. . ... ..- .- -.. .- --- -.. .. --- -.. .. --. -. .. ... ... .. -- .-.-.- .- . -. . .- -. -.. ..- .. -. .. ... .-.. --..-- .--. --- ... ..- . .-. . .- --- .-. -.-. .. ... . -.. --..-- -... .. -... . -. -.. ..- -- ..-. .-. .. -. --. .. .-.. .-.. .- .-.. . -.-. - ..- ... .-.-.-""";
|
||||
|
||||
void main() {
|
||||
|
||||
group("writtenMorse", () {
|
||||
|
||||
test("Convert.getWrittenMorseEncoded() convert lorem ipsum text.", () {
|
||||
expect(Convert.getWrittenMorseEncoded(text), equals(writtenMorse));
|
||||
});
|
||||
|
||||
test("Convert.getWrittenMorseEncoded() convert a special symbol.", () {
|
||||
String string = "UNDERSTOOD";
|
||||
expect(Convert.getWrittenMorseEncoded(string), equals("00010"));
|
||||
});
|
||||
|
||||
test("Convert.getWrittenMorseDecoded() convert lorem ipsum writtenMorse code.", () {
|
||||
String string = writtenMorse.replaceAll("<br>", "\n");
|
||||
expect(Convert.getWrittenMorseDecoded(string), equals(text.toUpperCase()));
|
||||
});
|
||||
|
||||
test("Convert.getWrittenMorseDecoded() convert a special symbol.", () {
|
||||
String string = "00010";
|
||||
expect(Convert.getWrittenMorseDecoded(string), equals("UNDERSTOOD"));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
group("Morse", () {
|
||||
|
||||
test("Convert.getMorseEncoded() convert lorem ipsum text.", () {
|
||||
expect(Convert.getMorseEncoded(text), equals(morse));
|
||||
});
|
||||
|
||||
test("Convert.getMorseEncoded() convert a special symbol.", () {
|
||||
String string = "UNDERSTOOD";
|
||||
expect(Convert.getMorseEncoded(string), equals("...-."));
|
||||
});
|
||||
|
||||
test("Convert.getMorseDecoded() convert lorem ipsum writtenMorse code.", () {
|
||||
String string = morse.replaceAll("<br>", "\n");
|
||||
expect(Convert.getMorseDecoded(string), equals(text.toUpperCase()));
|
||||
});
|
||||
|
||||
test("Convert.getMorseDecoded() convert a special symbol.", () {
|
||||
String string = "...-.";
|
||||
expect(Convert.getMorseDecoded(string), equals("UNDERSTOOD"));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
Reference in a new issue