public void ItShouldBeStoppable() { var tc = new TestTimeContext(); var invocations = 0; var duration = 3.seconds(); var cr = tc.every(duration, () => invocations++); invocations.shouldEqual(0); tc.timePassed += duration; invocations.shouldEqual(1); tc.timePassed += duration / 2; invocations.shouldEqual(1); tc.timePassed += duration; invocations.shouldEqual(2); var onFinishInvocations = 0; cr.onFinish += () => onFinishInvocations++; cr.stop(); cr.finished.shouldBeTrue(); onFinishInvocations.shouldEqual(1); cr.stop(); cr.finished.shouldBeTrue(); onFinishInvocations.shouldEqual(1); tc.timePassed += duration; invocations.shouldEqual(2); }
public void Test() { var d = Duration.fromSeconds(1); var tc = new TestTimeContext(); var f = Future.delay(d, 3, tc); f.value.shouldBeNone(); tc.timePassed = d / 2; f.value.shouldBeNone(); tc.timePassed = d; f.value.shouldBeSome(3); }
public void Test() { var frameDuration = new Duration(20); var tc = new TestTimeContext(frameDuration); var f = Future.delayFrames(3, 3, tc); f.value.shouldBeNone(); tc.timePassed = frameDuration * 2; f.value.shouldBeNone(); tc.timePassed = frameDuration * 3; f.value.shouldBeSome(3); }
public void ItShouldBeAbleToSelfStop() { var tc = new TestTimeContext(); var invocations = 0; var duration = 3.seconds(); var keepRunning = true; var cr = tc.every(duration, () => { invocations++; return(keepRunning); }); invocations.shouldEqual(0); tc.timePassed += duration; invocations.shouldEqual(1); tc.timePassed += duration / 2; invocations.shouldEqual(1); tc.timePassed += duration; invocations.shouldEqual(2); var onFinishInvocations = 0; cr.onFinish += () => onFinishInvocations++; keepRunning = false; tc.timePassed += duration; invocations.shouldEqual(3); cr.finished.shouldBeTrue(); onFinishInvocations.shouldEqual(1); tc.timePassed += duration; invocations.shouldEqual(3); cr.finished.shouldBeTrue(); onFinishInvocations.shouldEqual(1); cr.stop(); cr.finished.shouldBeTrue(); onFinishInvocations.shouldEqual(1); }
public void ItShouldRepeatTheAction() { var tc = new TestTimeContext(); var invocations = 0; var duration = 3.seconds(); tc.every(duration, () => invocations++); invocations.shouldEqual(0); tc.timePassed += duration; invocations.shouldEqual(1); tc.timePassed += duration / 2; invocations.shouldEqual(1); tc.timePassed += duration; invocations.shouldEqual(2); tc.timePassed += duration; invocations.shouldEqual(3); }
public void setup() { sourceFuture = Future <int> .async(out promise); tc = new TestTimeContext(); }