dict: create a type

This commit is contained in:
vinchent 2024-09-11 15:22:42 +02:00
parent dd61fb557b
commit baff9ee722
2 changed files with 6 additions and 4 deletions

View File

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

View File

@ -11,9 +11,9 @@ func assertStrings(t testing.TB, got, want string) {
}
func TestSearch(t *testing.T) {
dictionary := map[string]string{"test": "this is just a test"}
dictionary := Dictionary{"test": "this is just a test"}
got := Search(dictionary, "test")
got := dictionary.Search("test")
want := "this is just a test"
assertStrings(t, got, want)