Skip to content

Commit c4de908

Browse files
Sah, NandeshwarSah, Nandeshwar
authored andcommitted
Added function Odd<Type> to check if number is odd
1 parent 64f2e5a commit c4de908

File tree

8 files changed

+372
-22
lines changed

8 files changed

+372
-22
lines changed

fp/odd.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package fp
2+
3+
// OddInt Returns true if n is odd
4+
func OddInt(v int) bool {
5+
return v%2 != 0
6+
}
7+
8+
// OddIntPtr Returns true if n is odd
9+
func OddIntPtr(v *int) bool {
10+
return *v%2 != 0
11+
}
12+
13+
// OddInt64 Returns true if n is odd
14+
func OddInt64(v int64) bool {
15+
return v%2 != 0
16+
}
17+
18+
// OddInt64Ptr Returns true if n is odd
19+
func OddInt64Ptr(v *int64) bool {
20+
return *v%2 != 0
21+
}
22+
23+
// OddInt32 Returns true if n is odd
24+
func OddInt32(v int32) bool {
25+
return v%2 != 0
26+
}
27+
28+
// OddInt32Ptr Returns true if n is odd
29+
func OddInt32Ptr(v *int32) bool {
30+
return *v%2 != 0
31+
}
32+
33+
// OddInt16 Returns true if n is odd
34+
func OddInt16(v int16) bool {
35+
return v%2 != 0
36+
}
37+
38+
// OddInt16Ptr Returns true if n is odd
39+
func OddInt16Ptr(v *int16) bool {
40+
return *v%2 != 0
41+
}
42+
43+
// OddInt8 Returns true if n is odd
44+
func OddInt8(v int8) bool {
45+
return v%2 != 0
46+
}
47+
48+
// OddInt8Ptr Returns true if n is odd
49+
func OddInt8Ptr(v *int8) bool {
50+
return *v%2 != 0
51+
}
52+
53+
// OddUint Returns true if n is odd
54+
func OddUint(v uint) bool {
55+
return v%2 != 0
56+
}
57+
58+
// OddUintPtr Returns true if n is odd
59+
func OddUintPtr(v *uint) bool {
60+
return *v%2 != 0
61+
}
62+
63+
// OddUint64 Returns true if n is odd
64+
func OddUint64(v uint64) bool {
65+
return v%2 != 0
66+
}
67+
68+
// OddUint64Ptr Returns true if n is odd
69+
func OddUint64Ptr(v *uint64) bool {
70+
return *v%2 != 0
71+
}
72+
73+
// OddUint32 Returns true if n is odd
74+
func OddUint32(v uint32) bool {
75+
return v%2 != 0
76+
}
77+
78+
// OddUint32Ptr Returns true if n is odd
79+
func OddUint32Ptr(v *uint32) bool {
80+
return *v%2 != 0
81+
}
82+
83+
// OddUint16 Returns true if n is odd
84+
func OddUint16(v uint16) bool {
85+
return v%2 != 0
86+
}
87+
88+
// OddUint16Ptr Returns true if n is odd
89+
func OddUint16Ptr(v *uint16) bool {
90+
return *v%2 != 0
91+
}
92+
93+
// OddUint8 Returns true if n is odd
94+
func OddUint8(v uint8) bool {
95+
return v%2 != 0
96+
}
97+
98+
// OddUint8Ptr Returns true if n is odd
99+
func OddUint8Ptr(v *uint8) bool {
100+
return *v%2 != 0
101+
}

fp/odd_test.go

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package fp
2+
3+
import (
4+
_ "errors"
5+
"reflect"
6+
"testing"
7+
)
8+
9+
func TestOddInt(t *testing.T) {
10+
r := OddInt(11)
11+
if !r {
12+
t.Errorf("OddInt failed. Expected=true, actual=false")
13+
t.Errorf(reflect.String.String())
14+
}
15+
16+
r = OddInt(2)
17+
if r {
18+
t.Errorf("OddInt failed. Expected=false, actual=true")
19+
}
20+
21+
var three int = 3
22+
rPtr := OddIntPtr(&three)
23+
if !rPtr {
24+
t.Errorf("OddIntPtr failed. Expected=true, actual=false")
25+
}
26+
}
27+
28+
func TestOddInt64(t *testing.T) {
29+
r := OddInt64(11)
30+
if !r {
31+
t.Errorf("OddInt64 failed. Expected=true, actual=false")
32+
t.Errorf(reflect.String.String())
33+
}
34+
35+
r = OddInt64(2)
36+
if r {
37+
t.Errorf("OddInt64 failed. Expected=false, actual=true")
38+
}
39+
40+
var three int64 = 3
41+
rPtr := OddInt64Ptr(&three)
42+
if !rPtr {
43+
t.Errorf("OddInt64Ptr failed. Expected=true, actual=false")
44+
}
45+
}
46+
47+
func TestOddInt32(t *testing.T) {
48+
r := OddInt32(11)
49+
if !r {
50+
t.Errorf("OddInt32 failed. Expected=true, actual=false")
51+
t.Errorf(reflect.String.String())
52+
}
53+
54+
r = OddInt32(2)
55+
if r {
56+
t.Errorf("OddInt32 failed. Expected=false, actual=true")
57+
}
58+
59+
var three int32 = 3
60+
rPtr := OddInt32Ptr(&three)
61+
if !rPtr {
62+
t.Errorf("OddInt32Ptr failed. Expected=true, actual=false")
63+
}
64+
}
65+
66+
func TestOddInt16(t *testing.T) {
67+
r := OddInt16(11)
68+
if !r {
69+
t.Errorf("OddInt16 failed. Expected=true, actual=false")
70+
t.Errorf(reflect.String.String())
71+
}
72+
73+
r = OddInt16(2)
74+
if r {
75+
t.Errorf("OddInt16 failed. Expected=false, actual=true")
76+
}
77+
78+
var three int16 = 3
79+
rPtr := OddInt16Ptr(&three)
80+
if !rPtr {
81+
t.Errorf("OddInt16Ptr failed. Expected=true, actual=false")
82+
}
83+
}
84+
85+
func TestOddInt8(t *testing.T) {
86+
r := OddInt8(11)
87+
if !r {
88+
t.Errorf("OddInt8 failed. Expected=true, actual=false")
89+
t.Errorf(reflect.String.String())
90+
}
91+
92+
r = OddInt8(2)
93+
if r {
94+
t.Errorf("OddInt8 failed. Expected=false, actual=true")
95+
}
96+
97+
var three int8 = 3
98+
rPtr := OddInt8Ptr(&three)
99+
if !rPtr {
100+
t.Errorf("OddInt8Ptr failed. Expected=true, actual=false")
101+
}
102+
}
103+
104+
func TestOddUint(t *testing.T) {
105+
r := OddUint(11)
106+
if !r {
107+
t.Errorf("OddUint failed. Expected=true, actual=false")
108+
t.Errorf(reflect.String.String())
109+
}
110+
111+
r = OddUint(2)
112+
if r {
113+
t.Errorf("OddUint failed. Expected=false, actual=true")
114+
}
115+
116+
var three uint = 3
117+
rPtr := OddUintPtr(&three)
118+
if !rPtr {
119+
t.Errorf("OddUintPtr failed. Expected=true, actual=false")
120+
}
121+
}
122+
123+
func TestOddUint64(t *testing.T) {
124+
r := OddUint64(11)
125+
if !r {
126+
t.Errorf("OddUint64 failed. Expected=true, actual=false")
127+
t.Errorf(reflect.String.String())
128+
}
129+
130+
r = OddUint64(2)
131+
if r {
132+
t.Errorf("OddUint64 failed. Expected=false, actual=true")
133+
}
134+
135+
var three uint64 = 3
136+
rPtr := OddUint64Ptr(&three)
137+
if !rPtr {
138+
t.Errorf("OddUint64Ptr failed. Expected=true, actual=false")
139+
}
140+
}
141+
142+
func TestOddUint32(t *testing.T) {
143+
r := OddUint32(11)
144+
if !r {
145+
t.Errorf("OddUint32 failed. Expected=true, actual=false")
146+
t.Errorf(reflect.String.String())
147+
}
148+
149+
r = OddUint32(2)
150+
if r {
151+
t.Errorf("OddUint32 failed. Expected=false, actual=true")
152+
}
153+
154+
var three uint32 = 3
155+
rPtr := OddUint32Ptr(&three)
156+
if !rPtr {
157+
t.Errorf("OddUint32Ptr failed. Expected=true, actual=false")
158+
}
159+
}
160+
161+
func TestOddUint16(t *testing.T) {
162+
r := OddUint16(11)
163+
if !r {
164+
t.Errorf("OddUint16 failed. Expected=true, actual=false")
165+
t.Errorf(reflect.String.String())
166+
}
167+
168+
r = OddUint16(2)
169+
if r {
170+
t.Errorf("OddUint16 failed. Expected=false, actual=true")
171+
}
172+
173+
var three uint16 = 3
174+
rPtr := OddUint16Ptr(&three)
175+
if !rPtr {
176+
t.Errorf("OddUint16Ptr failed. Expected=true, actual=false")
177+
}
178+
}
179+
180+
func TestOddUint8(t *testing.T) {
181+
r := OddUint8(11)
182+
if !r {
183+
t.Errorf("OddUint8 failed. Expected=true, actual=false")
184+
t.Errorf(reflect.String.String())
185+
}
186+
187+
r = OddUint8(2)
188+
if r {
189+
t.Errorf("OddUint8 failed. Expected=false, actual=true")
190+
}
191+
192+
var three uint8 = 3
193+
rPtr := OddUint8Ptr(&three)
194+
if !rPtr {
195+
t.Errorf("OddUint8Ptr failed. Expected=true, actual=false")
196+
}
197+
}

internal/employee/fp.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)