コード例 #1
0
        public void RandomTest()
        {
            var charset = Resources.TestCharSet;
            var test    = new StringBuilder(512);
            var random  = new Random();

            ForegroundColor = ConsoleColor.Green;
            Write("    Running Test:   0 %");

            for (int cycle = 0; cycle < 10; cycle++)
            {
                for (int i = 0; i < 1000; i++)
                {
                    test.Clear();
                    var length = random.Next(512);

                    while (length-- > 0)
                    {
                        test.Append(charset, random.Next(charset.Length), 1);
                    }

                    var compressed   = Smaz.Compress(test.ToString());
                    var decompressed = Smaz.Decompress(compressed);

                    Assert.AreEqual(test.ToString(), decompressed, "Random failed for: '{0}'", test);
                }
                SetCursorPosition(19, CursorTop);
                Write($"{(cycle + 1) * 10:###} %");
            }
            SetCursorPosition(0, CursorTop);
        }
コード例 #2
0
        /// <summary>
        /// Test SmazSharp Decompression Performance, assume compliance (via other tests)
        /// </summary>
        public void DecompressPerfTest(int Cycles, int Iterations)
        {
            ForegroundColor = ConsoleColor.Yellow;
            WriteLine("------");
            WriteLine("Testing Decompression Performance");
            ForegroundColor = ConsoleColor.Gray;
            WriteLine($"       Cycles: {Cycles:N0}");
            WriteLine($"   Iterations: {Iterations:N0}");

#if DEBUG
            Assert.Inconclusive("Cannot run performance tests in Debug");
#endif
            Assert.IsTrue(Cycles > 0, "The number of Cycles must be greater than 0");
            Assert.IsTrue(Iterations > 0, "The number of Iterations must be greater than 0");

            ForegroundColor = ConsoleColor.Green;
            Write("  Running Tests: 0 %");

            var    testBytes = Resources.TestStringsCompressed;
            long[] results   = new long[Cycles];
            string result;

            // Warm Up
            for (int i = 0; i < testBytes.Length; i++)
            {
                result = Smaz.Decompress(testBytes[i]);
            }

            // Run Cycles
            for (int cycle = 0; cycle < Cycles; cycle++)
            {
                // Run Iterations
                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (int iteration = 0; iteration < Iterations; iteration++)
                {
                    Smaz.Decompress(testBytes[iteration % testBytes.Length]);
                }
                sw.Stop();
                results[cycle] = sw.ElapsedTicks;
                SetCursorPosition(17, CursorTop);
                Write($"{(100 / (double)Cycles) * (cycle + 1):N0} %");
            }

            SetCursorPosition(0, CursorTop);
            WriteLine("  Tests Complete       ");
            WriteLine($"    Cycles (ms): {string.Join(", ", results.Select(r => (r / TimeSpan.TicksPerMillisecond).ToString("N1")))}");
            WriteLine($"  Cycle Average: {results.Average() / TimeSpan.TicksPerMillisecond:N2} milliseconds");
            WriteLine($"        Average: {results.Average() / Iterations:N5} ticks/operation");
            ForegroundColor = ConsoleColor.Yellow;
            WriteLine("Decompression Performance Testing Complete");
            WriteLine("------");
            ForegroundColor = ConsoleColor.Gray;
            WriteLine();
        }
コード例 #3
0
        public void DecompressTest()
        {
            for (int i = 0; i < Resources.TestStringsCompressed.Length; i++)
            {
                var test             = Resources.TestStringsCompressed[i];
                var decompressedOk   = Resources.TestStrings[i];
                var decompressedTest = Smaz.Decompress(test);

                Assert.AreEqual(decompressedOk, decompressedTest, "Decompression failed for: '{0}'", decompressedOk);
            }
        }
コード例 #4
0
        public void CompressTest()
        {
            for (int i = 0; i < Resources.TestStrings.Length; i++)
            {
                var test           = Resources.TestStrings[i];
                var compressedOk   = Resources.TestStringsCompressed[i];
                var compressedTest = Smaz.Compress(test);

                // Compare Length
                if (compressedOk.Length != compressedTest.Length)
                {
                    Assert.Fail("Compression failed for: '{0}'", test);
                }

                // Compare Data
                for (int c = 0; c < compressedOk.Length; c++)
                {
                    if (compressedOk[c] != compressedTest[c])
                    {
                        Assert.Fail("Compression failed for: '{0}'", test);
                    }
                }
            }
        }