11package hazardproviders
22
33import (
4- "fmt"
54 "testing"
5+ "time"
66
77 "github.com/USACE/go-consequences/geography"
88 "github.com/USACE/go-consequences/hazards"
@@ -11,10 +11,20 @@ import (
1111func TestInitADDMHP (t * testing.T ) {
1212 file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.json"
1313
14+ expectedDepths := []float64 {1.0 , 1.0 , 1.0 , 2.0 , 2.0 }
15+ expectedDurations := []float64 {0.0 , 5.0 , 0.0 , 0.0 , 0.0 }
16+ et1 := time .Date (1984 , time .Month (1 ), 1 , 0 , 0 , 0 , 0 , time .UTC )
17+ et2 := time .Date (1984 , time .Month (1 ), 11 , 0 , 0 , 0 , 0 , time .UTC )
18+ et3 := time .Date (1984 , time .Month (1 ), 21 , 0 , 0 , 0 , 0 , time .UTC )
19+ et4 := time .Date (1985 , time .Month (1 ), 1 , 0 , 0 , 0 , 0 , time .UTC )
20+ et5 := time .Date (1985 , time .Month (1 ), 11 , 0 , 0 , 0 , 0 , time .UTC )
21+ expectedArrivals := []time.Time {et1 , et2 , et3 , et4 , et5 }
22+
1423 ADDMHP , err := InitADDMHP (file )
1524 if err != nil {
1625 panic (err )
1726 }
27+ defer ADDMHP .Close ()
1828
1929 loc := geography.Location {
2030 X : - 71.481 ,
@@ -23,16 +33,26 @@ func TestInitADDMHP(t *testing.T) {
2333 }
2434
2535 haz , err := ADDMHP .Hazard (loc )
26- h := haz .(hazards.ArrivalDepthandDurationEventMulti )
36+ h := haz .(* hazards.ArrivalDepthandDurationEventMulti )
2737 if err != nil {
2838 panic (err )
2939 }
3040
3141 for {
32- fmt .Printf (
33- "%d: Depth: %3.2f, Duration: %3.2f, Arrival: %v\n " ,
34- h .Index (), h .Depth (), h .Duration (), h .ArrivalTime (),
35- )
42+ edepth := expectedDepths [h .Index ()]
43+ edur := expectedDurations [h .Index ()]
44+ earr := expectedArrivals [h .Index ()]
45+
46+ if h .Depth () != edepth {
47+ t .Errorf ("Event at index %d had Depth = %v. Expected: %3.2f" , h .Index (), h .Depth (), edepth )
48+ }
49+ if h .Duration () != edur {
50+ t .Errorf ("Event at index %d had Duration = %v. Expected: %3.2f" , h .Index (), h .Duration (), edur )
51+ }
52+ if h .Depth () != edepth {
53+ t .Errorf ("Event at index %d had ArrivalTime = %v. Expected: %v" , h .Index (), h .ArrivalTime (), earr )
54+ }
55+
3656 if h .HasNext () {
3757 h .Increment ()
3858 } else {
0 commit comments