math-optim/stats/table_test.go

65 lines
1.8 KiB
Go
Raw Normal View History

2023-01-12 23:35:51 +01:00
// Copyright 2023 wanderer <a_mirre at utb dot cz>
2022-06-27 21:10:33 +02:00
// SPDX-License-Identifier: GPL-3.0-or-later
package stats
import (
"testing"
"git.dotya.ml/wanderer/math-optim/report"
2022-06-27 21:10:33 +02:00
)
func TestMakeRowTitle(t *testing.T) {
want := `D=10, f=Schwefel, G=3000, I=30`
got := makeRowTitle("Schwefel", 10, 3000, 30)
2022-06-27 21:10:33 +02:00
if want != got {
t.Errorf("wrong row title, want: %+q, got: %+q", want, got)
2022-06-27 21:10:33 +02:00
}
}
func TestParseBenchStats(t *testing.T) {
benchFuncStats := []FuncStats{
{
BenchName: "De Jong 5th",
BenchResults: []BenchRound{
{Iteration: 0, Results: []float64{2803.7015205977887, 2296.736381649773, 1763.9319525203364}},
{Iteration: 1, Results: []float64{2169.7378893600176, 2169.7378893600176, 2169.7378893600176}},
{Iteration: 2, Results: []float64{1909.6488355929007, 1336.3261400058473, 1336.3261400058473}},
{Iteration: 3, Results: []float64{2227.0782796718786, 2227.0782796718786, 1681.0667739991388}},
},
},
}
testStats := []Stats{
{
Algo: "Aladeen Search",
Dimens: 5,
BenchFuncStats: benchFuncStats,
Iterations: 4,
Generations: 3,
},
}
2022-07-18 04:17:58 +02:00
wantResults := []float64{1336.3261400058473, 2169.7378893600176, 1737.765688971335, 1722.4993632597375, 342.37072192259393}
want := report.Row{
Title: "D=5, f=De Jong 5th, G=3, I=4",
Values: wantResults,
}
// expecting a singlerow so we're accessing it directly.
got := parseSingleBenchStats(testStats)[0]
if len(want.Values) != len(got.Values) {
t.Errorf("outputs are of different sizes, want: %d, got: %d", len(want.Values), len(got.Values))
}
if want.Title != got.Title {
t.Errorf("output titles differ, want: %q, got: %q", want.Title, got.Title)
}
for i := range want.Values {
if want.Values[i] != got.Values[i] {
t.Errorf("outputs don't match,\n\twant: %+v,\n\tgot: %+v", want, got)
}
}
}