dict: create a type
This commit is contained in:
		@ -1,7 +1,9 @@
 | 
				
			|||||||
package dictionary
 | 
					package dictionary
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Search(dictionary map[string]string, word string) string {
 | 
					type Dictionary map[string]string
 | 
				
			||||||
	result, ok := dictionary[word]
 | 
					
 | 
				
			||||||
 | 
					func (d Dictionary) Search(word string) string {
 | 
				
			||||||
 | 
						result, ok := d[word]
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return ""
 | 
							return ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -11,9 +11,9 @@ func assertStrings(t testing.TB, got, want string) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestSearch(t *testing.T) {
 | 
					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"
 | 
						want := "this is just a test"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assertStrings(t, got, want)
 | 
					    assertStrings(t, got, want)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user