Example #1
0
func (r *RecipeBook) GetByIngredient(ingredient string) []Recipe {
	desired_recipes := make([]Recipe, 0)
	for _, j := range r.recipes {
		sortutil.Asc(j.ingredients)
		if filterutils.StringInSortedSlice(j.ingredients, ingredient) {
			desired_recipes = append(desired_recipes, j)
		}
	}
	return desired_recipes
}
Example #2
0
func TestStringInSortedSlice(t *testing.T) {
	for _, test := range testStringInSortedSlice {
		sort.Strings(test.a)
		i := filterutils.StringInSortedSlice(test.a, test.x)
		if i != test.expected {
			// XXX Need to figure out the actual types for % to pass in for string formatting
			t.Errorf("Test '%s' has failed. Expected: %s, Actual %s", test.name, test.expected, i)
		}
	}
}