Ejemplo n.º 1
0
        public void Pop_on_empty_Stack_throws_Exception()
        {
            var s = new CountableStack <string>(2);

            s.Put("s1");
            s.Put("s2");
            s.Pop();
            s.Pop();

            try
            {
                s.Pop();
                // se non lancia eccezione,
                // il test deve fallire!
                Assert.Fail("Did not throw Exception");
            }
            catch (InvalidOperationException ex)
            {
                // se viene catturata una InvalidOperationException
                // è tutto a posto
            }
            catch (Exception)
            {
                // se viene lanciata qualche altra eccezione
                // il test deve fallire!
                Assert.Fail("Threw wrong Exception");
            }
        }
Ejemplo n.º 2
0
        public void Pop_returns_the_elements_in_reverse_order()
        {
            var s = new CountableStack <string>(2);

            s.Put("s1");
            s.Put("s2");

            Assert.AreEqual("s2", s.Pop());
            Assert.AreEqual("s1", s.Pop());
        }
Ejemplo n.º 3
0
        public void An_unsubscribed_does_not_receive_the_Pop_element()
        {
            var s    = new CountableStack <int>(3);
            var sub1 = new StackSubscriber <int>();
            var sub2 = new StackSubscriber <int>();

            s.Subscribe(sub1);
            s.Subscribe(sub2);
            s.Put(40);
            s.Put(41);
            s.Pop();
            s.Unsubscribe(sub1);
            s.Pop();
            Assert.AreEqual(41, sub1.LastPop);
            Assert.AreEqual(40, sub2.LastPop);
        }
Ejemplo n.º 4
0
        public void Stack_emptied_cannot_Pop()
        {
            var s = new CountableStack <int>(2);

            s.Put(5);
            s.Pop();
            Assert.IsFalse(s.CanPop());
        }
Ejemplo n.º 5
0
        public void new_Stack_can_Pop_down_to_empty()
        {
            var s = new CountableStack <int>(3);

            s.Put(100);
            s.Put(150);
            s.Put(200);
            Assert.IsTrue(s.CanPop());

            s.Pop();
            Assert.IsTrue(s.CanPop());

            s.Pop();
            Assert.IsTrue(s.CanPop());

            s.Pop();
            Assert.IsFalse(s.CanPop());
        }
Ejemplo n.º 6
0
        public void Empty_Stack_returns_0()
        {
            var s = new CountableStack <string>(0);

            Assert.AreEqual(0, s.Count(x => x == null));
            Assert.AreEqual(0, s.Count(x => x.StartsWith("c")));
            Assert.AreEqual(0, s.Count(x => x.Length > 3));

            s = new CountableStack <string>(10);

            Assert.AreEqual(0, s.Count(x => x == null));
            Assert.AreEqual(0, s.Count(x => x.StartsWith("c")));
            Assert.AreEqual(0, s.Count(x => x.Length > 3));

            s = new CountableStack <string>(20);
            s.Put("cc");
            s.Put("heeeeey");
            s.Pop();
            s.Pop();

            Assert.AreEqual(0, s.Count(x => x == null));
            Assert.AreEqual(0, s.Count(x => x.StartsWith("c")));
            Assert.AreEqual(0, s.Count(x => x.Length > 3));
        }