コード例 #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);
        }
コード例 #5
0
        public async Task TestGodIsNowHere()
        {
            string morse = "--.----.......-.---.--......-..";

            IEnumerable <string> solution = await this.decoder.DecodeAndReturnMessagesAsync(morse, MorseDecoderTests.GetDefaultDictionary());

            Assert.AreEqual(6, solution.Count());
            Assert.IsTrue(solution.Contains("GOD E E E E E NOW HERE"));
            Assert.IsTrue(solution.Contains("GOD E E E E E NOW HER E"));
            Assert.IsTrue(solution.Contains("GOD E E E E E NO WHERE"));
            Assert.IsTrue(solution.Contains("GOD IS NOW HERE"));
            Assert.IsTrue(solution.Contains("GOD IS NOW HER E"));
            Assert.IsTrue(solution.Contains("GOD IS NO WHERE"));
        }