Exemplo n.º 1
0
        public void AddData(int count)
        {
            Console.WriteLine("Starting insertion");
            //var random = new Random();
            InsertedNumbers.Capacity = count;
            for (int i = 0; i < count; i++)
            {
                //var n = random.Next();
                var record = new TestRecord(i);
                if (TestRaf.Add(record, out var index))
                {
                    InsertedNumbers.Add(new RafTestBock(i, index));
                }
            }

            Console.WriteLine("Insertion test finished");
        }
Exemplo n.º 2
0
        public bool RandomRemoveInsertTest(int rounds)
        {
            Console.WriteLine("Starting random operations test");
            var current            = 0;
            var randSeed           = new Random();
            var randomCount        = new Random(randSeed.Next());
            var randomInsOrDel     = new Random(randSeed.Next());
            var randomInsertNumber = new Random(randSeed.Next());
            var randomDeleteNumber = new Random(randSeed.Next());

            InsertedNumbers.Clear();

            while (current < rounds)
            {
                var count    = randomCount.Next(50, 200);
                var insOrDel = randomInsOrDel.NextDouble();
                for (int i = 0; i < count; i++)
                {
                    if (InsertedNumbers.Count == 0)
                    {
                        insOrDel = 0.1;
                    }

                    if (insOrDel < 0.5)
                    {
                        var num    = randomInsertNumber.Next();
                        var record = new TestRecord(num);
                        if (TestRaf.Add(record, out var index))
                        {
                            InsertedNumbers.Add(new RafTestBock(num, index));
                        }
                    }
                    else
                    {
                        var index = randomDeleteNumber.Next(0, InsertedNumbers.Count - 1);
                        var value = InsertedNumbers[index];
                        InsertedNumbers.Remove(value);

                        if (!TestRaf.TryRemove(new TestRecord(value.TestRecordValue), value.IndexAddress, out var result))
                        {
                            Console.WriteLine("Did not remove value {0}", value.TestRecordValue);

                            if (TestRaf.TryFind(new TestRecord(value.TestRecordValue), value.IndexAddress, out var value2))
                            {
                                Console.WriteLine("Still contains value after deletion");
                                return(false);
                            }
                            else
                            {
                                Console.WriteLine("nie je tam ani");
                            }
                            return(false);
                        }
                    }
                }

                current++;
            }

            Console.WriteLine("Random operation test finished successfully");
            return(true);
        }