public void PostElementThenTestForElement() { int tmp; var p = new Port<int> (); ; var elem = new PortElement<int> (99); p.PostElement (elem); Assert.AreEqual (1, p.ItemCount, "#1"); var res = p.TestForElement (); Assert.AreEqual (elem, res, "#2"); Assert.AreEqual (0, p.ItemCount, "#3"); Assert.AreEqual (null, res.Owner, "#4"); }
public void PostElementPrependOnTheQueue() { Port<int> p = new Port<int> (); p.Post (10); p.Post (20); p.PostElement (new PortElement<int> (30)); Assert.AreEqual (30, (int)p, "#1"); Assert.AreEqual (10, (int)p, "#2"); Assert.AreEqual (20, (int)p, "#3"); }
public void PostElementBad() { var p = new Port<int> (); ; var elem = new PortElement<double> (99); try { p.PostElement (elem); Assert.Fail ("#1"); } catch (InvalidCastException) {} /*LAMEIMPL, stupid exception to throw*/ try { p.PostElement (null); Assert.Fail ("#2"); } catch (NullReferenceException) {} /*LAMEIMPL, stupid exception to throw*/ }
public void PostElementCausesLinking() { var p = new Port<int> (); p.Post (10); p.PostElement (new PortElement<int> (20)); p.Post (30); var r0 = p.TestForElement (); var r1 = r0.Next; Assert.IsNotNull (r1, "#1"); var r2 = r1.Next; Assert.IsNotNull (r2, "#1"); Assert.AreEqual (r1, r2.Previous, "#2"); Assert.AreEqual (r2, r1.Previous, "#3"); }
public void LinkStateAfterPostElement() { Port<int> p = new Port<int> (); p.Post (10); p.Post (20); p.PostElement (new PortElement<int> (30)); p.PostElement (new PortElement<int> (40)); IPortReceive rec = p; IPortElement a = (IPortElement)rec.GetItems () [0]; IPortElement b = (IPortElement)rec.GetItems () [1]; IPortElement c = (IPortElement)rec.GetItems () [2]; IPortElement d = (IPortElement)rec.GetItems () [3]; Assert.AreEqual (b, a.Next, "#1"); Assert.AreEqual (c, b.Next, "#2"); Assert.AreEqual (d, c.Next, "#3"); Assert.AreEqual (a, d.Next, "#4"); Assert.AreEqual (d, a.Previous, "#5"); Assert.AreEqual (a, b.Previous, "#6"); Assert.AreEqual (b, c.Previous, "#7"); Assert.AreEqual (c, d.Previous, "#8"); Assert.AreEqual (40, a.Item, "#9"); Assert.AreEqual (30, b.Item, "#10"); Assert.AreEqual (10, c.Item, "#11"); Assert.AreEqual (20, d.Item, "#12"); }