public void EncodingWorksForExactValue() { var result = _encodeService.Encode("Hello"); var expectedResult = StringToMorseTextTranlator.Translate(".... . .-.. .-.. ---"); Assert.Equal(result, expectedResult); }
public void DecodeThorwsExceptionWhenSymbolIsInvalid() { var text = ".......- -.-."; var message = StringToMorseTextTranlator.Translate(text); var exception = Assert.Throws <FormatException>(() => _decodeService.Decode(message)); Assert.Equal("Symbol is undecodable", exception.Message); }
public void DecodeWorksForExactValue() { var text = ".- -... -.-. -.."; var message = StringToMorseTextTranlator.Translate(text); var result = _decodeService.Decode(message); Assert.Equal("ABCD", result); }
private static void Test2() { var wavFileHandler = new WavFileHandler(); var text = ".- ---. . -"; var message = StringToMorseTextTranlator.Translate(text); wavFileHandler.CreateFile("a", message); var decodedMessage = wavFileHandler.ReadFromFile("a.wav"); Console.Write(string.Join(",", decodedMessage.ToString())); Console.WriteLine(); }
private static void Test() { var translator = new MorseToEngTranslator(); var morseDecodeService = new MorseDecodeService(translator); var morseEncodeService = new MorseEncodeService(translator); var element = new MorseElement("."); var text = ".-. -.- .- ."; var message = StringToMorseTextTranlator.Translate(text); Console.WriteLine(morseDecodeService.Decode(message)); var encoded = morseEncodeService.Encode("Hello world"); Console.Write(encoded); }
public MorseText ReadFromFile(string filepath) { var wav = File.ReadAllBytes(filepath); var dataBeginIndex = GetSoundBeginningIndex(wav); var decodedMessage = ""; var beenSilent = false; for (var i = dataBeginIndex; i < wav.Length;) { switch (wav[i]) { case (AMPLITUDE & 0xff): { decodedMessage += '-'; i += 4 * LONG_BEEP; beenSilent = false; break; } case (2 * AMPLITUDE & 0xff): { decodedMessage += '.'; i += 4 * SHORT_BEEP; beenSilent = false; break; } case 0: { i += 4 * SILENCE; if (beenSilent) { decodedMessage += " "; } beenSilent = true; break; } default: { throw new FormatException("Wrong wav format"); break; } } } var text = StringToMorseTextTranlator.Translate(decodedMessage); return(text); }