public void CouldReadVariantSeries() { var sm = new SortedMap <int, string>(); for (int i = 0; i < 100; i++) { sm.Add(i, (i * 100).ToString()); } var vs = new VariantSeries <int, string>(sm); foreach (var item in vs) { System.Console.WriteLine(item.Key.Get <int>() + ": " + item.Value.Get <string>()); } Assert.AreEqual(Variant.Create(0), vs.First.Key); Assert.AreEqual(Variant.Create("0"), vs.First.Value); Assert.AreEqual(Variant.Create(99), vs.Last.Key); Assert.AreEqual(Variant.Create("9900"), vs.Last.Value); var cursorSeries = new CursorSeries <int, string>(sm); Assert.AreEqual(0, cursorSeries.First.Key); }
public void CouldAddVariantSeries() { var sm = new SortedMap <int, double>(); for (int i = 0; i < 100; i++) { sm.Add(i, (i * 100)); } var vs = new VariantSeries <int, double>(sm); var doubled = vs + vs; foreach (var item in doubled) { System.Console.WriteLine(item.Key.Get <int>() + ": " + item.Value.Get <double>()); } Assert.AreEqual(Variant.Create(0), doubled.First.Key); Assert.AreEqual(Variant.Create(0.0), doubled.First.Value); Assert.AreEqual(Variant.Create(99), doubled.Last.Key); Assert.AreEqual(Variant.Create(9900.0 * 2), doubled.Last.Value); var cursorSeries = doubled.ReadOnly(); Assert.AreEqual(Variant.Create(0), cursorSeries.First.Key); }
public async void RangeOnVariantSeriesWorks() { var sm = new SortedMap <DateTime, int>(); for (int i = 0; i < 100; i++) { sm.Add(DateTime.Today.AddSeconds(i), i); } var vs = new VariantSeries <DateTime, int>(sm); Assert.IsTrue(!vs.Comparer.Equals(KeyComparer <Variant> .Default)); var rs = vs.After(Variant.Create(DateTime.Today.AddSeconds(50))); Assert.IsTrue(!rs.Comparer.Equals(KeyComparer <Variant> .Default)); var expected = 0; for (int i = 50; i < 100; i++) { expected += i; } var sum = 0; foreach (var variantKvp in rs) { sum += variantKvp.Value.Get <int>(); } Assert.AreEqual(expected, sum); var t = Task.Run(async() => { try { for (int i = 100; i < 150; i++) { sm.Add(DateTime.Today.AddSeconds(i), i); await Task.Delay(1); } sm.Complete(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }); var c = rs.GetCursor(); while (await c.MoveNext(CancellationToken.None)) { sum += c.CurrentValue.Get <int>(); } }