public void ToLookupIsImmediate() { var src = new IterateAndCount(10); var a = src.ToLookup(i => i > 5, null); var b = src.ToLookup(i => i > 5, j => "str: " + j.ToString(CultureInfo.InvariantCulture), null); Assert.AreEqual(src.Total, 20); a.Consume(); b.Consume(); Assert.AreEqual(src.Total, 20); }
public void ProgressiveLookupIsCached() { var src = new IterateAndCount(10); var a = ProgressiveLookup <bool, int> .Create(src, i => i > 5, null); var b = ProgressiveLookup <bool, string> .Create(src, i => i > 5, j => "str: " + j.ToString(CultureInfo.InvariantCulture), null); Assert.AreEqual(src.Total, 0); a.Consume(); b.Consume(); Assert.AreEqual(src.Total, 20); }
public void GroupByIsDefered() { var _src = new IterateAndCount(10); var a = _src.GroupBy(i => i > 5, null); var b = _src.GroupBy(i => i > 5, j => "str: " + j.ToString(CultureInfo.InvariantCulture), null); var c = _src.GroupBy(i => i > 5, (key, group) => StringHelper.Concat(group.ToArray()), null); var d = _src.GroupBy(i => i > 5, j => j + 1, (key, group) => StringHelper.Concat(group.ToArray()), null); Assert.AreEqual(_src.Total, 0); a.Consume(); b.Consume(); c.Consume(); d.Consume(); Assert.AreEqual(_src.Total, 40); }
public void GroupProgressiveByIsDeferred() { var src = new IterateAndCount(10); var a = src.GroupProgressiveBy(i => i > 5, null); var b = src.GroupProgressiveBy(i => i > 5, j => "str: " + j.ToString(CultureInfo.InvariantCulture), null); var c = src.GroupProgressiveBy(i => i > 5, (_, group) => StringEx.Concat(group.ToArray()), null); var d = src.GroupProgressiveBy(i => i > 5, j => j + 1, (_, group) => StringEx.Concat(group.ToArray()), null); Assert.AreEqual(src.Total, 0); a.Consume(); b.Consume(); c.Consume(); d.Consume(); Assert.AreEqual(src.Total, 40); }
public void GroupByIsDeferedToGetEnumerator() { var _src = new IterateAndCount(10); var a = _src.GroupBy(i => i > 5, null); Assert.AreEqual(_src.Total, 0); using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deffered Assert.AreEqual(_src.Total, 10); } Assert.AreEqual(_src.Total, 10); using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deffered Assert.AreEqual(_src.Total, 20); } Assert.AreEqual(_src.Total, 20); }
public void GroupByIsDeferedToGetEnumerator() // TODO: Review { var src = new IterateAndCount(10); var a = src.GroupBy(i => i > 5, null); Assert.AreEqual(src.Total, 0); using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deffered GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 10); } Assert.AreEqual(src.Total, 10); using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deffered GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 20); } Assert.AreEqual(src.Total, 20); }
public void GroupProgressiveByIsDeferredToGetEnumerator() { var src = new IterateAndCount(10); var a = src.GroupProgressiveBy(i => i > 5, null); Assert.AreEqual(src.Total, 0); using (var enumerator = a.GetEnumerator()) { // GroupProgressiveBy is truly deferred GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 0); } Assert.AreEqual(src.Total, 0); using (var enumerator = a.GetEnumerator()) { // GroupProgressiveBy is truly deferred GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 0); } Assert.AreEqual(src.Total, 0); }
public void GroupByIsDeferredToGetEnumerator() { var src = new IterateAndCount(10); var a = src.GroupBy(i => i > 5, null); Assert.AreEqual(src.Total, 0); // ReSharper disable once PossibleMultipleEnumeration using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deferred GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 10); } Assert.AreEqual(src.Total, 10); // ReSharper disable once PossibleMultipleEnumeration using (var enumerator = a.GetEnumerator()) { // This is a shame, GroupBy is not really deferred GC.KeepAlive(enumerator); Assert.AreEqual(src.Total, 20); } Assert.AreEqual(src.Total, 20); }