diff --git a/dictionary/dictionary.go b/dictionary/dictionary.go new file mode 100644 index 0000000..d0ce6f6 --- /dev/null +++ b/dictionary/dictionary.go @@ -0,0 +1,9 @@ +package dictionary + +func Search(dictionary map[string]string, word string) string { + result, ok := dictionary[word] + if !ok { + return "" + } + return result +} diff --git a/dictionary/dictionary_test.go b/dictionary/dictionary_test.go new file mode 100644 index 0000000..737bbd9 --- /dev/null +++ b/dictionary/dictionary_test.go @@ -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") + } +}