dict: add simple search method
This commit is contained in:
		
							
								
								
									
										9
									
								
								dictionary/dictionary.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								dictionary/dictionary.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					package dictionary
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Search(dictionary map[string]string, word string) string {
 | 
				
			||||||
 | 
						result, ok := dictionary[word]
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								dictionary/dictionary_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								dictionary/dictionary_test.go
									
									
									
									
									
										Normal file
									
								
							@ -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")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user