示例#1
0
        public void EncodingWorksForExactValue()
        {
            var result         = _encodeService.Encode("Hello");
            var expectedResult =
                StringToMorseTextTranlator.Translate(".... . .-.. .-.. ---");

            Assert.Equal(result, expectedResult);
        }
示例#2
0
        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);
        }
示例#3
0
        public void DecodeWorksForExactValue()
        {
            var text    = ".- -... -.-. -..";
            var message = StringToMorseTextTranlator.Translate(text);
            var result  = _decodeService.Decode(message);

            Assert.Equal("ABCD", result);
        }
示例#4
0
        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();
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }