From 73ab7dc92daa2c3d995912be7bb6a6503dd67a24 Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 11 Sep 2024 13:48:59 +0200 Subject: [PATCH] dict: add simple search method --- dictionary/dictionary.go | 9 +++++++++ dictionary/dictionary_test.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 dictionary/dictionary.go create mode 100644 dictionary/dictionary_test.go 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") + } +}