Created
December 8, 2012 03:04
-
-
Save nathany/4238394 to your computer and use it in GitHub Desktop.
Within Delta Custom Checker for gocheck
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type withinChecker struct { | |
*CheckerInfo | |
} | |
var Within Checker = &withinChecker{ | |
&CheckerInfo{Name: "Within", Params: []string{"obtained", "delta", "expected"}}, | |
} | |
func (c *withinChecker) Check(params []interface{}, names []string) (result bool, error string) { | |
obtained, ok := params[0].(float64) | |
if !ok { | |
return false, "obtained must be a float64" | |
} | |
delta, ok := params[1].(float64) | |
if !ok { | |
return false, "delta must be a float64" | |
} | |
expected, ok := params[2].(float64) | |
if !ok { | |
return false, "expected must be a float64" | |
} | |
return math.Abs(obtained-expected) <= delta, "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment