dict: create a type
This commit is contained in:
		@ -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 ""
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user