diff --git a/dictionary/dictionary.go b/dictionary/dictionary.go index 30ea5bb..b04ece0 100644 --- a/dictionary/dictionary.go +++ b/dictionary/dictionary.go @@ -13,3 +13,7 @@ func (d Dictionary) Search(word string) (string, error) { } return result, nil } + +func (d Dictionary) Add(word, definition string) { + d[word] = definition +} diff --git a/dictionary/dictionary_test.go b/dictionary/dictionary_test.go index 3ae8146..4e35081 100644 --- a/dictionary/dictionary_test.go +++ b/dictionary/dictionary_test.go @@ -1,6 +1,8 @@ package dictionary -import "testing" +import ( + "testing" +) func assertStrings(t testing.TB, got, want, given string) { t.Helper() @@ -36,3 +38,23 @@ func TestSearch(t *testing.T) { assertError(t, err, ErrNotFound) }) } + +func assertDefinition(t testing.TB, dict Dictionary, word, def string) { + t.Helper() + + got, err := dict.Search(word) + if err != nil { + t.Fatal("Should find added word:", err) + } + assertStrings(t, got, def, word) +} + +func TestAdd(t *testing.T) { + dict := Dictionary{} + + word := "test" + def := "this is just a test" + + dict.Add(word, def) + assertDefinition(t, dict, word, def) +}