Ejemplo n.º 1
0
 public void InsertAndCurrentAndModify <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue> kv)
 {
     target.Add(kv.Key, kv.Value);
     PexAssert.Throws <InvalidOperationException>(delegate
     {
         var enumerator = target.GetEnumerator();
         target.Add(kv.Key, kv.Value);
         var current = enumerator.Current;
     });
 }
 private void InsertAndResetAndModify <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue> kv)
 {
     target.Add(kv.Key, kv.Value);
     Assert.Throws <InvalidOperationException>(delegate
     {
         var enumerator = target.GetEnumerator();
         target.Add(kv.Key, kv.Value);
         enumerator.Reset();
     });
 }
Ejemplo n.º 3
0
        public void InsertAndRemoveMinimum <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            var count = target.Count;

            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
            }

            TPriority minimum = default(TPriority);

            for (int i = 0; i < kvs.Length; ++i)
            {
                if (i == 0)
                {
                    minimum = target.RemoveMinimum().Key;
                }
                else
                {
                    var m = target.RemoveMinimum().Key;
                    Assert.IsTrue(target.PriorityComparison(minimum, m) <= 0);
                    minimum = m;
                }
                AssertInvariant(target);
            }

            Assert.AreEqual(0, target.Count);
        }
Ejemplo n.º 4
0
        public void InsertAndMinimum <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            PexAssume.IsTrue(kvs.Length > 0);

            var       count   = target.Count;
            TPriority minimum = default(TPriority);

            for (int i = 0; i < kvs.Length; ++i)
            {
                var kv = kvs[i];
                if (i == 0)
                {
                    minimum = kv.Key;
                }
                else
                {
                    minimum = target.PriorityComparison(kv.Key, minimum) < 0 ? kv.Key : minimum;
                }
                target.Add(kv.Key, kv.Value);
                // check minimum
                var kvMin = target.Minimum();
                Assert.AreEqual(minimum, kvMin.Key);
            }
            AssertInvariant <TPriority, TValue>(target);
        }
Ejemplo n.º 5
0
 public void InsertManyAndMoveNextAndReset <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     PexEnumerablePatterns.MoveNextAndReset(target);
 }
 private void InsertManyAndMoveNextAndReset <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     //TODO FIXME PexEnumerablePatterns.MoveNextAndReset(target);
 }
 private void CurrentBeforeMoveNext <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue> kv)
 {
     target.Add(kv.Key, kv.Value);
     Assert.Throws <InvalidOperationException>(delegate
     {
         var enumerator = target.GetEnumerator();
         var current    = enumerator.Current;
     });
 }
 private void InsertManyAndEnumerateUntyped <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     foreach (KeyValuePair <TPriority, TValue> kv in (IEnumerable)target)
     {
         ;
     }
 }
 private void InsertAndIndexOf <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     foreach (var kv in kvs)
     {
         Assert.True(target.IndexOf(kv.Value) > -1);
     }
 }
        private void Insert <TPriority, TValue>(
            BinaryHeap <TPriority, TValue> target,
            KeyValuePair <TPriority, TValue>[] kvs)
        {
            var count = target.Count;

            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
                AssertInvariant <TPriority, TValue>(target);
            }
            Assert.True(count + kvs.Length == target.Count);
        }
Ejemplo n.º 11
0
        public void InsertAndEnumerate <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            var dic = new Dictionary <TPriority, TValue>();

            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
                dic[kv.Key] = kv.Value;
            }
            PexAssert.TrueForAll(target, kv => dic.ContainsKey(kv.Key));
        }
Ejemplo n.º 12
0
 public void InsertAndIndexOf <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     foreach (var kv in kvs)
     {
         Assert.IsTrue(target.IndexOf(kv.Value) > -1, "target.IndexOf(kv.Value) > -1");
     }
 }
        private void InsertAndEnumerate <TPriority, TValue>(
            BinaryHeap <TPriority, TValue> target,
            KeyValuePair <TPriority, TValue>[] kvs)
        {
            var dic = new Dictionary <TPriority, TValue>();

            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
                dic[kv.Key] = kv.Value;
            }
            Assert.All(target, kv => dic.ContainsKey(kv.Key));
        }
Ejemplo n.º 14
0
 public void InsertManyAndEnumerateUntyped <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
 {
     foreach (var kv in kvs)
     {
         target.Add(kv.Key, kv.Value);
     }
     foreach (KeyValuePair <TPriority, TValue> kv in (IEnumerable)target)
     {
         ;
     }
 }
Ejemplo n.º 15
0
        public void Insert <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            var count = target.Count;

            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
                AssertInvariant <TPriority, TValue>(target);
            }
            Assert.IsTrue(count + kvs.Length == target.Count);
        }
Ejemplo n.º 16
0
        public void InsertAndRemoveAt <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs,
            int removeAtIndex)
        {
            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
            }
            var count   = target.Count;
            var removed = target.RemoveAt(removeAtIndex);

            Assert.AreEqual(count - 1, target.Count);
            AssertInvariant <TPriority, TValue>(target);
        }
Ejemplo n.º 17
0
 public void CurrentAfterMoveNextFinished <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     KeyValuePair <TPriority, TValue> kv)
 {
     target.Add(kv.Key, kv.Value);
     PexAssert.Throws <InvalidOperationException>(delegate
     {
         var enumerator = target.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ;
         }
         var current = enumerator.Current;
     });
 }
        private void InsertAndRemoveAt <TPriority, TValue>(
            BinaryHeap <TPriority, TValue> target,
            KeyValuePair <TPriority, TValue>[] kvs,
            int removeAtIndex)
        {
            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
            }
            var count   = target.Count;
            var removed = target.RemoveAt(removeAtIndex);

            Assert.Equal(count - 1, target.Count);
            AssertInvariant <TPriority, TValue>(target);
        }
Ejemplo n.º 19
0
        public void InsertAndRemoveAtAll <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
            }
            var call = PexChoose.FromCall(this);

            for (int i = target.Count - 1; i > -1; ++i)
            {
                target.RemoveAt(call.ValueFromRange(i.ToString(), 0, target.Count - 1));
                AssertInvariant <TPriority, TValue>(target);
            }
        }
 private void Operations <TPriority, TValue>(
     BinaryHeap <TPriority, TValue> target,
     KeyValuePair <bool, TPriority>[] values)
 {
     foreach (var value in values)
     {
         if (value.Key)
         {
             target.Add(value.Value, default(TValue));
         }
         else
         {
             var min = target.RemoveMinimum();
         }
         AssertInvariant <TPriority, TValue>(target);
     }
 }
Ejemplo n.º 21
0
 public void Operations <TPriority, TValue>(
     [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
     [PexAssumeNotNull] KeyValuePair <bool, TPriority>[] values)
 {
     foreach (var value in values)
     {
         if (value.Key)
         {
             target.Add(value.Value, default(TValue));
         }
         else
         {
             var min = target.RemoveMinimum();
         }
         AssertInvariant <TPriority, TValue>(target);
     }
 }