dict: add simple search method

This commit is contained in:
vinchent 2024-09-11 13:48:59 +02:00
parent 4a497b9f93
commit 73ab7dc92d
2 changed files with 23 additions and 0 deletions

9
dictionary/dictionary.go Normal file
View File

@ -0,0 +1,9 @@
package dictionary
func Search(dictionary map[string]string, word string) string {
result, ok := dictionary[word]
if !ok {
return ""
}
return result
}

View File

@ -0,0 +1,14 @@
package dictionary
import "testing"
func TestSearch(t *testing.T) {
dictionary := map[string]string{"test": "this is just a test"}
got := Search(dictionary, "test")
want := "this is just a test"
if got != want {
t.Errorf("got %q want %q given %q", got, want, "test")
}
}