public void Trimmable_Create() { var values = new List <int>(); var res = Trimmable.Create <int>(shouldTrim => { return(values.RemoveAll(x => shouldTrim(x))); }); values.Add(1); values.Add(2); values.Add(3); values.Add(4); Assert.AreEqual(2, res.Trim(x => x % 2 == 0)); Assert.AreEqual(2, values.Count); }
public object GetService(Type serviceType) { if (_hasServices) { if (serviceType == typeof(ITrimmable <KeyValuePair <T, R> >)) { return(Trimmable.Create <KeyValuePair <T, R> >(_ => 0)); } else if (serviceType == typeof(ITrimmable <KeyValuePair <T, IValueOrError <R> > >)) { return(Trimmable.Create <KeyValuePair <T, IValueOrError <R> > >(_ => 0)); } else if (serviceType == typeof(ITrimmable <IMemoizationCacheEntryMetrics>)) { return(Trimmable.Create <IMemoizationCacheEntryMetrics>(_ => 0)); } } return(null); }
public void Trimmable_Create_ArgumentChecking() { Assert.ThrowsException <ArgumentNullException>(() => Trimmable.Create <int>(trim: null)); Assert.ThrowsException <ArgumentNullException>(() => Trimmable.Create <int>(_ => 0).Trim(shouldTrim: null)); }