private static void AssertEventsBetween <T>( IOrderedDictionary <int, T> treemap, MySubmapEvent sme, SupportBean[] events, SupportBean lastOf) where T : ICollection <SupportBean> { var submap = treemap.Between(sme.FromKey, sme.IsFromInclusive, sme.ToKey, sme.IsToInclusive); var all = new List <SupportBean>(); foreach (var entry in submap) { all.AddAll(entry.Value); } EPAssertionUtil.AssertEqualsExactOrder(all.ToArray(), events); if (all.IsEmpty()) { Assert.IsNull(lastOf); } else { Assert.AreEqual(all[all.Count - 1], lastOf); } }
public void Run(RegressionEnvironment env) { var epl = "@public @buseventtype create schema MySubmapEvent as " + typeof(MySubmapEvent).MaskTypeName() + ";\n" + "create table MyTable(sortcol sorted(IntPrimitive) @type('SupportBean'));\n" + "into table MyTable select sorted(*) as sortcol from SupportBean;\n" + "@Name('s0') select " + "MyTable.sortcol.eventsBetween(FromKey, IsFromInclusive, ToKey, IsToInclusive) as eb," + "MyTable.sortcol.eventsBetween(FromKey, IsFromInclusive, ToKey, IsToInclusive).lastOf() as eblastof," + "MyTable.sortcol.subMap(FromKey, IsFromInclusive, ToKey, IsToInclusive) as sm" + " from MySubmapEvent"; env.CompileDeploy(epl).AddListener("s0"); AssertType(env, typeof(SupportBean[]), "eb"); AssertType(env, typeof(IOrderedDictionary <object, object>), "sm"); AssertType(env, typeof(SupportBean), "eblastof"); var treemap = new OrderedListDictionary <int, IList <SupportBean> >(); PrepareTestData(env, treemap); // 1, 1, 4, 6, 6, 8, 9 for (var start = 0; start < 12; start++) { for (var end = 0; end < 12; end++) { if (start > end) { continue; } foreach (var includeStart in new bool[] { false, true }) { foreach (var includeEnd in new bool[] { false, true }) { var sme = new MySubmapEvent(start, includeStart, end, includeEnd); env.SendEventBean(sme); var @event = env.Listener("s0").AssertOneGetNewAndReset(); var submap = @event.Get("sm") .AsObjectDictionary(MagicMarker.SingletonInstance) .TransformLeft <object, object, SupportBean[]>(); AssertEventsBetween(treemap, sme, (SupportBean[])@event.Get("eb"), (SupportBean)@event.Get("eblastof")); AssertSubmap(treemap, sme, submap); } } } } env.UndeployAll(); }
private static void AssertSubmap <T>( IOrderedDictionary <int, T> treemap, MySubmapEvent sme, IDictionary <object, SupportBean[]> actual) where T : ICollection <SupportBean> { var expected = treemap.Between(sme.FromKey, sme.IsFromInclusive, sme.ToKey, sme.IsToInclusive); Assert.AreEqual(expected.Count, actual.Count); foreach (var key in expected.Keys) { var expectedEvents = expected.Get(key).ToArray(); var actualEvents = actual.Get(key); EPAssertionUtil.AssertEqualsExactOrder(expectedEvents, actualEvents); } }