aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/functional/number_spec.lua
blob: db523c2d334ec5a15ebf0014aefac5545b119a9a (plain) (blame)
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
local _ = require "mason-core.functional"

describe("functional: number", function()
    it("should negate numbers", function()
        assert.equals(-42, _.negate(42))
        assert.equals(42, _.negate(-42))
    end)

    it("should check numbers greater than value", function()
        local greater_than_life = _.gt(42)
        assert.is_false(greater_than_life(0))
        assert.is_false(greater_than_life(42))
        assert.is_true(greater_than_life(43))
    end)

    it("should check numbers greater or equal than value", function()
        local greater_or_equal_to_life = _.gte(42)
        assert.is_false(greater_or_equal_to_life(0))
        assert.is_true(greater_or_equal_to_life(42))
        assert.is_true(greater_or_equal_to_life(43))
    end)

    it("should check numbers lower than value", function()
        local lesser_than_life = _.lt(42)
        assert.is_true(lesser_than_life(0))
        assert.is_false(lesser_than_life(42))
        assert.is_false(lesser_than_life(43))
    end)

    it("should check numbers lower or equal than value", function()
        local lesser_or_equal_to_life = _.lte(42)
        assert.is_true(lesser_or_equal_to_life(0))
        assert.is_true(lesser_or_equal_to_life(42))
        assert.is_false(lesser_or_equal_to_life(43))
    end)

    it("should increment numbers", function()
        local add_5 = _.inc(5)
        assert.equals(0, add_5(-5))
        assert.equals(5, add_5(0))
        assert.equals(7, add_5(2))
    end)

    it("should decrement numbers", function()
        local subtract_5 = _.dec(5)
        assert.equals(5, subtract_5(10))
        assert.equals(-5, subtract_5(0))
        assert.equals(-3, subtract_5(2))
    end)
end)