-
Notifications
You must be signed in to change notification settings - Fork 2
/
if_test.go
97 lines (80 loc) · 2.84 KB
/
if_test.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package functions_for_govaluate_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/jamillosantos/functions-for-govaluate"
)
var _ = Describe("if functions", func() {
It("should evaluate a boolean operation (true)", func() {
c, err := functions_for_govaluate.If(true, 1, 0)
Expect(err).To(BeNil())
Expect(c).To(Equal(1))
})
It("should evaluate a boolean operation (false)", func() {
c, err := functions_for_govaluate.If(false, 1, 0)
Expect(err).To(BeNil())
Expect(c).To(Equal(0))
})
It("should get correct value with a float (non-zero)", func() {
c, err := functions_for_govaluate.If(0.000001, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
c, err = functions_for_govaluate.If(-0.000001, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should get correct value with a float (zero)", func() {
c, err := functions_for_govaluate.If(0.0, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
c, err = functions_for_govaluate.If(-0.0, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should get correct value with an integer (non-zero)", func() {
c, err := functions_for_govaluate.If(1, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
c, err = functions_for_govaluate.If(-1, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should get correct value with an integer (zero)", func() {
c, err := functions_for_govaluate.If(0, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
c, err = functions_for_govaluate.If(-0, true, false)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should get correct value with a string (non-empty)", func() {
c, err := functions_for_govaluate.If("non empty string", true, false)
Expect(err).To(BeNil())
Expect(c).To(BeTrue())
})
It("should get correct value with a string (empty)", func() {
c, err := functions_for_govaluate.If("", true, false)
Expect(err).To(BeNil())
Expect(c).To(BeFalse())
})
It("should get an wrong param count error (too few arguments)", func() {
c, err := functions_for_govaluate.If()
Expect(c).To(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
Expect(err).NotTo(BeNil())
c, err = functions_for_govaluate.If(0)
Expect(c).To(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
Expect(err).NotTo(BeNil())
c, err = functions_for_govaluate.If(0, 0)
Expect(c).To(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
Expect(err).NotTo(BeNil())
})
It("should get an wrong param count error (too many arguments)", func() {
c, err := functions_for_govaluate.Exp(true, true, true, true)
Expect(c).To(BeNil())
Expect(functions_for_govaluate.IsWrongParamsCount(err)).To(BeTrue())
Expect(err).NotTo(BeNil())
})
})