From: Alexis Laferrière Date: Sun, 22 May 2016 13:48:53 +0000 (-0400) Subject: tests & lib/realtime: rewrite test as a nitunit X-Git-Url: http://nitlanguage.org tests & lib/realtime: rewrite test as a nitunit Signed-off-by: Alexis Laferrière --- diff --git a/lib/realtime.nit b/lib/realtime.nit index 5a9571d..243b5d8 100644 --- a/lib/realtime.nit +++ b/lib/realtime.nit @@ -120,6 +120,20 @@ extern class Timespec `{struct timespec*`} end # Keeps track of real time +# +# ~~~ +# var clock = new Clock +# +# # sleeping at least 1s +# 1.0.sleep +# assert clock.total >= 1.0 +# assert clock.lapse >= 1.0 +# +# # sleeping at least 5ms +# 0.005.sleep +# assert clock.total >= 1.005 +# assert clock.lapse >= 0.005 +# ~~~ class Clock super FinalizableOnce diff --git a/tests/sav/test_realtime.res b/tests/sav/test_realtime.res deleted file mode 100644 index 65b7078..0000000 --- a/tests/sav/test_realtime.res +++ /dev/null @@ -1,7 +0,0 @@ -sleeping 1s -true -true -sleeping 5000ns -true -true -true diff --git a/tests/test_realtime.nit b/tests/test_realtime.nit deleted file mode 100644 index 6101a3d..0000000 --- a/tests/test_realtime.nit +++ /dev/null @@ -1,43 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012 Alexis Laferrière -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import realtime - -redef extern class Timespec - fun simplify : Int - do - return sec*1000000 + nanosec/1000 - end -end - -var c = new Clock -var t0 = c.total.simplify - -print "sleeping 1s" -nanosleep(1, 0) -print c.total.sec >= 1 -print c.lapse.sec >= 1 - -var t1 = c.total.simplify - -print "sleeping 5000ns" -nanosleep(0, 5000) -print c.lapse.nanosec >= 5000 - -var t2 = c.total.simplify - -print t0 <= t1 -print t1 <= t2