From 626d7340f365ca04a21ea805ea2ea124c91224fe Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Thu, 28 Feb 2019 15:01:13 +0100 Subject: [PATCH] [spec] Add more TimeVal tests (#4672) That should please CodeCov. --- spec/unit/timeval_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/unit/timeval_spec.lua b/spec/unit/timeval_spec.lua index f21cf3cbe..80e3684e5 100644 --- a/spec/unit/timeval_spec.lua +++ b/spec/unit/timeval_spec.lua @@ -15,6 +15,13 @@ describe("TimeVal module", function() end end) + it("should add", function() + local timev1 = TimeVal:new{ sec = 5, usec = 5000} + local timev2 = TimeVal:new{ sec = 10, usec = 6000} + + assert.is.same({sec = 15,usec = 11000}, timev1 + timev2) + end) + it("should subtract", function() local timev1 = TimeVal:new{ sec = 5, usec = 5000} local timev2 = TimeVal:new{ sec = 10, usec = 6000} @@ -31,4 +38,26 @@ describe("TimeVal module", function() assert.has.errors(function() return timev1 - timev2 end) end) + + it("should derive sec and usec from more than 1 sec worth of usec", function() + local timev1 = TimeVal:new{ sec = 5, usec = 5000000} + + assert.is.same({sec = 10,usec = 0}, timev1) + end) + + it("should compare", function() + local timev1 = TimeVal:new{ sec = 5, usec = 5000} + local timev2 = TimeVal:new{ sec = 10, usec = 6000} + local timev3 = TimeVal:new{ sec = 5, usec = 5000} + + assert.is_true(timev2 > timev1) + assert.is_true(timev2 >= timev1) + + assert.is_true(timev1 < timev2) + assert.is_true(timev1 <= timev2) + + assert.is_true(timev1 == timev3) + assert.is_true(timev1 >= timev3) + assert.is_true(timev1 <= timev3) + end) end)