You've already forked utilities
feat: add initial implementation of Go utilities and CI workflows
This commit is contained in:
11
Maps/maps.go
Executable file
11
Maps/maps.go
Executable file
@@ -0,0 +1,11 @@
|
||||
package Maps
|
||||
|
||||
//goland:noinspection GoUnusedExportedFunction // library function
|
||||
func IsElementExist(s []string, str string) bool {
|
||||
for _, v := range s {
|
||||
if v == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
26
Maps/maps_test.go
Normal file
26
Maps/maps_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package Maps
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsElementExist(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s []string
|
||||
str string
|
||||
expected bool
|
||||
}{
|
||||
{"element exists", []string{"a", "b", "c"}, "b", true},
|
||||
{"element does not exist", []string{"a", "b", "c"}, "d", false},
|
||||
{"empty slice", []string{}, "a", false},
|
||||
{"multiple same elements", []string{"a", "b", "a"}, "a", true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsElementExist(tt.s, tt.str)
|
||||
if result != tt.expected {
|
||||
t.Errorf("IsElementExist(%v, %q) = %v; want %v", tt.s, tt.str, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user