Example #1
0
        public void MultipleCreateAndDeleteTest()
        {
            //const int N = 21;

            using (var scope = new TempLinksTestScope())
            {
                var links = scope.Links;

                for (var N = 0; N < 100; N++)
                {
                    var random = new Random(N);

                    var created = 0;
                    var deleted = 0;

                    for (var i = 0; i < N; i++)
                    {
                        var linksCount = links.Count();

                        var createPoint = random.NextBoolean();

                        if (linksCount > 2 && createPoint)
                        {
                            var source = random.NextUInt64(1, linksCount);
                            var target = random.NextUInt64(1, linksCount);

                            var resultLink = links.CreateAndUpdate(source, target);
                            if (resultLink > linksCount)
                                created++;
                        }
                        else
                        {
                            links.Create();
                            created++;
                        }
                    }

                    Assert.True(created == (int)links.Count());

                    for (var i = 0; i < N; i++)
                    {
                        var link = (ulong)i + 1;
                        if (links.Exists(link))
                        {
                            links.Delete(link);
                            deleted++;
                        }
                    }

                    Assert.True(links.Count() == 0);
                }
            }
        }
Example #2
0
        public void TestRandomSearchAll()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong counter = 0;

                ulong minLink = 1UL;
                ulong maxLink = links.Total;

                ulong iterations = links.Total;
                var rnd = new Random((int)DateTime.UtcNow.Ticks);

                Console.WriteLine("Testing Random Search with {0} Iterations.", links.Total);

                Stopwatch sw = Stopwatch.StartNew();

                for (ulong i = iterations; i > 0; i--)
                {
                    ulong source = rnd.NextUInt64(minLink, maxLink);
                    ulong target = rnd.NextUInt64(minLink, maxLink);

                    counter += links.Search(source, target);
                }

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = iterations / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} Iterations of Random Search done in {1} ({2} Iterations per second), c: {3}",
                    iterations, elapsedTime, (long)iterationsPerSecond, counter);
            }

            File.Delete(tempFilename);
        }