github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/internal/utils/helpers_test.go (about) 1 package utils 2 3 import "testing" 4 5 func TestArrayContains(t *testing.T) { 6 // test string array 7 arr := []string{"a", "b", "c"} 8 9 mustBeFounded := "a" 10 expectedValue := true 11 actualValue := ArrayContains(&arr, mustBeFounded) 12 if actualValue != expectedValue { 13 t.Errorf("Find the %v in %v: Expected %v, but got %v", 14 mustBeFounded, arr, expectedValue, actualValue) 15 } 16 } 17 18 func TestArrayContainsInt(t *testing.T) { 19 arr := []int{1, 2, 3} 20 21 mustBeFounded := 2 22 expectedValue := true 23 actualValue := ArrayContains(&arr, mustBeFounded) 24 if actualValue != expectedValue { 25 t.Errorf("Find the %v in %v: Expected %v, but got %v", 26 mustBeFounded, arr, expectedValue, actualValue) 27 } 28 29 } 30 31 func TestArrayContainsWithPtr(t *testing.T) { 32 arr := &[]int{1, 2, 3} 33 34 mustBeFounded := 2 35 expectedValue := true 36 actualValue := ArrayContains(arr, mustBeFounded) 37 if actualValue != expectedValue { 38 t.Errorf("Find the %v in %v: Expected %v, but got %v", 39 mustBeFounded, arr, expectedValue, actualValue) 40 } 41 42 } 43 44 func TestArrayContainsDifferentTypes(t *testing.T) { 45 TestArrayContains(t) 46 TestArrayContainsInt(t) 47 TestArrayContainsWithPtr(t) 48 }