Example #1
0
        static void Main(string[] args)
        {
            //var text = "ddabcd";
            //var tree = new SuffixTree<char>(text.ToCharArray(), "abcd");
            //var result = tree.FindAllOccurrences("dd".ToCharArray());
            //Console.WriteLine(string.Join(" ", result));

            //throw new Exception("kek");

            var documents = new List <KeyValuePair <string, byte[]> >();

            foreach (var file in Directory.GetFiles(@"..\..\docs\", "*"))
            {
                string docKey     = Path.GetFileName(file);
                byte[] docContent = File.ReadAllBytes(file);
                documents.Add(new KeyValuePair <string, byte[]>(docKey, docContent));
            }

            var docIndex = new DocumentIndex(documents);
            var got      = docIndex.ReportOccurrences(Encoding.ASCII.GetBytes("TEST"));
            var expected = new Dictionary <string, int[]> {
                { "readme.txt", new[] { 0, 830, 1713 } },
                { "task-Match2d.txt", new[] { 679 } },
                { "task-Zfunc.txt", new[] { 2813 } }
            };

            Console.WriteLine(AreSame(got, expected) ? "Test passed" : "Test not passed");

            got      = docIndex.ReportOccurrences(Encoding.UTF8.GetBytes("то есть"));
            expected = new Dictionary <string, int[]> {
                { "bierce.txt", new[] { 1305, 2916 } },
                { "task-LZW.txt", new[] { 472, 1207 } },
                { "task-Match2d.txt", new[] { 409 } },
            };

            Console.WriteLine(AreSame(got, expected) ? "Test passed" : "Test not passed");
        }