forked from lunarmodules/Penlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_spec.lua
More file actions
54 lines (44 loc) · 1.61 KB
/
func_spec.lua
File metadata and controls
54 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local func = require("pl.func")
describe("pl.func", function ()
describe("compose", function ()
it("compose(f)(x) == f(x)", function ()
local f = function(x) return x + 1 end
assert.equals(func.compose(f)(1), f(1))
end)
it("compose(f, g)(x) == f(g(x))", function ()
local f = function(x) return x + 1 end
local g = function(x) return x + 2 end
assert.equals(func.compose(f, g)(1), f(g(1)))
end)
it("compose(f, g, h)(x) == f(g(h(x)))", function ()
local f = function(x) return x + 1 end
local g = function(x) return x + 2 end
local h = function(x) return x + 3 end
assert.equals(func.compose(f, g, h)(1), f(g(h(1))))
end)
it("compose(f)(x, y) == f(x, y)", function ()
local f = function(x, y) return x + 1, y + 1 end
local ax, ay = func.compose(f)(1, 2)
local bx, by = f(1, 2)
assert.equals(ax, bx)
assert.equals(ay, by)
end)
it("compose(f, g)(x, y) == f(g(x, y))", function ()
local f = function(x, y) return x + 1, y + 1 end
local g = function(x, y) return x + 2, y + 2 end
local ax, ay = func.compose(f, g)(1, 2)
local bx, by = f(g(1, 2))
assert.equals(ax, bx)
assert.equals(ay, by)
end)
it("compose(f, g, h)(x, y) == f(g(h(x, y)))", function ()
local f = function(x, y) return x + 1, y + 1 end
local g = function(x, y) return x + 2, y + 2 end
local h = function(x, y) return x + 3, y + 3 end
local ax, ay = func.compose(f, g, h)(1, 2)
local bx, by = f(g(h(1, 2)))
assert.equals(ax, bx)
assert.equals(ay, by)
end)
end)
end)