Skip to content
Snippets Groups Projects
Commit d3097f43 authored by Tucker Siegel's avatar Tucker Siegel
Browse files

update tests

parent 3c7ae959
No related branches found
No related tags found
2 merge requests!17Adds rabbitmq messaging,!14update tests
...@@ -45,7 +45,8 @@ var ProductType = &ProductList{ ...@@ -45,7 +45,8 @@ var ProductType = &ProductList{
SORGHUM: Product{"SORGHUM", 46.4}, SORGHUM: Product{"SORGHUM", 46.4},
} }
func GetProductFromString(productString string) Product { func GetProductFromString(product string) Product {
productString := strings.ToLower(product)
switch productString { switch productString {
case ProductType.CORN.Name: case ProductType.CORN.Name:
case strings.ToLower(ProductType.CORN.Name): case strings.ToLower(ProductType.CORN.Name):
......
package enums
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestProduct(t *testing.T) {
testTable := make(map[string]string)
testTable["corn"] = "CORN"
testTable["coRn"] = "CORN"
testTable["soybean"] = "SOYBEAN"
testTable["sunflower"] = "SUNFLOWER"
testTable["tomato"] = "TOMATO"
testTable["sugar_beet"] = "SUGAR_BEET"
testTable["peanut"] = "PEANUT"
testTable["cotton"] = "COTTON"
testTable["potato"] = "POTATO"
testTable["wheat"] = "WHEAT"
testTable["pea"] = "PEA"
testTable["oat"] = "OAT"
testTable["spring_wheat"] = "SPRING_WHEAT"
testTable["rice"] = "RICE"
testTable["sorghum"] = "SORGHUM"
for k := range testTable {
assert.Equal(t, testTable[k], GetProductFromString(k).Name)
}
}
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities" "gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities"
) )
func mockCurrentGddFindFirstByYearAndLocation(ctx common.DawnCtx, location entities.Location) entities.Gdd { func mockGddFindFirstByYearAndLocation(year int, location entities.Location) entities.Gdd {
return entities.Gdd{ return entities.Gdd{
ID: "id", ID: "id",
PrismLat: 10, PrismLat: 10,
...@@ -28,20 +28,21 @@ func mockCurrentGddFindFirstByYearAndLocation(ctx common.DawnCtx, location entit ...@@ -28,20 +28,21 @@ func mockCurrentGddFindFirstByYearAndLocation(ctx common.DawnCtx, location entit
} }
} }
func mockGddFindFirstByYearAndLocation(year int, location entities.Location) entities.Gdd { func mockNormalsFindFirstByYearAndLocation(location entities.Location) entities.Normal {
return entities.Gdd{ return entities.Normal{
ID: "id", ID: "id",
PrismLat: 10, PrismLat: 10,
PrismLon: 10, PrismLon: 10,
LastDate: 11647746,
AnalogYear: 2020,
Year: 1989,
MinTemps: []float64{30.0, 40.0, 50.0, 60.0, 70.0},
MaxTemps: []float64{40.0, 60.0, 78.0, 88.0, 105.0},
Location: entities.Location{ Location: entities.Location{
Type: "point", Type: "point",
Coordinates: []float64{12.0, 12.0}, Coordinates: []float64{12.0, 12.0},
}, },
GddBase: []float64{30.0, 50.0, 65.0},
CornBase: []float64{30.0, 50.0, 65.0},
GddMean: []float64{30.0, 50.0, 65.0},
CornMean: []float64{30.0, 50.0, 65.0},
GddStd: []float64{5.0, 6.0, 4.0},
CornStd: []float64{5.0, 6.0, 4.0},
} }
} }
...@@ -79,3 +80,37 @@ func TestGetGddValuesCorn(t *testing.T) { ...@@ -79,3 +80,37 @@ func TestGetGddValuesCorn(t *testing.T) {
assert.Equal(t, 28.0, gdds.GddValues[4], "must equal") assert.Equal(t, 28.0, gdds.GddValues[4], "must equal")
assert.Equal(t, 14.0, gdds.GddValues[2], "must equal") assert.Equal(t, 14.0, gdds.GddValues[2], "must equal")
} }
func TestGetNormalValuesCorn(t *testing.T) {
mock := DawnTest.CreateMock(persistence.NormalsFindFirstByYearAndLocation, mockNormalsFindFirstByYearAndLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "corn",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: false,
}
gdds := GetNormalValues(request)
assert.Equal(t, 0.0, gdds.GddValues[0], "must equal")
assert.Equal(t, 15.0, gdds.GddValues[2], "must equal")
}
func TestGetNormalValues(t *testing.T) {
mock := DawnTest.CreateMock(persistence.NormalsFindFirstByYearAndLocation, mockNormalsFindFirstByYearAndLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "soybean",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: false,
}
gdds := GetNormalValues(request)
assert.Equal(t, 0.0, gdds.GddValues[0], "must equal")
assert.Equal(t, 15.0, gdds.GddValues[2], "must equal")
}
package services
import (
"testing"
"github.com/stretchr/testify/assert"
DawnTest "gitlab.cs.umd.edu/dawn/dawn-go-common/testing"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/models"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities"
)
func mockGefsFindAllByLocation(location entities.Location) []entities.GefsGdd {
var arr []entities.GefsGdd
filler := entities.GefsGdd{
ID: "id",
Location: entities.Location{
Type: "point",
Coordinates: []float64{12.0, 12.0},
},
MinTemp: 45.0,
MaxTemp: 76.0,
VarMin: 1.0,
VarMax: 1.0,
Date: 215342634,
}
arr = append(arr,
entities.GefsGdd{
ID: "id",
Location: entities.Location{
Type: "point",
Coordinates: []float64{12.0, 12.0},
},
MinTemp: 45.0,
MaxTemp: 76.0,
VarMin: 1.0,
VarMax: 1.0,
Date: 215342634,
},
)
arr = append(arr,
entities.GefsGdd{
ID: "id",
Location: entities.Location{
Type: "point",
Coordinates: []float64{12.0, 12.0},
},
MinTemp: 65.0,
MaxTemp: 106.0,
VarMin: 1.0,
VarMax: 1.0,
Date: 215342634,
},
)
arr = append(arr,
entities.GefsGdd{
ID: "id",
Location: entities.Location{
Type: "point",
Coordinates: []float64{12.0, 12.0},
},
MinTemp: 23.0,
MaxTemp: 45.0,
VarMin: 1.0,
VarMax: 1.0,
Date: 215342634,
},
)
for i := 0; i < 7; i++ {
arr = append(arr, filler)
}
return arr
}
func mockCfsFindAllByLocation(location entities.Location) entities.CfsGdd {
return entities.CfsGdd{
ID: "id",
Location: entities.Location{
Type: "point",
Coordinates: []float64{12.0, 12.0},
},
MaxTemps: []float64{35.0, 55.0, 78.0},
MinTemps: []float64{65.0, 43.0, 54.0},
VarMin: []float64{1.0, 1.0, 1.0},
VarMax: []float64{1.0, 1.0, 1.0},
Date: 342653425,
}
}
func TestGetGefsGddValues(t *testing.T) {
mock := DawnTest.CreateMock(persistence.GefsFindAllByLocation, mockGefsFindAllByLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "soybean",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: false,
}
gdds := GetGefsGddValues(request)
assert.Equal(t, 10.5, gdds.GddValues[0], "must equal")
assert.Equal(t, 0.0, gdds.GddValues[2], "must equal")
}
func TestGetGefsGddValuesAccumulate(t *testing.T) {
mock := DawnTest.CreateMock(persistence.GefsFindAllByLocation, mockGefsFindAllByLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "soybean",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: true,
}
gdds := GetGefsGddValues(request)
assert.Equal(t, 10.5, gdds.GddValues[0], "must equal")
assert.Equal(t, 46.0, gdds.GddValues[2], "must equal")
}
func TestGetCefsGddValues(t *testing.T) {
mock := DawnTest.CreateMock(persistence.CfsFindAllByLocation, mockCfsFindAllByLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "soybean",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: false,
}
gdds := GetCfsGddValues(request)
assert.Equal(t, 0.0, gdds.GddValues[0], "must equal")
assert.Equal(t, 16.0, gdds.GddValues[2], "must equal")
}
func TestGetCefsGddValuesAccumulate(t *testing.T) {
mock := DawnTest.CreateMock(persistence.CfsFindAllByLocation, mockCfsFindAllByLocation)
defer mock.Unpatch()
request := models.GddRequest{
Product: "corn",
Latitude: 12.0,
Longitude: 12.0,
Year: 2020,
Accumulate: true,
}
gdds := GetCfsGddValues(request)
assert.Equal(t, 7.5, gdds.GddValues[0], "must equal")
assert.Equal(t, 26.0, gdds.GddValues[2], "must equal")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment