/// <summary> /// Finds a key-value mapping associated with the greatest key strictly less than the given key. /// </summary> /// <param name="key"></param> /// <returns></returns> public KeyValuePair <TK1, TV1>?LessThan(TK1 key) { var value = _subDictionaryOrdered.LessThan(KeyIn(key)); return(value.HasValue ? new KeyValuePair <TK1, TV1>(KeyOut(value.Value.Key), ValueOut(value.Value.Value)) : default(KeyValuePair <TK1, TV1>?)); }
private static void AssertOrderedDictionary( IOrderedDictionary <int, IList <SupportBean> > treemap, IOrderedDictionary <object, ICollection <EventBean> > actual) { Assert.AreEqual(treemap.Count, actual.Count); foreach (var key in treemap.Keys) { var expectedEvents = treemap.Get(key).ToArray(); EPAssertionUtil.AssertEqualsExactOrder(expectedEvents, ToArrayOfUnderlying(actual.Get(key))); } CompareEntry(treemap.First(), actual.FirstEntry); CompareEntry(treemap.Last(), actual.LastEntry); CompareEntry(treemap.LessThanOrEqualTo(5), actual.LessThanOrEqualTo(5)); CompareEntry(treemap.GreaterThanOrEqualTo(5), actual.GreaterThanOrEqualTo(5)); CompareEntry(treemap.LessThan(5), actual.LessThan(5)); CompareEntry(treemap.GreaterThan(5), actual.GreaterThan(5)); Assert.AreEqual(treemap.Keys.First(), actual.FirstEntry.Key); Assert.AreEqual(treemap.Keys.Last(), actual.LastEntry.Key); Assert.AreEqual(treemap.LessThanOrEqualTo(5)?.Key, actual.LessThanOrEqualTo(5)?.Key); Assert.AreEqual(treemap.GreaterThanOrEqualTo(5)?.Key, actual.GreaterThanOrEqualTo(5)?.Key); Assert.AreEqual(treemap.LessThan(5)?.Key, actual.LessThan(5)?.Key); Assert.AreEqual(treemap.GreaterThan(5)?.Key, actual.GreaterThan(5)?.Key); Assert.AreEqual(treemap.ContainsKey(5), actual.ContainsKey(5)); Assert.AreEqual(treemap.IsEmpty(), actual.IsEmpty()); EPAssertionUtil.AssertEqualsExactOrder(new object[] { 1, 4, 6, 8, 9 }, actual.Keys.ToArray()); Assert.AreEqual(1, actual.Between(9, true, 9, true).Count); Assert.AreEqual(1, actual.Tail(9).Count); Assert.AreEqual(1, actual.Tail(9, true).Count); Assert.AreEqual(1, actual.Head(2).Count); Assert.AreEqual(1, actual.Head(2, false).Count); Assert.AreEqual(5, actual.Count); Assert.AreEqual(5, actual.Keys.Count); Assert.AreEqual(5, actual.Values.Count); // values var values = actual.Values; Assert.That(values.Count, Is.EqualTo(5)); Assert.That(values.IsEmpty(), Is.False); var valuesEnum = values.GetEnumerator(); Assert.That(valuesEnum, Is.Not.Null); Assert.That(valuesEnum.MoveNext, Is.True); CollectionAssert.AreEqual( treemap.Get(1).ToArray(), ToArrayOfUnderlying(valuesEnum.Current)); Assert.That(valuesEnum.MoveNext, Is.True); Assert.That(values.ToArray(), Has.Length.EqualTo(5)); CollectionAssert.AreEqual( treemap.Get(1).ToArray(), ToArrayOfUnderlying((ICollection <EventBean>)values.ToArray()[0])); // ordered key set var oks = actual.OrderedKeys; //Assert.That(oks.Comparator()); Assert.That(oks.FirstEntry, Is.EqualTo(1)); Assert.That(oks.LastEntry, Is.EqualTo(9)); Assert.That(oks.Count, Is.EqualTo(5)); Assert.That(oks.IsEmpty(), Is.False); Assert.That(oks.Contains(6), Is.True); Assert.That(oks.ToArray(), Is.Not.Null); Assert.That(oks.LessThan(5), Is.EqualTo(4)); Assert.That(oks.GreaterThan(5), Is.EqualTo(6)); Assert.That(oks.LessThanOrEqualTo(5), Is.EqualTo(4)); Assert.That(oks.GreaterThanOrEqualTo(5), Is.EqualTo(6)); Assert.That(oks.Between(1, true, 100, true), Is.Not.Null); Assert.That(oks.Head(100, true), Is.Not.Null); Assert.That(oks.Tail(1, true), Is.Not.Null); // ordered key set - enumerator var oksit = oks.GetEnumerator(); Assert.That(oksit, Is.Not.Null); Assert.That(oksit.MoveNext(), Is.True); Assert.That(oksit.Current, Is.EqualTo(1)); Assert.That(oksit.MoveNext(), Is.True); // entry set ICollection <KeyValuePair <object, ICollection <EventBean> > > set = actual; Assert.IsFalse(set.IsEmpty()); var setit = set.GetEnumerator(); var entry = setit.Advance(); Assert.AreEqual(1, entry.Key); Assert.IsTrue(setit.MoveNext()); EPAssertionUtil.AssertEqualsExactOrder(treemap.Get(1).ToArray(), ToArrayOfUnderlying(entry.Value)); var array = set.ToArray(); Assert.AreEqual(5, array.Length); Assert.AreEqual(1, array[0].Key); EPAssertionUtil.AssertEqualsExactOrder(treemap.Get(1).ToArray(), ToArrayOfUnderlying(array[0].Value)); Assert.IsNotNull(set.ToArray()); // sorted map var events = actual.Head(100); Assert.AreEqual(5, events.Count); }