public void DistinctItems() { Bag <string> bag1 = new Bag <string>( new string[] { "foo", null, "Foo", "Eric", "FOO", "eric", "bar" }, StringComparer.InvariantCultureIgnoreCase); InterfaceTests.TestEnumerableElementsAnyOrder(bag1.DistinctItems(), new string[] { null, "bar", "Eric", "foo" }); // Make sure enumeration stops on change. int count = 0; try { foreach (string s in bag1.DistinctItems()) { if (count == 2) { bag1.Add("zippy"); } ++count; } Assert.Fail("should throw"); } catch (Exception e) { Assert.IsTrue(e is InvalidOperationException); Assert.AreEqual(3, count); } }
public void FindAll() { Bag <double> bag1 = new Bag <double>(new double[] { 4.5, 187.4, 1.2, 7.6, -7.6, -0.04, 1.2, 1.78, 10.11, 187.4 }); double[] expected = { -7.6, 7.6, 10.11, 187.4, 187.4 }; InterfaceTests.TestEnumerableElementsAnyOrder(bag1.FindAll(delegate(double d) { return(Math.Abs(d) > 5); }), expected); }
public void FindAll() { var bag1 = new Bag <double>(new[] { 4.5, 187.4, 1.2, 7.6, -7.6, -0.04, 1.2, 1.78, 10.11, 187.4 }); double[] expected = { -7.6, 7.6, 10.11, 187.4, 187.4 }; InterfaceTests.TestEnumerableElementsAnyOrder(bag1.FindAll(d => Math.Abs(d) > 5), expected); }