Пример #1
0
 /// <summary>
 /// Decrements the pointer, i.e. sets the previous node as the current.
 /// </summary>
 public void DecrementPointer()
 {
     if (this.current.HasPrevious)
     {
         this.current = this.current.Previous;
     }
     else
     {
         throw new InvalidOperationException(
             "The pointer can not be decremented below 0.");
     }
 }
Пример #2
0
        public void LinkTest()
        {
            ByteNode bn = new ByteNode();

            Assert.IsFalse(bn.HasNext);
            Assert.IsNull(bn.Next);
            Assert.IsFalse(bn.HasPrevious);
            Assert.IsNull(bn.Previous);

            bn.Next = new ByteNode();
            Assert.IsTrue(bn.HasNext);
            Assert.IsNotNull(bn.Next);

            bn.Next.Previous = bn;
            bn = bn.Next;
            Assert.IsFalse(bn.HasNext);
            Assert.IsNull(bn.Next);
            Assert.IsTrue(bn.HasPrevious);
            Assert.IsNotNull(bn.Previous);
        }
Пример #3
0
        public void SmokeTest()
        {
            ByteNode bn = new ByteNode();

            Assert.AreEqual(0, bn.Value);

            bn.IncrementValue();

            Assert.AreEqual(1, bn.Value);

            Assert.IsFalse(bn.HasNext);

            bn.Next = new ByteNode();

            Assert.IsTrue(bn.HasNext);

            Assert.AreEqual(0, bn.Next.Value);

            bn.Next.IncrementValue();

            Assert.AreEqual(1, bn.Next.Value);
        }
Пример #4
0
        public void ValueTest()
        {
            ByteNode bn = new ByteNode();

            Assert.AreEqual(0, bn.Value);

            bn.IncrementValue();
            Assert.AreEqual(1, bn.Value);

            for (int i = 0; i < 20; i++)
            {
                bn.IncrementValue();
            }

            Assert.AreEqual(21, bn.Value);

            bn.DecrementValue();
            Assert.AreEqual(20, bn.Value);

            for (int i = 0; i < 20; i++)
            {
                bn.DecrementValue();
            }

            Assert.AreEqual(0, bn.Value);

            for (int i = 0; i < byte.MaxValue + 1; i++)
            {
                bn.IncrementValue();
            }

            Assert.AreEqual(0, bn.Value);

            bn.DecrementValue();
            Assert.AreEqual(byte.MaxValue, bn.Value);
        }
Пример #5
0
 public ByteNode()
 {
     this.value = 0;
     this.previous = null;
     this.next = null;
 }
Пример #6
0
 /// <summary>
 /// Increments the pointer, i.e. sets the next node as the current.
 /// </summary>
 public void IncrementPointer()
 {
     if (this.current.HasNext)
     {
         this.current = this.current.Next;
     }
     else
     {
         try
         {
             this.AddNode();
             this.IncrementPointer();
         }
         catch (InvalidOperationException ex)
         {
             throw new OutOfMemoryException(
                 "Not allowed to allocate more memory!", ex);
         }
     }
 }
Пример #7
0
 public ByteList()
 {
     this.current = new ByteNode();
     this.nodeCounter = 1;
 }