コード例 #1
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());

            InsertedRecords.Clear();

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

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

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

                            if (TestDynHash.TryFind(new TestRecord(value.Number), 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);
        }
コード例 #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());
            var randomStringLength = new Random(randSeed.Next());

            InsertedRecords.Clear();

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

                    if (insOrDel < 0.5)
                    {
                        var length = randomStringLength.Next(0, 15);
                        var guid   = Guid.NewGuid().ToString().Substring(0, length);
                        var num    = randomInsertNumber.Next();
                        var record = new RealtyByCadAndRegNumber
                        {
                            AddressIndex   = 0,
                            UniqueName     = guid,
                            RegisterNumber = num
                        };
                        if (TestDynHash.Add(record))
                        {
                            var iRecord = new RealtyByCadAndRegNumber
                            {
                                AddressIndex   = 0,
                                UniqueName     = guid,
                                RegisterNumber = num
                            };
                            InsertedRecords.Add(iRecord);
                        }
                    }
                    else
                    {
                        var index = randomDeleteNumber.Next(0, InsertedRecords.Count - 1);
                        var value = InsertedRecords[index];
                        InsertedRecords.Remove(value);
                        var record = new RealtyByCadAndRegNumber
                        {
                            AddressIndex   = value.AddressIndex,
                            UniqueName     = value.UniqueName,
                            RegisterNumber = value.RegisterNumber
                        };

                        if (!TestDynHash.TryRemove(record, out var result))
                        {
                            Console.WriteLine("Did not remove value {0}", record.RegisterNumber);

                            if (TestDynHash.TryFind(record, out var value2))
                            {
                                Console.WriteLine("Still contains value after deletion");
                                return(false);
                            }
                            else
                            {
                                Console.WriteLine("nie je tam ani");
                            }
                            return(false);
                        }
                        if (TestDynHash.TryFind(value, out var value3))
                        {
                            Console.WriteLine("Still contains value after deletion");
                            return(false);
                        }
                    }
                }

                current++;
            }

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