From 1c164e0a734c205d0e16adead230e2200d75f1d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 22 May 2016 09:48:53 -0400 Subject: [PATCH] tests & lib/realtime: rewrite test as a nitunit MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/realtime.nit | 14 ++++++++++++++ tests/sav/test_realtime.res | 7 ------- tests/test_realtime.nit | 43 ------------------------------------------- 3 files changed, 14 insertions(+), 50 deletions(-) delete mode 100644 tests/sav/test_realtime.res delete mode 100644 tests/test_realtime.nit 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 -- 1.7.9.5