Skip to content

Commit c7444a6

Browse files
Merge pull request #123 from logic-building/Equal<Type>sP
Added function Equal<Type>sP to check of list are equal or not
2 parents f5c3f8f + 952e21a commit c7444a6

File tree

9 files changed

+1699
-39
lines changed

9 files changed

+1699
-39
lines changed

fp/equal.go

Lines changed: 477 additions & 0 deletions
Large diffs are not rendered by default.

fp/equal_test.go

Lines changed: 972 additions & 0 deletions
Large diffs are not rendered by default.

fp/exists.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package fp
22

33
import "strings"
44

5-
// ExistsInt checkss if given item exists in the list
5+
// ExistsInt checks if given item exists in the list
66
//
77
// Example:
88
// ExistsInt(8, []int{8, 2, 10, 4}) // Returns true

fp/someerr_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestSomeIntErr(t *testing.T) {
4141
t.Errorf("SomeIntErr failed. Expected=false, actual=true")
4242
}
4343

44-
r, _=SomeIntErr(isEvenIntErr, []int{})
44+
r, _ = SomeIntErr(isEvenIntErr, []int{})
4545
if r {
4646
t.Errorf("SomeIntPtr failed. Expected=false, actual=true")
4747
}
@@ -83,7 +83,7 @@ func TestSomeInt64Err(t *testing.T) {
8383
t.Errorf("SomeInt64Err failed. Expected=false, actual=true")
8484
}
8585

86-
r, _=SomeInt64Err(isEvenInt64Err, []int64{})
86+
r, _ = SomeInt64Err(isEvenInt64Err, []int64{})
8787
if r {
8888
t.Errorf("SomeInt64Ptr failed. Expected=false, actual=true")
8989
}
@@ -125,7 +125,7 @@ func TestSomeInt32Err(t *testing.T) {
125125
t.Errorf("SomeInt32Err failed. Expected=false, actual=true")
126126
}
127127

128-
r, _=SomeInt32Err(isEvenInt32Err, []int32{})
128+
r, _ = SomeInt32Err(isEvenInt32Err, []int32{})
129129
if r {
130130
t.Errorf("SomeInt32Ptr failed. Expected=false, actual=true")
131131
}
@@ -167,7 +167,7 @@ func TestSomeInt16Err(t *testing.T) {
167167
t.Errorf("SomeInt16Err failed. Expected=false, actual=true")
168168
}
169169

170-
r, _=SomeInt16Err(isEvenInt16Err, []int16{})
170+
r, _ = SomeInt16Err(isEvenInt16Err, []int16{})
171171
if r {
172172
t.Errorf("SomeInt16Ptr failed. Expected=false, actual=true")
173173
}
@@ -209,7 +209,7 @@ func TestSomeInt8Err(t *testing.T) {
209209
t.Errorf("SomeInt8Err failed. Expected=false, actual=true")
210210
}
211211

212-
r, _=SomeInt8Err(isEvenInt8Err, []int8{})
212+
r, _ = SomeInt8Err(isEvenInt8Err, []int8{})
213213
if r {
214214
t.Errorf("SomeInt8Ptr failed. Expected=false, actual=true")
215215
}
@@ -251,7 +251,7 @@ func TestSomeUintErr(t *testing.T) {
251251
t.Errorf("SomeUintErr failed. Expected=false, actual=true")
252252
}
253253

254-
r, _=SomeUintErr(isEvenUintErr, []uint{})
254+
r, _ = SomeUintErr(isEvenUintErr, []uint{})
255255
if r {
256256
t.Errorf("SomeUintPtr failed. Expected=false, actual=true")
257257
}
@@ -293,7 +293,7 @@ func TestSomeUint64Err(t *testing.T) {
293293
t.Errorf("SomeUint64Err failed. Expected=false, actual=true")
294294
}
295295

296-
r, _=SomeUint64Err(isEvenUint64Err, []uint64{})
296+
r, _ = SomeUint64Err(isEvenUint64Err, []uint64{})
297297
if r {
298298
t.Errorf("SomeUint64Ptr failed. Expected=false, actual=true")
299299
}
@@ -335,7 +335,7 @@ func TestSomeUint32Err(t *testing.T) {
335335
t.Errorf("SomeUint32Err failed. Expected=false, actual=true")
336336
}
337337

338-
r, _=SomeUint32Err(isEvenUint32Err, []uint32{})
338+
r, _ = SomeUint32Err(isEvenUint32Err, []uint32{})
339339
if r {
340340
t.Errorf("SomeUint32Ptr failed. Expected=false, actual=true")
341341
}
@@ -377,7 +377,7 @@ func TestSomeUint16Err(t *testing.T) {
377377
t.Errorf("SomeUint16Err failed. Expected=false, actual=true")
378378
}
379379

380-
r, _=SomeUint16Err(isEvenUint16Err, []uint16{})
380+
r, _ = SomeUint16Err(isEvenUint16Err, []uint16{})
381381
if r {
382382
t.Errorf("SomeUint16Ptr failed. Expected=false, actual=true")
383383
}
@@ -419,7 +419,7 @@ func TestSomeUint8Err(t *testing.T) {
419419
t.Errorf("SomeUint8Err failed. Expected=false, actual=true")
420420
}
421421

422-
r, _=SomeUint8Err(isEvenUint8Err, []uint8{})
422+
r, _ = SomeUint8Err(isEvenUint8Err, []uint8{})
423423
if r {
424424
t.Errorf("SomeUint8Ptr failed. Expected=false, actual=true")
425425
}
@@ -461,7 +461,7 @@ func TestSomeStrErr(t *testing.T) {
461461
t.Errorf("SomeStrErr failed. Expected=false, actual=true")
462462
}
463463

464-
r, _=SomeStrErr(isEvenStrErr, []string{})
464+
r, _ = SomeStrErr(isEvenStrErr, []string{})
465465
if r {
466466
t.Errorf("SomeStrPtr failed. Expected=false, actual=true")
467467
}
@@ -532,7 +532,7 @@ func TestSomeFloat32Err(t *testing.T) {
532532
t.Errorf("SomeFloat32Err failed. Expected=false, actual=true")
533533
}
534534

535-
r, _=SomeFloat32Err(isEvenFloat32Err, []float32{})
535+
r, _ = SomeFloat32Err(isEvenFloat32Err, []float32{})
536536
if r {
537537
t.Errorf("SomeFloat32Ptr failed. Expected=false, actual=true")
538538
}
@@ -574,7 +574,7 @@ func TestSomeFloat64Err(t *testing.T) {
574574
t.Errorf("SomeFloat64Err failed. Expected=false, actual=true")
575575
}
576576

577-
r, _=SomeFloat64Err(isEvenFloat64Err, []float64{})
577+
r, _ = SomeFloat64Err(isEvenFloat64Err, []float64{})
578578
if r {
579579
t.Errorf("SomeFloat64Ptr failed. Expected=false, actual=true")
580580
}

fp/someptrerr_test.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestSomeIntPtrErr(t *testing.T) {
4141
t.Errorf("SomeIntPtrErr failed. Expected=false, actual=true")
4242
}
4343

44-
r, _=SomeIntPtrErr(isEvenIntPtrErr, []*int{})
44+
r, _ = SomeIntPtrErr(isEvenIntPtrErr, []*int{})
4545
if r {
4646
t.Errorf("SomeIntPtr failed. Expected=false, actual=true")
4747
}
@@ -83,7 +83,7 @@ func TestSomeInt64PtrErr(t *testing.T) {
8383
t.Errorf("SomeInt64PtrErr failed. Expected=false, actual=true")
8484
}
8585

86-
r, _=SomeInt64PtrErr(isEvenInt64PtrErr, []*int64{})
86+
r, _ = SomeInt64PtrErr(isEvenInt64PtrErr, []*int64{})
8787
if r {
8888
t.Errorf("SomeInt64Ptr failed. Expected=false, actual=true")
8989
}
@@ -125,7 +125,7 @@ func TestSomeInt32PtrErr(t *testing.T) {
125125
t.Errorf("SomeInt32PtrErr failed. Expected=false, actual=true")
126126
}
127127

128-
r, _=SomeInt32PtrErr(isEvenInt32PtrErr, []*int32{})
128+
r, _ = SomeInt32PtrErr(isEvenInt32PtrErr, []*int32{})
129129
if r {
130130
t.Errorf("SomeInt32Ptr failed. Expected=false, actual=true")
131131
}
@@ -167,7 +167,7 @@ func TestSomeInt16PtrErr(t *testing.T) {
167167
t.Errorf("SomeInt16PtrErr failed. Expected=false, actual=true")
168168
}
169169

170-
r, _=SomeInt16PtrErr(isEvenInt16PtrErr, []*int16{})
170+
r, _ = SomeInt16PtrErr(isEvenInt16PtrErr, []*int16{})
171171
if r {
172172
t.Errorf("SomeInt16Ptr failed. Expected=false, actual=true")
173173
}
@@ -209,7 +209,7 @@ func TestSomeInt8PtrErr(t *testing.T) {
209209
t.Errorf("SomeInt8PtrErr failed. Expected=false, actual=true")
210210
}
211211

212-
r, _=SomeInt8PtrErr(isEvenInt8PtrErr, []*int8{})
212+
r, _ = SomeInt8PtrErr(isEvenInt8PtrErr, []*int8{})
213213
if r {
214214
t.Errorf("SomeInt8Ptr failed. Expected=false, actual=true")
215215
}
@@ -251,7 +251,7 @@ func TestSomeUintPtrErr(t *testing.T) {
251251
t.Errorf("SomeUintPtrErr failed. Expected=false, actual=true")
252252
}
253253

254-
r, _=SomeUintPtrErr(isEvenUintPtrErr, []*uint{})
254+
r, _ = SomeUintPtrErr(isEvenUintPtrErr, []*uint{})
255255
if r {
256256
t.Errorf("SomeUintPtr failed. Expected=false, actual=true")
257257
}
@@ -293,7 +293,7 @@ func TestSomeUint64PtrErr(t *testing.T) {
293293
t.Errorf("SomeUint64PtrErr failed. Expected=false, actual=true")
294294
}
295295

296-
r, _=SomeUint64PtrErr(isEvenUint64PtrErr, []*uint64{})
296+
r, _ = SomeUint64PtrErr(isEvenUint64PtrErr, []*uint64{})
297297
if r {
298298
t.Errorf("SomeUint64Ptr failed. Expected=false, actual=true")
299299
}
@@ -335,7 +335,7 @@ func TestSomeUint32PtrErr(t *testing.T) {
335335
t.Errorf("SomeUint32PtrErr failed. Expected=false, actual=true")
336336
}
337337

338-
r, _=SomeUint32PtrErr(isEvenUint32PtrErr, []*uint32{})
338+
r, _ = SomeUint32PtrErr(isEvenUint32PtrErr, []*uint32{})
339339
if r {
340340
t.Errorf("SomeUint32Ptr failed. Expected=false, actual=true")
341341
}
@@ -377,7 +377,7 @@ func TestSomeUint16PtrErr(t *testing.T) {
377377
t.Errorf("SomeUint16PtrErr failed. Expected=false, actual=true")
378378
}
379379

380-
r, _=SomeUint16PtrErr(isEvenUint16PtrErr, []*uint16{})
380+
r, _ = SomeUint16PtrErr(isEvenUint16PtrErr, []*uint16{})
381381
if r {
382382
t.Errorf("SomeUint16Ptr failed. Expected=false, actual=true")
383383
}
@@ -419,7 +419,7 @@ func TestSomeUint8PtrErr(t *testing.T) {
419419
t.Errorf("SomeUint8PtrErr failed. Expected=false, actual=true")
420420
}
421421

422-
r, _=SomeUint8PtrErr(isEvenUint8PtrErr, []*uint8{})
422+
r, _ = SomeUint8PtrErr(isEvenUint8PtrErr, []*uint8{})
423423
if r {
424424
t.Errorf("SomeUint8Ptr failed. Expected=false, actual=true")
425425
}
@@ -461,7 +461,7 @@ func TestSomeStrPtrErr(t *testing.T) {
461461
t.Errorf("SomeStrPtrErr failed. Expected=false, actual=true")
462462
}
463463

464-
r, _=SomeStrPtrErr(isEvenStrPtrErr, []*string{})
464+
r, _ = SomeStrPtrErr(isEvenStrPtrErr, []*string{})
465465
if r {
466466
t.Errorf("SomeStrPtr failed. Expected=false, actual=true")
467467
}
@@ -480,18 +480,24 @@ func TestSomeBoolPtrErr(t *testing.T) {
480480
}
481481

482482
r, _ = SomeBoolPtrErr(nil, nil)
483-
484-
if r{
483+
484+
if r {
485485
t.Errorf("SomeBoolPtr failed. Expected=false, actual=true")
486486
}
487487

488488
r, _ = SomeBoolPtrErr(func(v *bool) (bool, error) { return *v == true, nil }, []*bool{})
489-
if r {
489+
if r {
490490
t.Errorf("SomeBoolPtrErr failed. Expected=false, actual=true")
491491
}
492492

493-
_, err := SomeBoolPtrErr(func(v *bool) (bool, error) { if *v == false { return false, errors.New("false is invalid in this test") }; return *v == true, nil }, []*bool{&vf})
494-
if err == nil {
493+
_, err := SomeBoolPtrErr(func(v *bool) (bool, error) {
494+
if *v == false {
495+
return false, errors.New("false is invalid in this test")
496+
}
497+
return *v == true, nil
498+
}, []*bool{&vf})
499+
500+
if err == nil {
495501
t.Errorf("SomeBoolPtrErr failed. Expected=false, actual=true")
496502
}
497503
}
@@ -532,7 +538,7 @@ func TestSomeFloat32PtrErr(t *testing.T) {
532538
t.Errorf("SomeFloat32PtrErr failed. Expected=false, actual=true")
533539
}
534540

535-
r, _=SomeFloat32PtrErr(isEvenFloat32PtrErr, []*float32{})
541+
r, _ = SomeFloat32PtrErr(isEvenFloat32PtrErr, []*float32{})
536542
if r {
537543
t.Errorf("SomeFloat32Ptr failed. Expected=false, actual=true")
538544
}
@@ -574,7 +580,7 @@ func TestSomeFloat64PtrErr(t *testing.T) {
574580
t.Errorf("SomeFloat64PtrErr failed. Expected=false, actual=true")
575581
}
576582

577-
r, _=SomeFloat64PtrErr(isEvenFloat64PtrErr, []*float64{})
583+
r, _ = SomeFloat64PtrErr(isEvenFloat64PtrErr, []*float64{})
578584
if r {
579585
t.Errorf("SomeFloat64Ptr failed. Expected=false, actual=true")
580586
}

internal/generatefp.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ var fpCodeList = []fpCode{
128128
generatedTestFileName: "superset_test.go",
129129
},
130130

131+
fpCode{
132+
function: "Equal",
133+
codeTemplate: basic.Equal(),
134+
dataTypes: []string{"int", "int64", "int32", "int16", "int8", "uint", "uint64", "uint32", "uint16", "uint8", "string", "bool", "float32", "float64"},
135+
generatedFileName: "equal.go",
136+
137+
testTemplate: basic.EqualTest(),
138+
testTemplateBool: basic.EqualBoolTest(),
139+
generatedTestFileName: "equal_test.go",
140+
},
141+
131142
fpCode{
132143
function: "Zero",
133144
codeTemplate: basic.ZeroP(),

internal/template/basic/equal.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package basic
2+
3+
// Equal is template to generate itself for different combination of data type.
4+
func Equal() string {
5+
return `
6+
// Equal<FTYPE>sP Returns true if both list are equal else returns false
7+
func Equal<FTYPE>sP(list1, list2 []<TYPE>) bool {
8+
len1 := len(list1)
9+
len2 := len(list2)
10+
11+
if len1 == 0 || len2 == 0 || len1 != len2 {
12+
return false
13+
}
14+
15+
for i := 0; i < len1; i++ {
16+
if list1[i] != list2[i] {
17+
return false
18+
}
19+
}
20+
return true
21+
}
22+
23+
// Equal<FTYPE>sPPtr Returns true if both list are equal else returns false
24+
func Equal<FTYPE>sPPtr(list1, list2 []*<TYPE>) bool {
25+
len1 := len(list1)
26+
len2 := len(list2)
27+
28+
if len1 == 0 || len2 == 0 || len1 != len2 {
29+
return false
30+
}
31+
32+
for i := 0; i < len1; i++ {
33+
if *list1[i] != *list2[i] {
34+
return false
35+
}
36+
}
37+
return true
38+
}
39+
`
40+
}

0 commit comments

Comments
 (0)