示例#1
0
        public void TestEditingStackOperations()
        {
            var commands = new XTMFCommand[20];

            for (int i = 0; i < commands.Length; i++)
            {
                commands[i] = new TestCommand();
            }
            EditingStack stack = new EditingStack(10);

            Assert.AreEqual(0, stack.Count, "The stack's count is incorrect!");
            // fill the stack
            for (int i = 0; i < 10; i++)
            {
                stack.Add(commands[i]);
                Assert.AreEqual(i + 1, stack.Count, "The stack's count is incorrect!");
            }
            // over fill the stack
            for (int i = 10; i < 20; i++)
            {
                stack.Add(commands[i]);
                Assert.AreEqual(10, stack.Count, "The stack's count is incorrect!");
            }
            // Make sure the first don't exist anymore
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(false, stack.Contains(commands[i]), "The stack retained a command it should have lost!");
            }
            // Make sure the newer ones still exist
            for (int i = 10; i < 20; i++)
            {
                Assert.AreEqual(true, stack.Contains(commands[i]), "The stack lost a command it should have retained!");
            }
            XTMFCommand command;

            for (int i = 19; i >= 10; i--)
            {
                if (stack.TryPop(out command))
                {
                    Assert.AreEqual(commands[i], command, "While popping we popped an unexpected command!");
                }
                else
                {
                    Assert.Fail("A pop failed that should have succeeded!");
                }
            }
        }
示例#2
0
 public void TestEditingStackOperations()
 {
     var commands = new XTMFCommand[20];
     for ( int i = 0; i < commands.Length; i++ )
     {
         commands[i] = new TestCommand();
     }
     EditingStack stack = new EditingStack( 10 );
     Assert.AreEqual( 0, stack.Count, "The stack's count is incorrect!" );
     // fill the stack
     for ( int i = 0; i < 10; i++ )
     {
         stack.Add( commands[i] );
         Assert.AreEqual( i + 1, stack.Count, "The stack's count is incorrect!" );
     }
     // over fill the stack
     for ( int i = 10; i < 20; i++ )
     {
         stack.Add( commands[i] );
         Assert.AreEqual( 10, stack.Count, "The stack's count is incorrect!" );
     }
     // Make sure the first don't exist anymore
     for ( int i = 0; i < 10; i++ )
     {
         Assert.AreEqual( false, stack.Contains( commands[i] ), "The stack retained a command it should have lost!" );
     }
     // Make sure the newer ones still exist
     for ( int i = 10; i < 20; i++ )
     {
         Assert.AreEqual( true, stack.Contains( commands[i] ), "The stack lost a command it should have retained!" );
     }
     XTMFCommand command;
     for ( int i = 19; i >= 10; i-- )
     {
         if ( stack.TryPop( out command ) )
         {
             Assert.AreEqual( commands[i], command, "While popping we popped an unexpected command!" );
         }
         else
         {
             Assert.Fail( "A pop failed that should have succeeded!" );
         }
     }
 }