Exemplo n.º 1
0
        public void TestSample_04_RowByRowScanner()
        {
            //Arrange
            string[] text1 =
            {
                "Row1",
                "Row2",
                "Row3",
                "Row4",
                "Row5",
                "Row6",
                "Row7",

                "Row1",
                "Row2",
                "Row3",
                "Row4.1"
            };

            string[] text2 =
            {
                "Row1",
                "Row2",
                "Row3",
                "Row4.1",

                "Row1",
                "Row2",
                "Row3",
                "Row4",
                "Row5",
                "Row6",

                "Row1",
                "Row2",
                "Row3",

                "Row1",
                "Row2",
                "Row3",
                "Row4.1",
                "Row5",

                "Row1",
                "Row2",
                "Row3"
            };


            var sourceQueue = new Queue <ScanSource>();

            sourceQueue.Enqueue(new ScanSource()
            {
                Name = "Text1", Text = string.Join(envNewLine, text1)
            });
            sourceQueue.Enqueue(new ScanSource()
            {
                Name = "Text2", Text = string.Join(envNewLine, text2)
            });

            ///

            string[] duplicateText_01 =
            {
                "Row1",
                "Row2",
                "Row3",
                "Row4",
                "Row5",
                "Row6"
            };

            var text1Info_01 = new FileWithDuplicates()
            {
                Name = "Text1",
                DupliateItemCount = 1,
                Path = ""
            };

            var text2Info_01 = new FileWithDuplicates()
            {
                Name = "Text2",
                DupliateItemCount = 1,
                Path = ""
            };

            var duplicateFilesInfos_01 = new List <FileWithDuplicates>()
            {
                text1Info_01,
                text2Info_01
            };

            ///

            string[] duplicateText_02 =
            {
                "Row1",
                "Row2",
                "Row3",
                "Row4.1"
            };

            var text1Info_02 = new FileWithDuplicates()
            {
                Name = "Text1",
                DupliateItemCount = 1,
                Path = ""
            };

            var text2Info_02 = new FileWithDuplicates()
            {
                Name = "Text2",
                DupliateItemCount = 2,
                Path = ""
            };

            var duplicateFilesInfos_02 = new List <FileWithDuplicates>()
            {
                text1Info_02,
                text2Info_02
            };

            ///

            string[] duplicateText_03 =
            {
                "Row1",
                "Row2",
                "Row3"
            };

            var text1Info_03 = new FileWithDuplicates()
            {
                Name = "Text1",
                DupliateItemCount = 2,
                Path = ""
            };

            var text2Info_03 = new FileWithDuplicates()
            {
                Name = "Text2",
                DupliateItemCount = 2,
                Path = ""
            };

            var duplicateFilesInfos_03 = new List <FileWithDuplicates>()
            {
                text1Info_03,
                text2Info_03
            };

            ///

            var expectedResult = new List <ScanResult>()
            {
                new ScanResult()
                {
                    DuplicateText       = string.Join(envNewLine, duplicateText_01),
                    DuplicateFilesInfos = duplicateFilesInfos_01
                },
                new ScanResult()
                {
                    DuplicateText       = string.Join(envNewLine, duplicateText_02),
                    DuplicateFilesInfos = duplicateFilesInfos_02
                },
                new ScanResult()
                {
                    DuplicateText       = string.Join(envNewLine, duplicateText_03),
                    DuplicateFilesInfos = duplicateFilesInfos_03
                }
            };

            //Act
            var scanerObj  = new RowByRowScanner(sourceQueue);
            var resultReal = scanerObj.SearchDuplicates();

            string expJson  = JsonConvert.SerializeObject(expectedResult);
            string realJson = JsonConvert.SerializeObject(resultReal);

            //Assert
            Assert.Equal(expJson, realJson);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine("======================");


            string text1 =
                "Row1\r\n" +
                "Row2\r\n" +
                "\tRow3\r\n" +
                "Row1\r\n" +
                "Row2\r\n" +
                "Row2.1";

            string text2 =
                "row1.1\r\n" +
                "row1.2\r\n" +
                "row1.3\r\n" +

                "row2\r\n" +
                "row3\r\n" +
                "row4\r\n" +

                "row4.1\r\n" +

                "row1.1\r\n" +
                "row1.2\r\n" +
                "row1.3\r\n" +

                "row2\r\n" +
                "row3\r\n" +
                "row4\r\n" +

                "row1.1\r\n" +
                "row1.2\r\n" +
                "row1.3\r\n";


            string text3 =
                "Row1.1\r\n" +
                "Row1.2\r\n" +
                "Row1.3\r\n" +

                "row2\r\n" +
                "row3\r\n" +
                "row4\r\n" +

                "Row1\r\n" +
                "Row2\r\n" +
                "Row3\r\n";

            string realFilePath = @"/Users/macbookair/Desktop/test.php";
            var    realSource   = new ScanSource()
            {
                Name = Path.GetFileName(realFilePath),
                Path = realFilePath,
                Text = File.ReadAllText(realFilePath)
            };

            var sourceQueue = new Queue <ScanSource>();

            //sourceStack.Push(new ScanSource() { Name = "Text1", Text = text1 });
            //sourceStack.Push(new ScanSource() { Name = "Text2", Text = text2 });
            //sourceStack.Push(new ScanSource() { Name = "Text3", Text = text3 });
            sourceQueue.Enqueue(realSource);


            var stopWatch = System.Diagnostics.Stopwatch.StartNew();

            SearcherBase      scanerObj = new RowByRowScanner(sourceQueue);
            List <ScanResult> res       = scanerObj.SearchDuplicates();

            stopWatch.Stop();
            Console.WriteLine($"Calc time => {stopWatch.ElapsedMilliseconds} mlsec");
            //Console.WriteLine($"TotalIterationCount = {scanerObj.TotalIterationCount}");

            string resJson = JsonConvert.SerializeObject(res.OrderByDescending(r => r.TotalItems), Formatting.Indented);

            Console.WriteLine(resJson);

            Console.WriteLine("Done!");

            Console.ReadKey();
            Console.Clear();
        }