aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-03-13 22:25:51 -0400
committerMitch Riedstra <mitch@riedstra.us>2019-03-13 22:25:51 -0400
commit868219192a2c5d6e14df73ceb348f4ec3d25327b (patch)
treeb2923b7bf234e6244f0fd3286c18285b3c0a9af6
parent9ebe8a048bb57e7b85fdabb7cbbe7957ae33af65 (diff)
downloadstats-tests.tar.gz
stats-tests.tar.xz
So far miserable failure on testing fieldstests
-rw-r--r--stats_test.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/stats_test.go b/stats_test.go
index 3340b77..64ed88b 100644
--- a/stats_test.go
+++ b/stats_test.go
@@ -20,7 +20,7 @@ var (
22.679, 16.277, 18.738, 20.271, 20.967, 19.157, 20.338,
},
}
- expectedResults map[string][]float64 = map[string][]float64{
+ expectedMethodResults map[string][]float64 = map[string][]float64{
"Mean": {29.044091, 18.2453333333333},
"StandardDeviation": {8.06420820019572, 2.56887224932135},
"Kurtosis": {0.515004967048032, -0.804414119818956},
@@ -28,6 +28,10 @@ var (
"Skewness": {-0.669882132708844, -0.297404073286609},
"NumValues": {22, 21},
}
+ expectedFieldValues map[string][]float64 = map[string][]float64{
+ "Min": {10.68, 13.691},
+ "Max": {41.08, 22.679},
+ }
)
func TestStats(t *testing.T) {
@@ -36,11 +40,8 @@ func TestStats(t *testing.T) {
for _, n := range set {
s.Push(n)
}
- // rs := reflect.ValueOf(&s)
- for method, values := range expectedResults {
+ for method, values := range expectedMethodResults {
t.Run(fmt.Sprintf("%s for set %d", method, i), func(t *testing.T) {
- // m := rs.MethodByName(method).Call([]reflect.Value{})
- // got := reflect.ValueOf(&s).MethodByName(method).Call([]reflect.Value{})
m := reflect.ValueOf(s).MethodByName(method).Call([]reflect.Value{})
// Round to three decimal places
got := math.Round(m[0].Float()*1000) / 1000
@@ -54,6 +55,23 @@ func TestStats(t *testing.T) {
}
})
}
+ for field, values := range expectedFieldValues {
+ t.Run(fmt.Sprintf("%s for set %d", field, i), func(t *testing.T) {
+ m := reflect.ValueOf(s).FieldByName(field)
+ fmt.Println(m)
+ // Round to three decimal places
+ //got := math.Round(m.Float()*1000) / 1000
+ got := 0.00000
+ expected := math.Round(values[i]*1000) / 1000
+ if got != expected {
+ t.Errorf("Field %s failure: \n"+
+ "\tOn set: %d\n"+
+ "\tExpected: %f\n"+
+ "\tGot: %f\n",
+ field, i, expected, got)
+ }
+ })
+ }
}
}