diff options
author | Yonaba <roland.yonaba@gmail.com> | 2017-04-14 17:45:55 +0300 |
---|---|---|
committer | Yonaba <roland.yonaba@gmail.com> | 2017-04-14 17:45:55 +0300 |
commit | 49aec875a0417c351e5dec2b7bd551e0660e290e (patch) | |
tree | 49da86c520c6027ffee3400979d3668baf528c53 /spec | |
parent | 168c64d7f421cf2e570c6c9efd4d17d0a3e29964 (diff) |
Added _.overEvery and _.overSome
Diffstat (limited to 'spec')
-rw-r--r-- | spec/func_spec.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/func_spec.lua b/spec/func_spec.lua index 1fa1c70..2c9e3ce 100644 --- a/spec/func_spec.lua +++ b/spec/func_spec.lua @@ -337,7 +337,57 @@ context('Utility functions specs', function() end) end) + + context('overEvery', function() + + local alleven, allpositive + + before(function() + alleven = function(...) + for i, v in ipairs({...}) do if v%2~=0 then return false end end + return true + end + + allpositive = function(...) + for i, v in ipairs({...}) do if v < 0 then return false end end + return true + end + end) + + test('checks if all predicates passes truth with args. ',function() + local allok = _.overEvery(alleven, allpositive) + assert_false(allok(2,4,-1,8)) + assert_false(allok(10,3,2,6)) + assert_true(allok(8,4,6,10)) + end) + + end) + + context('overSome', function() + + local alleven, allpositive + + before(function() + alleven = function(...) + for i, v in ipairs({...}) do if v%2~=0 then return false end end + return true + end + + allpositive = function(...) + for i, v in ipairs({...}) do if v < 0 then return false end end + return true + end + end) + test('checks if all predicates passes truth with args. ',function() + local anyok = _.overSome(alleven, allpositive) + assert_false(anyok(2,4,-1,8)) + assert_true(anyok(10,3,2,6)) + assert_false(anyok(-1,-5,-3)) + end) + + end) + context('overArgs', function() test('Creates a function that invokes `f` with its arguments transformed',function() |