Skip to content

Commit 20cd5ce

Browse files
Sah, NandeshwarSah, Nandeshwar
authored andcommitted
Added function Pos<Type>
1 parent 5640137 commit 20cd5ce

File tree

12 files changed

+790
-385
lines changed

12 files changed

+790
-385
lines changed

fp/pos.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package fp
2+
3+
// PosInt Returns true if num is greater than zero, else false
4+
func PosInt(v int) bool {
5+
if v > 0 {
6+
return true
7+
}
8+
return false
9+
}
10+
11+
// PosIntPtr Returns true if num is greater than zero, else false
12+
func PosIntPtr(v *int) bool {
13+
if *v > 0 {
14+
return true
15+
}
16+
return false
17+
}
18+
19+
// PosInt64 Returns true if num is greater than zero, else false
20+
func PosInt64(v int64) bool {
21+
if v > 0 {
22+
return true
23+
}
24+
return false
25+
}
26+
27+
// PosInt64Ptr Returns true if num is greater than zero, else false
28+
func PosInt64Ptr(v *int64) bool {
29+
if *v > 0 {
30+
return true
31+
}
32+
return false
33+
}
34+
35+
// PosInt32 Returns true if num is greater than zero, else false
36+
func PosInt32(v int32) bool {
37+
if v > 0 {
38+
return true
39+
}
40+
return false
41+
}
42+
43+
// PosInt32Ptr Returns true if num is greater than zero, else false
44+
func PosInt32Ptr(v *int32) bool {
45+
if *v > 0 {
46+
return true
47+
}
48+
return false
49+
}
50+
51+
// PosInt16 Returns true if num is greater than zero, else false
52+
func PosInt16(v int16) bool {
53+
if v > 0 {
54+
return true
55+
}
56+
return false
57+
}
58+
59+
// PosInt16Ptr Returns true if num is greater than zero, else false
60+
func PosInt16Ptr(v *int16) bool {
61+
if *v > 0 {
62+
return true
63+
}
64+
return false
65+
}
66+
67+
// PosInt8 Returns true if num is greater than zero, else false
68+
func PosInt8(v int8) bool {
69+
if v > 0 {
70+
return true
71+
}
72+
return false
73+
}
74+
75+
// PosInt8Ptr Returns true if num is greater than zero, else false
76+
func PosInt8Ptr(v *int8) bool {
77+
if *v > 0 {
78+
return true
79+
}
80+
return false
81+
}
82+
83+
// PosFloat32 Returns true if num is greater than zero, else false
84+
func PosFloat32(v float32) bool {
85+
if v > 0 {
86+
return true
87+
}
88+
return false
89+
}
90+
91+
// PosFloat32Ptr Returns true if num is greater than zero, else false
92+
func PosFloat32Ptr(v *float32) bool {
93+
if *v > 0 {
94+
return true
95+
}
96+
return false
97+
}
98+
99+
// PosFloat64 Returns true if num is greater than zero, else false
100+
func PosFloat64(v float64) bool {
101+
if v > 0 {
102+
return true
103+
}
104+
return false
105+
}
106+
107+
// PosFloat64Ptr Returns true if num is greater than zero, else false
108+
func PosFloat64Ptr(v *float64) bool {
109+
if *v > 0 {
110+
return true
111+
}
112+
return false
113+
}

fp/pos_test.go

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package fp
2+
3+
import (
4+
_ "errors"
5+
"reflect"
6+
"testing"
7+
)
8+
9+
func TestPosInt(t *testing.T) {
10+
r := PosInt(1)
11+
if !r {
12+
t.Errorf("PosInt failed. Expected=true, actual=false")
13+
t.Errorf(reflect.String.String())
14+
}
15+
16+
r = PosInt(-1)
17+
if r {
18+
t.Errorf("PosInt failed. Expected=false, actual=true")
19+
}
20+
21+
var zero int
22+
var one int = 1
23+
rPtr := PosIntPtr(&one)
24+
if !rPtr {
25+
t.Errorf("PosIntPtr failed. Expected=true, actual=false")
26+
}
27+
28+
rPtr = PosIntPtr(&zero)
29+
if rPtr {
30+
t.Errorf("PosIntPtr failed. Expected=false, actual=true")
31+
}
32+
}
33+
34+
func TestPosInt64(t *testing.T) {
35+
r := PosInt64(1)
36+
if !r {
37+
t.Errorf("PosInt64 failed. Expected=true, actual=false")
38+
t.Errorf(reflect.String.String())
39+
}
40+
41+
r = PosInt64(-1)
42+
if r {
43+
t.Errorf("PosInt64 failed. Expected=false, actual=true")
44+
}
45+
46+
var zero int64
47+
var one int64 = 1
48+
rPtr := PosInt64Ptr(&one)
49+
if !rPtr {
50+
t.Errorf("PosInt64Ptr failed. Expected=true, actual=false")
51+
}
52+
53+
rPtr = PosInt64Ptr(&zero)
54+
if rPtr {
55+
t.Errorf("PosInt64Ptr failed. Expected=false, actual=true")
56+
}
57+
}
58+
59+
func TestPosInt32(t *testing.T) {
60+
r := PosInt32(1)
61+
if !r {
62+
t.Errorf("PosInt32 failed. Expected=true, actual=false")
63+
t.Errorf(reflect.String.String())
64+
}
65+
66+
r = PosInt32(-1)
67+
if r {
68+
t.Errorf("PosInt32 failed. Expected=false, actual=true")
69+
}
70+
71+
var zero int32
72+
var one int32 = 1
73+
rPtr := PosInt32Ptr(&one)
74+
if !rPtr {
75+
t.Errorf("PosInt32Ptr failed. Expected=true, actual=false")
76+
}
77+
78+
rPtr = PosInt32Ptr(&zero)
79+
if rPtr {
80+
t.Errorf("PosInt32Ptr failed. Expected=false, actual=true")
81+
}
82+
}
83+
84+
func TestPosInt16(t *testing.T) {
85+
r := PosInt16(1)
86+
if !r {
87+
t.Errorf("PosInt16 failed. Expected=true, actual=false")
88+
t.Errorf(reflect.String.String())
89+
}
90+
91+
r = PosInt16(-1)
92+
if r {
93+
t.Errorf("PosInt16 failed. Expected=false, actual=true")
94+
}
95+
96+
var zero int16
97+
var one int16 = 1
98+
rPtr := PosInt16Ptr(&one)
99+
if !rPtr {
100+
t.Errorf("PosInt16Ptr failed. Expected=true, actual=false")
101+
}
102+
103+
rPtr = PosInt16Ptr(&zero)
104+
if rPtr {
105+
t.Errorf("PosInt16Ptr failed. Expected=false, actual=true")
106+
}
107+
}
108+
109+
func TestPosInt8(t *testing.T) {
110+
r := PosInt8(1)
111+
if !r {
112+
t.Errorf("PosInt8 failed. Expected=true, actual=false")
113+
t.Errorf(reflect.String.String())
114+
}
115+
116+
r = PosInt8(-1)
117+
if r {
118+
t.Errorf("PosInt8 failed. Expected=false, actual=true")
119+
}
120+
121+
var zero int8
122+
var one int8 = 1
123+
rPtr := PosInt8Ptr(&one)
124+
if !rPtr {
125+
t.Errorf("PosInt8Ptr failed. Expected=true, actual=false")
126+
}
127+
128+
rPtr = PosInt8Ptr(&zero)
129+
if rPtr {
130+
t.Errorf("PosInt8Ptr failed. Expected=false, actual=true")
131+
}
132+
}
133+
134+
func TestPosFloat32(t *testing.T) {
135+
r := PosFloat32(1)
136+
if !r {
137+
t.Errorf("PosFloat32 failed. Expected=true, actual=false")
138+
t.Errorf(reflect.String.String())
139+
}
140+
141+
r = PosFloat32(-1)
142+
if r {
143+
t.Errorf("PosFloat32 failed. Expected=false, actual=true")
144+
}
145+
146+
var zero float32
147+
var one float32 = 1
148+
rPtr := PosFloat32Ptr(&one)
149+
if !rPtr {
150+
t.Errorf("PosFloat32Ptr failed. Expected=true, actual=false")
151+
}
152+
153+
rPtr = PosFloat32Ptr(&zero)
154+
if rPtr {
155+
t.Errorf("PosFloat32Ptr failed. Expected=false, actual=true")
156+
}
157+
}
158+
159+
func TestPosFloat64(t *testing.T) {
160+
r := PosFloat64(1)
161+
if !r {
162+
t.Errorf("PosFloat64 failed. Expected=true, actual=false")
163+
t.Errorf(reflect.String.String())
164+
}
165+
166+
r = PosFloat64(-1)
167+
if r {
168+
t.Errorf("PosFloat64 failed. Expected=false, actual=true")
169+
}
170+
171+
var zero float64
172+
var one float64 = 1
173+
rPtr := PosFloat64Ptr(&one)
174+
if !rPtr {
175+
t.Errorf("PosFloat64Ptr failed. Expected=true, actual=false")
176+
}
177+
178+
rPtr = PosFloat64Ptr(&zero)
179+
if rPtr {
180+
t.Errorf("PosFloat64Ptr failed. Expected=false, actual=true")
181+
}
182+
}

0 commit comments

Comments
 (0)