public void Test01()
        {
            var instance    = new AutocompleteSystem(new [] { "i love you", "island", "ironman", "i love leetcode" }, new [] { 5, 3, 2, 2 });
            var queryResult = instance.Input('i');

            PrintQueryResult(queryResult);

            queryResult = instance.Input(' ');
            PrintQueryResult(queryResult);

            queryResult = instance.Input('a');
            PrintQueryResult(queryResult);

            queryResult = instance.Input('#');
            PrintQueryResult(queryResult);

            queryResult = instance.Input('i');
            PrintQueryResult(queryResult);

            queryResult = instance.Input(' ');
            PrintQueryResult(queryResult);

            queryResult = instance.Input('a');
            PrintQueryResult(queryResult);

            queryResult = instance.Input('#');
            PrintQueryResult(queryResult);
        }
        public void EmptyTest()
        {
            var sut    = new AutocompleteSystem(new string[] { "d", "a", "deer", "deal" });
            var result = sut.Query("");

            ArraysEqual(result, new string[] { });
        }
        public void OtherTest1()
        {
            var sut    = new AutocompleteSystem(new string[] { "", "d", "a", "deer", "deal", "buzzword", "buz1word" });
            var result = sut.Query("buzz");

            ArraysEqual(result, new string[] { "buzzword" });
        }
        public void ReferenceTest()
        {
            var sut    = new AutocompleteSystem(new string[] { "dog", "deer", "deal" });
            var result = sut.Query("de");

            ArraysEqual(result, new string[] { "deer", "deal" });
        }
Beispiel #5
0
        public void Test2()
        {
            var strings = new string[] { "uqpewwnxyqxxlhiptuzevjxbwedbaozz", "ewftoujyxdgjtazppyztom", "pvyqceqrdrxottnukgbdfcr", "qtdkgdbcyozhllfycfjhdsdnuhycqcofaojknuqqnozltrjcabyxrdqwrxvqrztkcxpenbbtnnnkfhmebj", "jwfbusbwahyugiaiazysqbxkwgcawpniptbtmhqyrlxdwxxwhtumglihrgizrczv", "cfptjitfzdcrhw", "aitqgitjgrcbacgnaasvbouqsqcwbyskkpsnigtfeecmlkcjbgduban", "utsqkmiqqgglufourfdpgdmrkbippffacwvtkpflzrvdlkdxykfpkoqcb", "ethtbdopotpamvrwuomlpahtveyw", "jiaqkaxovsqtkpdjfbkajpvpyetuoqwnrnpjdhoojbsdvneecsdvgqpyurmsvcy", "j", "btbnuplyeuccjbernsfbnveillrwdbqledwvpmvdbcugkurrkabtpykhlcogeszclyfuquafouv", "hndjzblegevtfkgbjttektox", "gtvnlninpvenapyfgmsjdisfnmiktitrutctawosjflvzfkbegnprixzqwzcyhoovsivuwmofsveqkyosowuyamuvy", "sawrirvrfrbfagreahrioaombukmdwztbpggnxd", "mgdcwptvbvhzyvvumvbjjn", "otjvvkegwleyyxtghwgfmlsqlhrlibdvqfinyyebotjpwoaejhtornfgikmifdmwswbqgwhcbzuhrpajxuqicegcptszct", "zlondsttyvnnnnxjtoqnlktitwzurissczzbyfsbgpoawodwjpsmavaugnhqtsbeixwl", "yehvdehbtmwqkmcjmvpivfzqvevkotwzvjoyfvp", "bjximtpayjdcxbrnksbtfnpynzaygygdflowewprqngdadzdhxcpgapjejojrkzrutgcsfpfvpluagniqimfqddldxqiw", "bysyrxfykivyauysytgxfhqcrxliulahuizjvozpywrokxujhzpauxwufcxiitukljiiclatfrspqcljjoxpxziumstnhqr", "uxtvutlgqapyfltiulwrplesmtowzoyhhjhzihatpuvmutxqgxfawpwypedbz", "jzgsdjdawrqfladolduldhpdpagmvllvzamypuqlrpbmhxxadqaqrqavtxeghcyysjynovkiyjtvdluttodtmtocajgttmv", "mbijfkmepalhdiubposdksdmmttxblkodcdrxbnxaqebnwliatnxpwaohbwkidia", "ljggggbyxwrwanhjonoramexdmgjigrtpz", "cqfvkutpipxjepfgsufonvjtotwfxyn", "kvseesjazssavispavchdpzvdhibptowhyrrshyntpwkez", "nveuzbaosuayteiozmnelxlwkrrrjlwvhejxhupvchfwmvnqukphgoacnazuoimcliubvhv", "uwrpwhfdrxfnarxqpkhrylkwiuhzubjfk", "bniyggdcloefwy", "ihranmhbsahqjxesbtmdkjfsupzdzjvdfovgbtwhqfjdddwhdvrnlyscvqlnqpzegnvvzyymrajvso", "lscreasfuxpdxsiinymuzybjexkpfjiplevqcjxlm", "uwgnfozopsygnmptdtmmuumahoungpkodwxrcvfymqpeymaqruayvqqgoddgbnhemtsjifhxwiehncswxzrghf", "nyfbxgcpfrzyqwfjzgmhuohjhrjizsyjqgmertmooeiaadcmiuyyylpcosnweoyydeauazhzbeaqn", "tpylrxbwnkrfxckfdlvrbytaezuzmyscpvruthuvbxjenkeolvqsrjqzizyclzmqtjvnamdansmzyspcfghfprorqprua", "nhldlmxpuckxeekipkrzugatjiivtazjbjyxokksyueyjbgmrovbckbxqcqefaiavzsarbbypgmpxe", "sylraqsd", "xr", "xkzpxkhrucyatpatkigvntohihibyisyqtkjdhatdvyvxbjttz", "nvnz", "blzddwxphkgqfsfzfclwytstpvpzgcdeggdwzukzirscfzcteeuqbmmrfxcnokbbyxkqrxtjfarcefiynwfmy", "inuxmuhtdwpuvyludwtokhtalxbuccepsayrjycbcwbtnfholjvkmypodv", "awwillrm", "xznodxngrstjrwqzmlmigpw", "khlxjdtictufdfbkgfusdtaaeuspbbfmtjodflgqofzlqnulkdztflm", "nlngmckslyqzjiyiexbropbxnynjcstziluewypboqhqndqsxhtnosrgrameajovsclrgwqjgnztvxrkhwnxkfrf", "yroadxhxyacaexrwju", "ujxlbpcbxdqrvubifnpzjmmkolyljzjhdegaiowaal", "tnfnjgtxbckbpyplucprxcqzhrfjimylmlhdglntfydepltjvklyxesndzuubienhvuaqc", "ouedhtkpkg", "ygchsrrubucqffewifsxaefwocfaiiupqbomktvrcddggqfgnaycstpccwtbheyaqwhosxajqeqqxzyjsfng", "jqqgpjvfkgjh", "csowoazaiyejgyixszqmtctpzlkccccqregyhtvxccvrpkupwcyhqatxscevzdfbdqnuyadiyfnhysddfyxpgqtjiogmxsmzbbkr", "dlzxdpchkdaztkqtrjmuujgoiae", "plcjkwukkyqluxjbhxsyeaqvviinfuujsafwsquidvmutsrukxwrv", "yopqbtpoqhpcktjangauzcvvpephhprpaaclbbkgchlqkrwdsaupeizlwxzcpkchoagmrrkwdkthosmrjefgbumnrjsb" };
            var times   = new int[] { 12, 9, 4, 4, 1, 5, 3, 4, 7, 9, 2, 4, 2, 3, 11, 13, 1, 3, 4, 10, 7, 1, 9, 5, 10, 14, 5, 3, 2, 11, 5, 14, 4, 13, 11, 5, 15, 8, 1, 12, 2, 11, 4, 2, 11, 14, 9, 12, 1, 7, 13, 11, 7, 2, 6, 10 };
            var ac      = new AutocompleteSystem(strings, times);

            ac.Input('w').Should().Equal();
            ac.Input('o').Should().Equal();
            ac.Input('f').Should().Equal();
        }
Beispiel #6
0
        private static void Run()
        {
            var sentences          = new string[] { "i love you", "island", "iroman", "i love leetcode" };
            var times              = new int[] { 5, 3, 2, 2 };
            var autocompleteSystem = new AutocompleteSystem(sentences, times);

            autocompleteSystem.Input('i');
            autocompleteSystem.Input(' ');
            autocompleteSystem.Input('a');
            autocompleteSystem.Input('#');
        }
Beispiel #7
0
        public void Run()
        {
            var instance = new AutocompleteSystem(new string[] { "i love you", "island", "iroman", "i love leetcode" }, new int[] { 5, 3, 2, 2 });

            for (int i = 0; i < 3; i++)
            {
                var r = instance.Input('i');
                r = instance.Input(' ');
                r = instance.Input('a');
                r = instance.Input('#');
            }
        }
Beispiel #8
0
        public void Test1()
        {
            var strings = new string[] { "i love you", "island", "iroman", "i love leetcode" };
            var times   = new int[] { 5, 3, 2, 2 };
            var ac      = new AutocompleteSystem(strings, times);

            ac.Input('i').Should().Equal("i love you", "island", "i love leetcode");
            ac.Input(' ').Should().Equal("i love you", "i love leetcode");
            ac.Input('a').Should().Equal();
            ac.Input('#').Should().Equal();
            ac.Input('i').Should().Equal("i love you", "island", "i love leetcode");
            ac.Input(' ').Should().Equal("i love you", "i love leetcode", "i a");
            ac.Input('a').Should().Equal("i a");
            ac.Input('#').Should().Equal();
            ac.Input('i').Should().Equal("i love you", "island", "i a");
            ac.Input(' ').Should().Equal("i love you", "i a", "i love leetcode");
            ac.Input('a').Should().Equal("i a");
            ac.Input('#').Should().Equal();
        }
Beispiel #9
0
        protected override void Run()
        {
            AutocompleteSystem autocompleteSystem = new AutocompleteSystem();

            WORDS.ForEach(autocompleteSystem.Add);

            Console.Write("Insert the prefix: ");
            string prefix = Console.ReadLine();

            Console.WriteLine("\nPrefix readed: '" + prefix + "'.\n");

            List <string> words = autocompleteSystem.FindWordByPrefix(prefix);

            if (0 == words.Count)
            {
                Console.WriteLine("No words founded.");
            }
            else
            {
                Console.WriteLine("Words founded:");
            }
            words.ForEach(Console.WriteLine);
        }
        public void Tests()
        {
            var system = new AutocompleteSystem(
                new[] { "abc", "abbc", "a" },
                new [] { 3, 3, 3 });

            var result = system.Input('b');

            Assert.Equal(new string[0], result);
            result = system.Input('c');
            Assert.Equal(new string[0], result);
            result = system.Input('#');
            Assert.Equal(new string[0], result);
            result = system.Input('b');
            Assert.Equal(new [] { "bc" }.OrderBy(x => x), result);
            result = system.Input('c');
            Assert.Equal(new [] { "bc" }.OrderBy(x => x), result);
            result = system.Input('#');
            Assert.Equal(new string[0], result);

            result = system.Input('a');
            Assert.Equal(new[] { "a", "abbc", "abc" }, result);
            result = system.Input('b');
            Assert.Equal(new[] { "abbc", "abc" }, result);
            result = system.Input('c');
            Assert.Equal(new[] { "abc" }, result);
            result = system.Input('#');
            Assert.Equal(new string[0], result);
            result = system.Input('a');
            Assert.Equal(new[] { "abc", "a", "abbc" }, result);
            result = system.Input('b');
            Assert.Equal(new[] { "abc", "abbc" }, result);
            result = system.Input('c');
            Assert.Equal(new[] { "abc" }, result);
            result = system.Input('#');
            Assert.Equal(new string[0], result);
        }