Ejemplo n.º 1
0
        public void TreatTransaction(string rawTransaction)
        {
            var parts       = rawTransaction.Split(' ');
            var transaction = (TransactionType)Enum.Parse(typeof(TransactionType), parts[0], true);
            var word        = parts[1];

            switch (transaction)
            {
            case TransactionType.Add:
                _contacts.Add(word);
                break;

            case TransactionType.Find:
                _printer.Print(_contacts.Find(word));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        public void Should_return_number_of_words_when_find_for_prefix()
        {
            var input   = new[] { "CAR", "CARD", "CARDAN", "TRY", "TRIES", "TRIED" };
            var printer = new FakePrinter("{0:#}");
            var tries   = new Tries();

            foreach (var s in input)
            {
                tries.Add(s);
            }

            var cCount = tries.Find("C");

            Assert.Equal(3, cCount);
            var carCount = tries.Find("CAR");

            Assert.Equal(3, carCount);
            var cardCount = tries.Find("CARD");

            Assert.Equal(2, cardCount);
            var cardanCount = tries.Find("CARDAN");

            Assert.Equal(1, cardanCount);

            var tCount = tries.Find("T");

            Assert.Equal(3, tCount);
            var trCount = tries.Find("TR");

            Assert.Equal(3, trCount);
            var tryCount = tries.Find("TRY");

            Assert.Equal(1, tryCount);
            var trieCount = tries.Find("TRIE");

            Assert.Equal(2, trieCount);
            var triesCount = tries.Find("TRIES");

            Assert.Equal(1, triesCount);
            var triedCount = tries.Find("TRIED");

            Assert.Equal(1, triedCount);

            var nCount = tries.Find("N");

            Assert.Equal(0, nCount);

            tries.Print(printer);

            foreach (var s in input)
            {
                Assert.Contains(s, printer.Printed);
            }
            Assert.Equal(6, printer.Printed.Count);
        }