[spec] Add more TimeVal tests (#4672)

That should please CodeCov.
This commit is contained in:
Frans de Jonge
2019-02-28 15:01:13 +01:00
committed by GitHub
parent abba7ba873
commit 626d7340f3

View File

@@ -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)