Skip to content

Commit

Permalink
adding some unit tests, also noting some todo locations to respond to…
Browse files Browse the repository at this point in the history
… nick comments
  • Loading branch information
HenryGeorgist committed Apr 17, 2024
1 parent 8e42478 commit a72282f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lifeloss/lifeloss.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Init(seed int64, warningSystem warning.WarningResponseSystem) LifeLossEngin
}

func LifeLossHeader() []string {
return []string{"ll_u65", "ll_o65", "ll_tot"}
return []string{"ll_u65", "ll_o65", "ll_tot"} //@TODO: Consider adding structure stability state, fatality rates, and sampled hazard parameters
}
func LifeLossDefaultResults() []interface{} {
var ll_u65, ll_o65, ll_tot int32
Expand Down Expand Up @@ -89,7 +89,7 @@ func (le LifeLossEngine) ComputeLifeLoss(e hazards.HazardEvent, s structures.Str
} else {
return le.submergenceCriteria(e, s, remainingPop, rng)
}
} else {
} else { //@TODO:ensure i have depth at least!!!
//apply submergence criteria
return le.submergenceCriteria(e, s, remainingPop, rng)
}
Expand Down
72 changes: 72 additions & 0 deletions lifeloss/stability_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package lifeloss

import (
"testing"

"github.com/USACE/go-consequences/hazards"
)

func Test_RescDamUnanchoredWoodStability(t *testing.T) {

sc := RescDamWoodUnanchored

h := hazards.DepthandDVEvent{}
h.SetDV(30)
h.SetDepth(100)
result := sc.Evaluate(h)
if result != Stable {
t.Fail()
}

h.SetDV(35)
h.SetDepth(100)
result = sc.Evaluate(h)
if result != Collapsed {
t.Fail()
}
}
func Test_RescDamAnchoredWoodStability(t *testing.T) {

sc := RescDamWoodAnchored

h := hazards.DepthandDVEvent{}
h.SetDV(35)
h.SetDepth(100)
result := sc.Evaluate(h)
if result != Stable {
t.Fail()
}

h.SetDV(75.4)
h.SetDepth(100)
result = sc.Evaluate(h)
if result != Collapsed {
t.Fail()
}
}
func Test_RescDamConcreteMasonarySteelStability(t *testing.T) {

sc := RescDamMasonryConcreteBrick

h := hazards.DepthandDVEvent{}
h.SetDV(35)
h.SetDepth(100)
result := sc.Evaluate(h)
if result != Stable {
t.Fail()
}

h.SetDV(75.4)
h.SetDepth(10)
result = sc.Evaluate(h)
if result != Collapsed {
t.Fail()
}

h.SetDV(75.4)
h.SetDepth(20)
result = sc.Evaluate(h)
if result != Stable { //velocity is computed as not being high enough because depth was so high.
t.Fail()
}
}
2 changes: 1 addition & 1 deletion warning/warningresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ComplianceBasedWarningSystem struct {
func InitComplianceBasedWarningSystem(seed int64, complianceRate float64) ComplianceBasedWarningSystem {
return ComplianceBasedWarningSystem{rng: rand.New(rand.NewSource(seed)), ComplianceRate: complianceRate}
}
func (c ComplianceBasedWarningSystem) WarningFunction() PopulationReductionFunction {
func (c ComplianceBasedWarningSystem) WarningFunction() PopulationReductionFunction { //@TODO:Consider housing groups instead of simply assuming each individual is independent
return func(s structures.StructureDeterministic, hazard hazards.HazardEvent) (structures.PopulationSet, consequences.Result) {
pop2amo65 := 0
pop2amu65 := 0
Expand Down

0 comments on commit a72282f

Please sign in to comment.