Skip to content

Commit

Permalink
arraylist util functions and testing added.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron committed Jul 29, 2022
1 parent eb51b6d commit 2978667
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c
github.com/devfile/library v1.2.1-0.20220308191614-f0f7e11b17de
github.com/devfile/registry-support/index/generator v0.0.0-20220624203950-e7282a4695b6
github.com/emirpasic/gods v1.12.0
github.com/gin-gonic/gin v1.7.7
github.com/hashicorp/go-version v1.4.0
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
Expand All @@ -27,7 +28,6 @@ require (
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
Expand Down
2 changes: 0 additions & 2 deletions index/server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c h1:sjghKUov/WT71dBr
github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/library v1.2.1-0.20220308191614-f0f7e11b17de h1:jImHtiAxjyul1UkPmf6C3EMS5wqNz+k84LKkCXkeqws=
github.com/devfile/library v1.2.1-0.20220308191614-f0f7e11b17de/go.mod h1:GSPfJaBg0+bBjBHbwBE5aerJLH6tWGQu2q2rHYd9czM=
github.com/devfile/registry-support/index/generator v0.0.0-20220316161530-f06d84c42b54 h1:k7F4Hc4svkA+qHerBTZzcU1iVrQAJHOh8KurPnL4uYk=
github.com/devfile/registry-support/index/generator v0.0.0-20220316161530-f06d84c42b54/go.mod h1:1fyDJL+fPHtcrYA6yjSVWeLmXmjCNth0d5Rq1rvtryc=
github.com/devfile/registry-support/index/generator v0.0.0-20220624203950-e7282a4695b6 h1:bTbZxKSjF9xfiUuOKpoyX7P/ZcnIRy993+JBvkQ91hw=
github.com/devfile/registry-support/index/generator v0.0.0-20220624203950-e7282a4695b6/go.mod h1:1fyDJL+fPHtcrYA6yjSVWeLmXmjCNth0d5Rq1rvtryc=
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down
80 changes: 80 additions & 0 deletions index/server/pkg/util/arraylist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package util

import "github.com/emirpasic/gods/lists/arraylist"

// ConvertStringArrayToArrayList converts string array to interface arraylist
func ConvertStringArrayToArrayList(sArray []string) *arraylist.List {
arrayList := arraylist.New()

for _, s := range sArray {
arrayList.Add(s)
}

return arrayList
}

// ConvertBoolArrayToArrayList converts bool array to interface arraylist
func ConvertBoolArrayToArrayList(bArray []bool) *arraylist.List {
arrayList := arraylist.New()

for _, b := range bArray {
arrayList.Add(b)
}

return arrayList
}

// ConvertIntArrayToArrayList converts int array to interface arraylist
func ConvertIntArrayToArrayList(iArray []int) *arraylist.List {
arrayList := arraylist.New()

for _, i := range iArray {
arrayList.Add(i)
}

return arrayList
}

// ConvertShortArrayToArrayList converts int16 array to interface arraylist
func ConvertShortArrayToArrayList(iArray []int16) *arraylist.List {
arrayList := arraylist.New()

for _, i := range iArray {
arrayList.Add(i)
}

return arrayList
}

// ConvertLongArrayToArrayList converts int64 array to interface arraylist
func ConvertLongArrayToArrayList(iArray []int64) *arraylist.List {
arrayList := arraylist.New()

for _, i := range iArray {
arrayList.Add(i)
}

return arrayList
}

// ConvertFloatArrayToArrayList converts float32 array to interface arraylist
func ConvertFloatArrayToArrayList(fArray []float32) *arraylist.List {
arrayList := arraylist.New()

for _, f := range fArray {
arrayList.Add(f)
}

return arrayList
}

// ConvertDoubleArrayToArrayList converts float64 array to interface arraylist
func ConvertDoubleArrayToArrayList(fArray []float64) *arraylist.List {
arrayList := arraylist.New()

for _, f := range fArray {
arrayList.Add(f)
}

return arrayList
}
204 changes: 204 additions & 0 deletions index/server/pkg/util/arraylist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package util

import (
"reflect"
"testing"

"github.com/emirpasic/gods/lists/arraylist"
)

func TestConvertStringArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []string
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []string{"abc"},
wantResult: arraylist.New("abc"),
},
{
name: "Test Array with multiple values",
array: []string{"abc", "ab", "test"},
wantResult: arraylist.New("abc", "ab", "test"),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertStringArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertBoolArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []bool
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []bool{true},
wantResult: arraylist.New(true),
},
{
name: "Test Array with multiple values",
array: []bool{true, false, true},
wantResult: arraylist.New(true, false, true),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertBoolArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertIntArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []int
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []int{0},
wantResult: arraylist.New(0),
},
{
name: "Test Array with multiple values",
array: []int{0, 1, 2},
wantResult: arraylist.New(0, 1, 2),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertIntArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertShortArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []int16
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []int16{0},
wantResult: arraylist.New(int16(0)),
},
{
name: "Test Array with multiple values",
array: []int16{0, 1, 2},
wantResult: arraylist.New(int16(0), int16(1), int16(2)),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertShortArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertLongArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []int64
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []int64{0},
wantResult: arraylist.New(int64(0)),
},
{
name: "Test Array with multiple values",
array: []int64{0, 1, 2},
wantResult: arraylist.New(int64(0), int64(1), int64(2)),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertLongArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertFloatArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []float32
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []float32{0.23},
wantResult: arraylist.New(float32(0.23)),
},
{
name: "Test Array with multiple values",
array: []float32{0.23, 1.1, 2.2},
wantResult: arraylist.New(float32(0.23), float32(1.1), float32(2.2)),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertFloatArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

func TestConvertDoubleArrayToArrayList(t *testing.T) {
tests := []struct {
name string
array []float64
wantResult *arraylist.List
}{
{
name: "Test singleton array",
array: []float64{0.23},
wantResult: arraylist.New(0.23),
},
{
name: "Test Array with multiple values",
array: []float64{0.23, 1.1, 2.2},
wantResult: arraylist.New(0.23, 1.1, 2.2),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
gotResult := ConvertDoubleArrayToArrayList(test.array)
if !reflect.DeepEqual(gotResult, test.wantResult) {
t.Fatalf("Expected: %v, Got: %v\n", *test.wantResult, *gotResult)
}
})
}
}

0 comments on commit 2978667

Please sign in to comment.