From 720fd5d826f2a1c9fe3b6c8b02bf282d7e1f7eed Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Thu, 22 Feb 2018 12:26:51 +0100 Subject: [PATCH] [spec] Test all aspects of Math module (#3683) --- spec/unit/optmath_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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))