public void ConvertAllTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.Equal(new[] { false, true, false, true, true }, ListUtils.ConvertAll(collection, item => item % 2 == 0)); Assert.Equal(new[] { false, true, false, true, true }, ReadOnlyListUtils.ConvertAll(collection, item => item % 2 == 0)); }
public void FindTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.Equal(8, ListUtils.Find(collection, item => item % 2 == 0)); Assert.Equal(8, ReadOnlyListUtils.Find(collection, item => item % 2 == 0)); Assert.Equal(default, ListUtils.Find(collection, item => item > 12));
public void ExistsTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.True(ListUtils.Exists(collection, item => item > 10)); Assert.True(ReadOnlyListUtils.Exists(collection, item => item > 10)); Assert.False(ListUtils.Exists(collection, item => item > 12)); Assert.False(ReadOnlyListUtils.Exists(collection, item => item > 12)); }
public void BinarySearchTest() { var collection = new IntCollection { 5, 8, 9, 10, 12 }; Assert.Equal(-1, ListUtils.BinarySearch(collection, 0)); Assert.Equal(-1, ReadOnlyListUtils.BinarySearch(collection, 0)); Assert.Equal(1, ListUtils.BinarySearch(collection, 8)); Assert.Equal(1, ReadOnlyListUtils.BinarySearch(collection, 8)); Assert.Equal(1, ListUtils.BinarySearch(collection, 8, s_intComparer)); Assert.Equal(1, ReadOnlyListUtils.BinarySearch(collection, 8, s_intComparer)); Assert.Equal(-2, ListUtils.BinarySearch(collection, 1, 2, 5)); Assert.Equal(-2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 5)); Assert.Equal(-4, ListUtils.BinarySearch(collection, 1, 2, 10)); Assert.Equal(-4, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 10)); Assert.Equal(2, ListUtils.BinarySearch(collection, 1, 2, 9)); Assert.Equal(2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 9)); Assert.Equal(2, ListUtils.BinarySearch(collection, 1, 2, 9, s_intComparer)); Assert.Equal(2, ReadOnlyListUtils.BinarySearch(collection, 1, 2, 9, s_intComparer)); Assert.Equal(-1, ListUtils.BinarySearch(collection, 0, 0, 5)); Assert.Equal(-1, ReadOnlyListUtils.BinarySearch(collection, 0, 0, 5)); Assert.Equal(~collection.Count, ListUtils.BinarySearch(collection, collection.Count, 0, 12)); Assert.Equal(~collection.Count, ReadOnlyListUtils.BinarySearch(collection, collection.Count, 0, 12)); Assert.Throws <ArgumentOutOfRangeException>(() => ListUtils.BinarySearch(collection, -1, 1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ReadOnlyListUtils.BinarySearch(collection, -1, 1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ListUtils.BinarySearch(collection, 0, -1, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => ReadOnlyListUtils.BinarySearch(collection, 0, -1, 0)); Assert.Throws <ArgumentException>(() => ListUtils.BinarySearch(collection, collection.Count, 1, 0)); Assert.Throws <ArgumentException>(() => ReadOnlyListUtils.BinarySearch(collection, collection.Count, 1, 0)); }