diff --git a/spec/unit/optmath_spec.lua b/spec/unit/optmath_spec.lua index 55610968f..d7f316cce 100644 --- a/spec/unit/optmath_spec.lua +++ b/spec/unit/optmath_spec.lua @@ -6,6 +6,34 @@ describe("Math module", function() Math = require("optmath") end) + describe("tmin", function() + it("should return nil on empty table", function() + assert.is_nil(Math.tmin({})) + end) + it("should get minimum element in table", function() + assert.are.same(5, Math.tmin({9,7,10,11,5,7})) + end) + it("should get minimum element in table using custom function", function() + assert.are.same(5, + Math.tmin({"9","7","10","11","5","7"}, function(a,b) + return tonumber(a) > tonumber(b) + end)) + end) + end) + describe("tmax", function() + it("should return nil on empty table", function() + assert.is_nil(Math.tmin({})) + end) + it("should get maximum element in table", function() + assert.are.same(4, Math.tmax({9,7,10,11,5,7})) + end) + it("should get maximum element in table using custom function", function() + assert.are.same(4, + Math.tmax({"9","7","10","11","5","7"}, function(a,b) + return tonumber(a) < tonumber(b) + end)) + end) + end) it("should round away from zero", function() assert.are.same(2, Math.roundAwayFromZero(1.5)) assert.are.same(2, Math.roundAwayFromZero(1.4))