Exemple #1
0
    public void TestAddFirst() {
      Deque<int> intDeque = new Deque<int>(16);
      for(int item = 0; item < 48; ++item) {
        intDeque.AddFirst(item);
      }

      for(int item = 0; item < 48; ++item) {
        Assert.AreEqual(47 - item, intDeque[item]);
      }
    }
Exemple #2
0
    /// <summary>
    ///   Creates a deque whose first element does not coincide with a block boundary
    /// </summary>
    /// <param name="count">Number of items the deque will be filled with</param>
    /// <returns>The newly created deque</returns>
    private static Deque<int> createNonNormalizedDeque(int count) {
      Deque<int> intDeque = new Deque<int>(16);

      for(int item = 4; item < count; ++item) {
        intDeque.AddLast(item);
      }
      if(count > 3) { intDeque.AddFirst(3); }
      if(count > 2) { intDeque.AddFirst(2); }
      if(count > 1) { intDeque.AddFirst(1); }
      if(count > 0) { intDeque.AddFirst(0); }

      return intDeque;
    }
Exemple #3
0
    public void TestRemoveAtEmptiesLeftBlock() {
      Deque<int> intDeque = new Deque<int>(16);
      for(int item = 1; item <= 16; ++item) {
        intDeque.AddLast(item);
      }
      intDeque.AddFirst(0);
      intDeque.RemoveAt(3);

      Assert.AreEqual(16, intDeque.Count);

      for(int index = 0; index < 3; ++index) {
        Assert.AreEqual(index, intDeque[index]);
      }
      for(int index = 3; index < 16; ++index) {
        Assert.AreEqual(index + 1, intDeque[index]);
      }
    }
Exemple #4
0
    public void TestRemoveAtNonNormalized() {
      for(int testedIndex = 0; testedIndex < 96; ++testedIndex) {
        Deque<int> intDeque = new Deque<int>(16);
        for(int item = 4; item < 96; ++item) {
          intDeque.AddLast(item);
        }
        intDeque.AddFirst(3);
        intDeque.AddFirst(2);
        intDeque.AddFirst(1);
        intDeque.AddFirst(0);

        intDeque.RemoveAt(testedIndex);

        Assert.AreEqual(95, intDeque.Count);

        for(int index = 0; index < testedIndex; ++index) {
          Assert.AreEqual(index, intDeque[index]);
        }
        for(int index = testedIndex; index < 95; ++index) {
          Assert.AreEqual(index + 1, intDeque[index]);
        }
      }
    }