Exemple #1
0
        public void TestExampleFromDescription()
        {
            string decodeBits = MorseCodeDecoder.DecodeBits("1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011");

            Assert.AreEqual(".... . -.--   .--- ..- -.. .", decodeBits);
            Assert.AreEqual("HEY JUDE", MorseCodeDecoder.DecodeMorse(decodeBits));
        }
Exemple #2
0
    public static string Decode(string morseCode)
    {
        morseCode = morseCode.Trim();
        Console.WriteLine(morseCode);

        char[]   delimiterChars           = { ' ' };
        string[] subCodes                 = morseCode.Split(delimiterChars);
        Dictionary <string, string> morse = MorseCodeDecoder.Codes();
        string        output;
        StringBuilder sb = new StringBuilder();
        int           i  = 0;

        foreach (string code in subCodes)
        {
            if (morse.ContainsKey(code))
            {
                morse.TryGetValue(code, out output);
                sb.Append(output);
                Console.WriteLine(output);
            }
            else
            {
                if (code.Length == 0 && i + 1 < subCodes.Length)
                {
                    if (subCodes[i + 1].Length == 0)
                    {
                        sb.Append(" ");
                    }
                }
            }
            i++;
        }

        return(sb.ToString());
    }
Exemple #3
0
        static void Main(string[] args)
        {
            var test = "1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011";
            var out1 = MorseCodeDecoder.DecodeBits(test);

            Console.WriteLine(out1);
            System.Console.WriteLine(MorseCodeDecoder.DecodeMorse(out1));
        }
Exemple #4
0
 static void Main(string[] args)
 {
     // for (int i = 'A'; i <= 'Z'; i++)
     // {
     //     System.Console.WriteLine(@"{"",'" + (char)i + @"'},");
     // }
     Console.WriteLine(MorseCodeDecoder.Decode("...---... -.-.--   - .... .   --.- ..- .. -.-. -.-   -... .-. --- .-- -.   ..-. --- -..-   .--- ..- -- .--. ...   --- ...- . .-.   - .... .   .-.. .- --.. -.--   -.. --- --. .-.-.- "));
 }
Exemple #5
0
        public void Decode_RegularString_CorrectResult()
        {
            string input    = ".... . -.--   .--- ..- -.. .";
            string expected = "HEY JUDE";

            string actual = MorseCodeDecoder.Decode(input);

            Assert.AreEqual(expected, actual);
        }
        public void Test1()
        {
            string input    = ".... . -.--   .--- ..- -.. .";
            string expected = "[L][L][L] [L][L][L][L]";

            string actual = MorseCodeDecoder.Decode(input);

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        public void MorseCodeDecoderBasicTest_1()
        {
            try
            {
                string input    = ".... . -.--   .--- ..- -.. .";
                string expected = "HEY JUDE";

                string actual = MorseCodeDecoder.Decode(input);

                Assert.AreEqual(expected, actual);
            }
            catch (Exception ex)
            {
                Assert.Fail("There seems to be an error somewhere in your code. Exception message reads as follows: " + ex.Message);
            }
        }
Exemple #8
0
        public void DecodeMorseLetter_SingleLetter_CorrectResult()
        {
            var morseDictionary = new Dictionary <string, string>
            {
                { ".-", "A" },
                { "-...", "B" },
                { "-.-.", "C" },
                { "-..", "D" },
                { ".", "E" },
                { "..-.", "F" },
                { "--.", "G" },
                { "....", "H" },
                { "..", "I" },
                { ".---", "J" },
                { "-.-", "K" },
                { ".-..", "L" },
                { "--", "M" },
                { "-.", "N" },
                { "---", "O" },
                { ".--.", "P" },
                { "--.-", "Q" },
                { ".-.", "R" },
                { "...", "T" },
                { "-", "S" },
                { "..-", "U" },
                { "...-", "V" },
                { ".--", "W" },
                { "-..-", "X" },
                { "-.--", "Y" },
                { "--..", "Z" },
                { "-.-.--", "!" },
                { ".-.-.-", "." },
                { " ", " " },
            };

            Assert.Multiple(() =>
            {
                foreach (var entry in morseDictionary)
                {
                    var input    = entry.Key;
                    var expected = entry.Value;
                    var actual   = MorseCodeDecoder.DecodeMorseLetter(input);
                    Assert.AreEqual(expected, actual);
                }
            });
        }
Exemple #9
0
    public void MorseCodeDecoderComplexTest_3()
    {
        try
        {
            string input =
                "      ...---... -.-.--   - .... .   --.- ..- .. -.-. -.-   -... .-. --- .-- -.   ..-. --- -..-   .--- ..- -- .--. ...   --- ...- . .-.   - .... .   .-.. .- --.. -.--   -.. --- --. .-.-.-  ";
            string expected = "SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.";

            string actual = MorseCodeDecoder.Decode(input);

            Assert.AreEqual(expected, actual);
        }
        catch (Exception ex)
        {
            Assert.Fail("There seems to be an error somewhere in your code. Exception message reads as follows: " +
                        ex.Message);
        }
    }
 static void Main(string[] args)
 {
     Console.WriteLine(MorseCodeDecoder.Decode("...---..."));
 }
Exemple #11
0
 public void MorseCodeTest()
 {
     Assert.AreEqual("HEY JUDE", MorseCodeDecoder.Decode(".... . -.--   .--- ..- -.. ."));
 }
Exemple #12
0
        public void Decode_SOSCodeTester(string input, string expected)
        {
            var actual = MorseCodeDecoder.Decode(input);

            Assert.AreEqual(expected, actual);
        }
Exemple #13
0
 public void MySolution()
 {
     Assert.AreEqual("HEY JUDE", MorseCodeDecoder.DecodeMySolution(".... . -.--   .--- ..- -.. ."));
     Assert.AreEqual("SOS", MorseCodeDecoder.DecodeMySolution("...---..."));
 }
Exemple #14
0
        static void Main(string[] args)
        {
            var test = "0000000011011010011100000110000001111110100111110011111100000000000111011111111011111011111000000101100011111100000111110011101100000100000";

            Console.WriteLine(MorseCodeDecoder.decodeBitsAdvanced(test));
        }