Exemple #1
0
        public void CalcChunksByLength_randomGen_tests()
        {
            StringBuilder sb    = new StringBuilder();
            int           i     = 0;
            int           skips = 0;

            for (; i < RANDOM_TEST_LOOPS; i++)
            {
                int[] randPair = RandomParams.GetNumberPair(1, MAX_FRAME);

                int start    = randPair[0];
                int end      = randPair[1];
                int totalLen = end - start + 1;

                // ignore small spans
                if (totalLen < MIN_CHUNK_LEN)
                {
                    skips++;
                    continue;
                }

                // range of random lengths:
                var minLen = totalLen * 0.05;
                var maxLen = totalLen * 0.5;

                int len = RandomParams.GetNumber((int)minLen, (int)maxLen);

                // ignore small spans
                if (len < MIN_CHUNK_LEN)
                {
                    skips++;
                    continue;
                }

                var calcResult = new List <Chunk>(Chunk.CalcChunksByLength(start, end, len));

                sb.AppendFormat("\n{0}: Number of chunks: {1}, Chunk lenght: {2}\n", i, calcResult.Count, len);
                sb.AppendFormat("Start frame: {0}, End frame: {1}, Total lenght: {2}\n", start, end, totalLen);
                foreach (var res in calcResult)
                {
                    sb.AppendLine(res + "\tLenght: " + res.Length);
                }

                var actualLen = calcResult.First().Length;
                Assert.AreEqual(len, actualLen, "Lenght and generated chunk's lenght don't match");

                Assert.AreEqual(start, calcResult.First().Start, "First calcResult.Start was diferent then param start");
                Assert.AreEqual(end, calcResult.Last().End, "Last calcResult.End was diferent then param end");
                Assert.IsTrue(CheckStartAndEnd(calcResult), "There are unexpected gaps between Chunks");
                Assert.AreEqual(totalLen, calcResult.TotalLength(), "Total Lenghts don't match");
            }

            Console.WriteLine("CalcChunksByLength Random test. {0} runs", i - skips);
            Console.Write(sb.ToString());
        }
Exemple #2
0
        public void CalcChunks_TotalLenght_is_accurate()
        {
            int[] randPair = RandomParams.GetNumberPair(1, MAX_FRAME);

            var start    = randPair[0];
            var end      = randPair[1];
            int totalLen = end - start + 1;
            int cores    = RandomParams.GetNumber(1, MAX_CORES);

            var chunks = Chunk.CalcChunks(start, end, cores);

            Console.WriteLine("Total lenght = " + totalLen);
            Console.WriteLine("Chunks total length = " + chunks.TotalLength());

            Assert.AreEqual(totalLen, chunks.TotalLength(), "Lenghts are not equal");
        }
Exemple #3
0
        public void CalcChunks_randomGen_tests()
        {
            StringBuilder sb    = new StringBuilder();
            int           skips = 0;
            int           i     = 0;

            for (; i < RANDOM_TEST_LOOPS; i++)
            {
                int[] randPair = RandomParams.GetNumberPair(1, MAX_FRAME);

                var cores = RandomParams.GetNumber(1, MAX_CORES);
                var start = randPair[0];
                var end   = randPair[1];

                var totalLen = end - start + 1;

                if (totalLen < MIN_CHUNK_LEN)
                {
                    skips++;
                    continue;
                }

                var calcResult = new List <Chunk>(Chunk.CalcChunks(start, end, cores));

                sb.AppendFormat("\n{0}: Number of chunks: {1}\n", i, calcResult.Count);
                sb.AppendFormat("Start: {0}, End: {1}, Total lenght: {2}, CoreCount: {3}\n", start, end, totalLen, cores);
                foreach (var res in calcResult)
                {
                    sb.AppendLine(res + "\tLenght: " + res.Length);
                }

                Assert.AreEqual(start, calcResult.First().Start, "First calcResult.Start was diferent then param start");
                Assert.AreEqual(end, calcResult.Last().End, "Last calcResult.End was diferent then param end");
                Assert.IsTrue(CheckStartAndEnd(calcResult), "There are unexpected gaps between Chunks");
                Assert.AreEqual(totalLen, calcResult.TotalLength(), "Lenghts don't match");
            }

            Console.WriteLine("CalcChunks Random test. {0} runs", i - skips);
            Console.Write(sb.ToString());
        }