From 20220a30fad9b616eb759ce61f3537345511bde8 Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Mon, 30 May 2016 23:18:43 +0200 Subject: [PATCH] Tests for Dart code --- README.md | 8 ++-- pubspec.yaml | 9 +++++ test/CodeRecognization_test.dart | 19 ++++++++++ test/Convert_test.dart | 63 ++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 pubspec.yaml create mode 100644 test/CodeRecognization_test.dart create mode 100644 test/Convert_test.dart diff --git a/README.md b/README.md index 1f13aa8..05c1339 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..ff1d593 --- /dev/null +++ b/pubspec.yaml @@ -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) +homepage: https://mmk2410.org/writtenmorse/ +documentation: https://mmk2410.org/writtenmorse/ +dependencies: + test: "^0.12.13+4" diff --git a/test/CodeRecognization_test.dart b/test/CodeRecognization_test.dart new file mode 100644 index 0000000..5912cd1 --- /dev/null +++ b/test/CodeRecognization_test.dart @@ -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); + }); + + }); + +} diff --git a/test/Convert_test.dart b/test/Convert_test.dart new file mode 100644 index 0000000..8b23272 --- /dev/null +++ b/test/Convert_test.dart @@ -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#
#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 = """ +.-.. --- .-. . -- .. .--. ... ..- -- -.. --- .-.. --- .-. ... .. - .- -- . - --..-- -.-. --- -. ... . -.-. - . - ..- .-. .- -.. .. .--. .. ... -.-. .. -. --. . .-.. .. - .-.-.- .--. . .-.. .-.. . -. - . ... --.- ..- . .. -. ...- .- .-. .. ..- ... .- ..- --. ..- . .-.-.- ... ..- ... .--. . -. -.. .. ... ... . -. --- -. . .-.. .. - - .-. .. ... - .. --.- ..- . . ... - ..-. .-. .. -. --. .. .-.. .-.. .- - . -- .--. --- .-. .-.-.- .-.. --- .-. . -- .. .--. ... ..- -- -.. --- .-.. --- .-. ... .. - .- -- . - --..-- -.-. --- -. ... . -.-. - . - ..- .-. .- -.. .. .--. .. ... -.-. .. -. --. . .-.. .. - .-.-.- -. ..- .-.. .-.. .- ...- . ... - .. -... ..- .-.. ..- -- -.. ..- .. . ..- -. . --.- ..- . . ..-. ..-. .. -.-. .. - ..- .-. -.-. --- -. ... . --.- ..- .- - .-.-.- -.. --- -. . -.-. --- .-. -. .- .-. . -.-. --- -. --. ..- . ..-. .- -.-. .. .-.. .. ... .. ... .-.-.- -.. ..- .. ... -.-. --- -. ... . --.- ..- .- - . ... - .-.. . -.-. - ..- ... --..-- ... .. - .- -- . - .... . -. -.. .-. . .-. .. - . .-. .- - . ..- .. ... -- --- -.. ...- . .-.. .-.-.-
-- .- . -.-. . -. .- ... -. .. ... .. .-.. . --- --..-- -.-. --- -- -- --- -.. --- . --. . - ...- . .... .. -.-. ..- .-.. .- .- --..-- .- .-.. .. --.- ..- . - -. . -.-. .--. ..- .-. ..- ... .-.-.- .- . -. . .- -. . --. . - -.. .. -.-. - ..- -- - ..- .-. .--. .. ... .-.-.- .. -. ... .. - .- -- . - ...- --- .-.. ..- - .--. .- - -. .. ... .-.. --..-- . - --- .-. -. .- .-. . ..- .-. -. .- .-.-.- . - .. .- -- . --. . - -.-. ..- .-. ... ..- ... .. .--. ... ..- -- .-.-.- ...- . ... - .. -... ..- .-.. ..- -- . - -- .- --. -. .- .. -.. -- . - ..- ... -.-. ..- .-. ... ..- ... ..- .-.. .-.. .- -- -.-. --- .-. .--. . .-. .-.-.- -.. --- -. . -.-. --- .-. -. .- .-. . .-.. .. -... . .-. --- .- -.-. . -. .. -- -.-. --- -. ... . -.-. - . - ..- .-. --..-- ... .. - .- -- . - -- .- .-.. . ... ..- .- -.. .- --- -.. .. --- -.. .. --. -. .. ... ... .. -- .-.-.- .- . -. . .- -. -.. ..- .. -. .. ... .-.. --..-- .--. --- ... ..- . .-. . .- --- .-. -.-. .. ... . -.. --..-- -... .. -... . -. -.. ..- -- ..-. .-. .. -. --. .. .-.. .-.. .- .-.. . -.-. - ..- ... .-.-.-"""; + +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("
", "\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("
", "\n"); + expect(Convert.getMorseDecoded(string), equals(text.toUpperCase())); + }); + + test("Convert.getMorseDecoded() convert a special symbol.", () { + String string = "...-."; + expect(Convert.getMorseDecoded(string), equals("UNDERSTOOD")); + }); + + }); + +}