//TODO FIXME
        //[Theory]
        //[MemberData(nameof(KeysData))]
        public void Add(IEnumerable <int> keys)
        {
            Assert.True(keys.All(k => k < int.MaxValue));
            Assert.True(keys.Count() > 0);

            var target = new SoftHeap <int, int>(1 / 4.0, int.MaxValue);

            TestConsole.WriteLine("expected error rate: {0}", target.ErrorRate);
            foreach (var key in keys)
            {
                var count = target.Count;
                target.Add(key, key + 1);
                Assert.Equal(count + 1, target.Count);
            }

            int lastMin = int.MaxValue;
            int error   = 0;

            while (target.Count > 0)
            {
                var kv = target.DeleteMin();
                if (lastMin < kv.Key)
                {
                    error++;
                }
                lastMin = kv.Key;
                Assert.Equal(kv.Key + 1, kv.Value);
            }

            TestConsole.WriteLine("error rate: {0}", error / (double)keys.Count());
            Assert.True(error / (double)keys.Count() <= target.ErrorRate);
        }
Exemplo n.º 2
0
        public void Add([PexAssumeNotNull] int[] keys)
        {
            PexAssume.TrueForAll(keys, k => k < int.MaxValue);
            PexAssume.IsTrue(keys.Length > 0);

            var target = new SoftHeap <int, int>(1 / 4.0, int.MaxValue);

            Console.WriteLine("expected error rate: {0}", target.ErrorRate);
            foreach (var key in keys)
            {
                var count = target.Count;
                target.Add(key, key + 1);
                Assert.AreEqual(count + 1, target.Count);
            }

            int lastMin = int.MaxValue;
            int error   = 0;

            while (target.Count > 0)
            {
                var kv = target.DeleteMin();
                if (lastMin < kv.Key)
                {
                    error++;
                }
                lastMin = kv.Key;
                Assert.AreEqual(kv.Key + 1, kv.Value);
            }

            Console.WriteLine("error rate: {0}", error / (double)keys.Length);
            Assert.IsTrue(error / (double)keys.Length <= target.ErrorRate);
        }