private void cleanupSubscriptions() { if (pendingRemovals == 0) { return; } subscriptions.RemoveWhere(t => !t._1.isSubscribed); pendingRemovals = 0; }
[Test] public void RemoveWhereNoneTest() { var l = new RandomList <int> { 1, 3, 5, 7, 9 }; l.RemoveWhere(i => i % 2 == 0); Assert.AreEqual(F.list(1, 3, 5, 7, 9), l); Assert.AreEqual(5, l.Count); }
[Test] public void RemoveWhereAllTest() { var l = new RandomList <int> { 2, 4, 6, 8, 10 }; l.RemoveWhere(i => i % 2 == 0); Assert.AreEqual(F.emptyList <int>(), l); Assert.AreEqual(0, l.Count); }
void triggerActions() { actions.RemoveWhere(t => t.ua((runAt, act) => { var shouldRun = timePassed >= runAt; if (shouldRun) { act(); } return(shouldRun); })); }
[Test] public void RemoveWhereAlteringTest() { var l = new RandomList <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; l.RemoveWhere(i => i % 2 == 0); // { 1, 9, 3, 4, 5, 6, 7, 8 } // { 1, 9, 3, 8, 5, 6, 7 } // { 1, 9, 3, 7, 5, 6 } // { 1, 9, 3, 7, 5 } Assert.AreEqual(F.list(1, 9, 3, 7, 5), l); Assert.AreEqual(5, l.Count); }
void triggerActions() { // Actions might remove themselves as side effects, so we should first evaluate // all actions that should be run, then remove the ran actions if they are still // there. var toRun = actions.Where(t => t.ua((runAt, act, name) => { var shouldRun = timePassed >= runAt; return(shouldRun); })).ToList(); foreach (var t in toRun) { t._2(); } actions.RemoveWhere(toRun.Contains); }
[Test] public void RemoveWhereSequentialTest() { var l = new RandomList <int> { 1, 2, 2, 2, 3, 4, 4, 4, 5 }; l.RemoveWhere(i => i % 2 == 0); // {1, 5, 2, 2, 3, 4, 4, 4} // {1, 5, 4, 2, 3, 4, 4} // {1, 5, 4, 2, 3, 4} // {1, 5, 4, 2, 3} // {1, 5, 3, 2} // {1, 5, 3} Assert.AreEqual(F.list(1, 5, 3), l); Assert.AreEqual(3, l.Count); }