public void TestSort() { var compareFuncWasCalled = false; Comparison <OpaqueInt> compareFunc = (a, b) => { compareFuncWasCalled = true; return(a.Handle.ToInt32().CompareTo(b.Handle.ToInt32())); }; using (var list = new SList <OpaqueInt> ()) { list.Prepend(new OpaqueInt(1)); list.Prepend(new OpaqueInt(2)); Assume.That(list.Length, Is.EqualTo(2)); Assume.That(list[0].Handle, Is.EqualTo((IntPtr)2)); Assume.That(list[1].Handle, Is.EqualTo((IntPtr)1)); list.Sort(compareFunc); Assert.That(compareFuncWasCalled); Assert.That(list.Length, Is.EqualTo(2)); Assume.That(list[0].Handle, Is.EqualTo((IntPtr)1)); Assume.That(list[1].Handle, Is.EqualTo((IntPtr)2)); // calling without a compare function is not allowed Assert.That(() => list.Sort(null), Throws.InstanceOf <ArgumentNullException> ()); } Utility.AssertNoGLibLog(); }
public void TestReverse() { using (var list = new SList <OpaqueInt> ()) { list.Prepend(new OpaqueInt(1)); list.Prepend(new OpaqueInt(2)); Assume.That(list.Length, Is.EqualTo(2)); Assume.That(list[0].Handle, Is.EqualTo((IntPtr)2)); Assume.That(list[1].Handle, Is.EqualTo((IntPtr)1)); list.Reverse(); Assert.That(list.Length, Is.EqualTo(2)); Assume.That(list[0].Handle, Is.EqualTo((IntPtr)1)); Assume.That(list[1].Handle, Is.EqualTo((IntPtr)2)); } Utility.AssertNoGLibLog(); }
public void TestPrepend() { using (var list = new SList <OpaqueInt> ()) { Assume.That(list.Length, Is.EqualTo(0)); list.Prepend(null); Assert.That(list.Length, Is.EqualTo(1)); } Utility.AssertNoGLibLog(); }