Modeling and testing a basic stopwatch #1173
-
|
Hi, I am new to Kyo. I have modeled a very basic stopwatch (using also the The code can be seen here on Scastie https://scastie.scala-lang.org/mcallisto/29P0lehNTyCHOkHMWRvdmA/4 Questions I have in mind:
Thank you in advance for your ideas |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Since I was not confident it worked 100%, I created an alternate version based on The new code on Scastie as well, see https://scastie.scala-lang.org/mcallisto/UJJDRcSgSSapscFjSr9LxA |
Beta Was this translation helpful? Give feedback.
-
|
Hi @mcallisto -- sorry we missed this back in may. None of us have really been monitoring discussions...
Clock.withTimeControl: timeControl =>
for
stopWatch <- AltStopWatch.create
initialTimeStopped <- stopWatch.updateAndGetTotalElapsedTime
_ <- timeControl.advance(1.hour)
timeAfterOneHourStopped <- stopWatch.updateAndGetTotalElapsedTime
_ <- stopWatch.start
timeAfterStarted <- stopWatch.updateAndGetTotalElapsedTime
_ <- timeControl.advance(1.hour)
timeAfterOneHourStarted <- stopWatch.updateAndGetTotalElapsedTime
_ <- stopWatch.reset
timeAfterReset <- stopWatch.updateAndGetTotalElapsedTime
_ <- timeControl.advance(30.minutes)
timeAfterThirtyMinsAfterReset <- stopWatch.updateAndGetTotalElapsedTime
yield assert(
initalTimeStopped == Duration.Zero
&& timeAfterOneHourStopped == Duration.Zero
&& timeAfterStarted == Duration.Zero
&& timeAfterOneHourStarted == 1.hour
&& timeAfterReset == Duration.Zero
&& timeAfterThirtyMinsAfterReset == Duration.Zero
) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @johnhungerford and @fwbrasil for your detailed replies! Sorry for starting the In general I think some space where questions like this can be filed (and not lost) is needed. I know @fwbrasil is quite active on Discord but it is a little bit too chaotic there on the Scala channels without threads. Maybe I could have posted it to Stack Overflow but here it felt more like "home". |
Beta Was this translation helpful? Give feedback.
Hi @mcallisto -- sorry we missed this back in may. None of us have really been monitoring discussions...
updateAndGetTotalElapsedTimetocurrentTimeor something. The name exposes implementation details. I might also hide everything behind a trait.Clock.withTimeControl: