예제 #1
0
        private async Task <long> RunAndMeasureElapsedMs()
        {
            string morse = "--.----.......-.---.--......-..";

            ISet <string> dictionary = new HashSet <string>
            {
                "GOD", "IS", "NO", "NOW", "HERE", "WHERE",
                "HER", "GO", "ME", "MED", "MOD", "MO",
            };

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = morse,
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            await this.decoder.DecodeMorseSequenceAsync();

            stopwatch.Stop();
            return(stopwatch.ElapsedMilliseconds);
        }
예제 #2
0
        public void Setup()
        {
            ISet <string> dictionary = MorseDecoderTests.GetDefaultDictionary();

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = "--.----.......-.---.--......-..",
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };
        }
예제 #3
0
        public async Task TestHelloWorld()
        {
            ISet <string> dictionary = new HashSet <string>
            {
                "HELL", "HELLO", "OWORLD", "WORLD", "TEST"
            };

            this.decoder = new MorseDecoder()
            {
                MorseSequence      = "......-...-..---.-----.-..-..-..",
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            await this.decoder.DecodeMorseSequenceAsync();

            Assert.AreEqual(2, this.decoder.DecodedMessageCount);
        }
예제 #4
0
        public void TestDecodeMorse()
        {
            string morse = "--.-";

            ISet <string> dictionary = new HashSet <string>
            {
                "MA", "G", "M", "A", "T", "TNT"
            };

            this.decoder = new MorseDecoder()
            {
                FirstLetters       = MorseDecoderTests.GetFirstLetters(dictionary),
                WordsByFirstLetter = MorseDecoderTests.GetWordsByFirstLetter(dictionary)
            };

            ISet <KeyValuePair <string, string> > result = this.decoder.DecodeMorse(morse);

            Assert.AreEqual(6, result.Count);
        }