Skip to content

Commit

Permalink
Merge pull request #15 from openhealthalgorithms/error-management
Browse files Browse the repository at this point in the history
Error management
  • Loading branch information
samhq authored Sep 8, 2021
2 parents a08096e + 3301ac2 commit 4a3bec4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
8 changes: 4 additions & 4 deletions actions/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func AlgorithmHandler(c echo.Context) error {
GoalContent: *glc,
}

hs, hg, hr, hd, hrs, err := hearts.Process(*o, colorChartPath, countriesPath)
if err != nil {
return ErrorResponse(c, err, 500)
}
hs, hg, hr, hd, hrs, _ := hearts.Process(*o, colorChartPath, countriesPath)
// if err != nil {
// return ErrorResponse(c, err, 500)
// }

output := models.NewOutput(*o.Config.Algorithm)
output.Assessments = hs
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

const version = "v1.5.0"
const version = "v1.6.0"

// GetVersion returns the current version
func GetVersion() string {
Expand Down
12 changes: 12 additions & 0 deletions pkg/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg

import (
"testing"
)

func TestGetVersion(t *testing.T) {
vers := version
if GetVersion() != vers {
t.Errorf("GetVersion(): expected %s, actual %s", vers, GetVersion())
}
}
3 changes: 2 additions & 1 deletion tools/calculate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tools

import (
"math"
"strings"
)

Expand All @@ -18,7 +19,7 @@ func CalculateAge(age float64, unit string) float64 {
}
}

return calAge
return math.Ceil(calAge*100) / 100
}

// CalculateExercise to minutes and moderate type weekly
Expand Down
28 changes: 28 additions & 0 deletions tools/calculate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tools

import (
"testing"
)

func TestCalculateAge(t *testing.T) {
type ageTest struct {
value float64
unit string
result float64
}

var ageTests = []ageTest{
{25, "year", 25},
{12, "month", 1},
{17, "week", 0.33},
{715, "day", 1.96},
{17, "hours", 17},
}

for _, at := range ageTests {
actual := CalculateAge(at.value, at.unit)
if actual != at.result {
t.Errorf("CalculateAge(%f, %s): expected %f, actual %f", at.value, at.unit, at.result, actual)
}
}
}
20 changes: 20 additions & 0 deletions tools/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,23 @@ func TestSliceStringEqual(t *testing.T) {
}
}
}

func TestGetFullGenderText(t *testing.T) {
type genderTest struct {
str string
output string
}

var genderTests = []genderTest{
{"m", "male"},
{"f", "female"},
{"t", "female"},
}

for _, sas := range genderTests {
actual := GetFullGenderText(sas.str)
if actual != sas.output {
t.Errorf("GetFullGenderText(%s): expected %s, actual %s", sas.str, sas.output, actual)
}
}
}

0 comments on commit 4a3bec4

Please sign in to comment.