public void TestLinkedHashedMapDictionaryOperations() { var map = new LinkedHashedMap <Order, Bill>(new OrderEqualityComparer()); map.DictionaryOperations(x => new Order { Id = x }, y => new Bill { Id = y }, new BillEqualityComparer().Equals); }
public void TestOneItemLinkedHashMap() { var orders = new LinkedHashedMap <int, string>(); orders.Add(1, "1"); Assert.Equal(1, orders.First.Key); Assert.Equal(1, orders.Last.Key); Assert.Throws(typeof(ArgumentException), () => orders.Before(1)); Assert.Throws(typeof(ArgumentException), () => orders.After(1)); }
public void TestEmptyLinkedHashMap() { var orders = new LinkedHashedMap <string, Order>(); Assert.Throws(typeof(InvalidOperationException), () => orders.First); Assert.Throws(typeof(InvalidOperationException), () => orders.Last); Assert.Throws(typeof(InvalidOperationException), () => orders.After("1")); Assert.Throws(typeof(InvalidOperationException), () => orders.Before("2")); Assert.Throws(typeof(ArgumentException), () => orders.GetIndex(0)); Assert.Throws(typeof(ArgumentException), () => orders.GetIndex(1)); }
public void TestLinkedHashMapConstructors() { var orders = new LinkedHashedMap <string, Order>(); orders.HashAbility(); var orders2 = new LinkedHashedMap <string, Order>(10000); orders2.HashAbility(); var orders3 = new LinkedHashedMap <string, Order>(EqualityComparer <string> .Default); orders3.HashAbility(); var orders6 = new LinkedHashedMap <string, Order>((x1, x2) => x1 == x2); orders6.HashAbility(); var orders7 = new LinkedHashedMap <string, Order>(100, EqualityComparer <string> .Default); orders7.HashAbility(); var orders4 = new LinkedHashedMap <string, Order>(500, (x1, x2) => x1 == x2); orders4.HashAbility(); //var orders5 = new LinkedHashedMap<string, Order>(orders2, EqualityComparer<string>.Default); //Assert.NotEmpty(orders5); //Assert.Equal(orders2.Count, orders5.Count); //orders5.Clear(); //Assert.Equal(0, orders5.Count); //var orders9 = new LinkedHashedMap<string, Order>(orders2, (x1, x2) => x1 == x2); //Assert.NotEmpty(orders9); //Assert.Equal(orders2.Count, orders9.Count); //orders9.Clear(); //Assert.Equal(0, orders9.Count); }
public void TestOrderedMap() { var container = new LinkedHashedMap <int, string>(10000); Assert.Throws(typeof(InvalidOperationException), () => container.First); Assert.Throws(typeof(InvalidOperationException), () => container.Last); Assert.Throws(typeof(InvalidOperationException), () => container.After(1)); Assert.Throws(typeof(InvalidOperationException), () => container.Before(1)); for (var i = 0; i < 10000; i++) { container.Add(i, i.ToString()); } Assert.Equal(0, container.First.Key); Assert.Equal("0", container.First.Value); Assert.Equal(9999, container.Last.Key); Assert.Equal("9999", container.Last.Value); Assert.Equal("0", container.GetIndex(0).Value); Assert.Equal("1000", container.GetIndex(1000).Value); Assert.Equal("1600", container.GetIndex(1600).Value); Assert.Equal("2749", container.GetIndex(2749).Value); Assert.Equal("4999", container.GetIndex(4999).Value); Assert.Equal("11", container.After(10).Value); Assert.Equal("100", container.After(99).Value); Assert.Equal("1001", container.After(1000).Value); Assert.Equal("5000", container.After(4999).Value); Assert.Equal("50", container.Before(51).Value); Assert.Equal("500", container.Before(501).Value); Assert.Equal("1500", container.Before(1501).Value); Assert.Equal("7900", container.Before(7901).Value); Assert.Throws(typeof(ArgumentException), () => container.After(9999)); Assert.Throws(typeof(ArgumentException), () => container.Before(0)); Assert.Throws(typeof(ArgumentException), () => container.Before(10000)); Assert.Throws(typeof(ArgumentException), () => container.After(10000)); Assert.Throws(typeof(ArgumentException), () => container.GetIndex(-100)); Assert.Throws(typeof(ArgumentException), () => container.GetIndex(20000)); for (var i = 2000; i < 5000; i++) { Assert.True(container.Remove(i)); } Assert.Equal("0", container.First.Value); Assert.Equal("9999", container.Last.Value); Assert.Equal("1000", container.After(999).Value); Assert.Equal("999", container.Before(1000).Value); Assert.Equal("9000", container.After(8999).Value); Assert.Equal("8999", container.Before(9000).Value); Assert.Equal("8500", container.Before(8501).Value); Assert.Equal("5000", container.After(1999).Value); Assert.Equal("1999", container.Before(5000).Value); for (var i = 7000; i < 8000; i++) { Assert.True(container.Remove(i)); } Assert.Equal("0", container.First.Value); Assert.Equal("9999", container.Last.Value); Assert.Equal("1000", container.After(999).Value); Assert.Equal("999", container.Before(1000).Value); Assert.Equal("9000", container.After(8999).Value); Assert.Equal("8999", container.Before(9000).Value); Assert.Equal("8500", container.Before(8501).Value); Assert.Equal("8000", container.After(6999).Value); Assert.Equal("6999", container.Before(8000).Value); }
public void TestLinkedHashedMapRemove() { var map = new LinkedHashedMap <int, Order>(); map.Fill(x => new KeyValuePair <int, Order>(x, new Order { Id = x })); Assert.Equal(1000, map.Count); for (var i = 0; i < 100; i++) { Assert.True(map.ContainsKey(i)); Assert.True(map.Remove(i)); Assert.False(map.ContainsKey(i)); } Assert.Throws(typeof(ArgumentException), () => map.After(0)); Assert.Throws(typeof(ArgumentException), () => map.Before(100)); Assert.Throws(typeof(ArgumentException), () => map.After(999)); Assert.Equal(900, map.Count); var index = 100; foreach (var item in map) { Assert.Equal(index, item.Key); index++; } Assert.Equal(1000, index); for (var i = 900; i < 1000; i++) { Assert.True(map.ContainsKey(i)); Assert.True(map.Remove(i)); Assert.False(map.ContainsKey(i)); } Assert.Equal(800, map.Count); Assert.Throws(typeof(ArgumentException), () => map.After(899)); index = 100; foreach (var item in map) { Assert.Equal(index, item.Key); index++; } Assert.Equal(900, index); for (var i = 300; i < 500; i++) { Assert.True(map.ContainsKey(i)); Assert.True(map.Remove(i)); } Assert.Equal(299, map.Before(500).Key); Assert.Equal(500, map.After(299).Key); Assert.Equal(600, map.Count); index = 100; foreach (var item in map) { index = index == 300 ? 500 : index; Assert.Equal(index, item.Key); index++; } Assert.Equal(900, index); }
public LinkedSet(int capacity, Equator <T> equator) { map = new LinkedHashedMap <T, object>(capacity, equator); }
public LinkedSet(int capacity, IEqualityComparer <T> comparer) { map = new LinkedHashedMap <T, object>(capacity, comparer); }
public LinkedSet(Equator <T> equator) { map = new LinkedHashedMap <T, object>(equator); }
public LinkedSet(IEqualityComparer <T> comparer) { map = new LinkedHashedMap <T, object>(comparer); }
public LinkedSet(int capacity) { map = new LinkedHashedMap <T, object>(capacity); }
public LinkedSet() { map = new LinkedHashedMap <T, object>(); }