-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
69 lines (59 loc) · 1.9 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"recipes.com/config"
"recipes.com/dtos"
_ "recipes.com/indexer"
"reflect"
"testing"
)
func TestFetchResult(t *testing.T) {
recipes := getDummyRecipe()
config.SEARCH_STR = "Dosa,Ghee"
config.POSTCODE = "10137"
config.TIME_RANGE = "5AM-1PM"
result := newcookbook(recipes).c.FetchResult()
if result.UniqueRecipeCount != 4 {
t.Errorf("Unique Recipe Count got %d, want %d", result.UniqueRecipeCount, 4)
}
for _, r := range result.CountPerRecipe {
if r.Recipe == "Ghee Dosa" && r.Count != 2 {
t.Errorf("Count per recipe for %s got %d, want %d", r.Recipe, r.Count, 2)
}
}
if result.BusiestPostCode.Postcode != "10137" {
t.Errorf("Busiest Postcode got %s, want %s", result.BusiestPostCode.Postcode, "10137")
}
if result.BusiestPostCode.DeliveryCount != 4 {
t.Errorf("Busiest Postcode count got %d, want %d", result.BusiestPostCode.DeliveryCount, 4)
}
if result.CountPerPostCodeAndTime.DeliveryCount != 3 {
t.Errorf("Count per postcode %s between %s got %d, want %d", config.POSTCODE, config.TIME_RANGE, result.CountPerPostCodeAndTime.DeliveryCount, 3)
}
if !reflect.DeepEqual(result.MatchByName, []string{"Ghee Dosa", "Masala Dosa"}) {
t.Errorf("Recipes matched for search query %s got %d, want %d", config.SEARCH_STR, result.CountPerPostCodeAndTime.DeliveryCount, 2)
}
}
func getDummyRecipe() []dtos.Recipe {
r1 := dtos.Recipe{}
r1.Postcode = "10137"
r1.Name = "Ghee Dosa"
r1.Delivery = "Sunday 6AM - 12PM"
r2 := dtos.Recipe{}
r2.Postcode = "10599"
r2.Name = "Chapathi"
r2.Delivery = "Sunday 11AM - 5PM"
r3 := dtos.Recipe{}
r3.Postcode = "10137"
r3.Name = "Masala Dosa"
r3.Delivery = "Sunday 7PM - 10PM"
r4 := dtos.Recipe{}
r4.Postcode = "10137"
r4.Name = "Ghee Dosa"
r4.Delivery = "Sunday 6AM - 1PM"
r5 := dtos.Recipe{}
r5.Postcode = "10137"
r5.Name = "Vadai"
r5.Delivery = "Sunday 5AM - 11AM"
result := []dtos.Recipe{r1, r2, r3, r4, r5}
return result
}