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"
|
2022-07-13 17:35:18 +02:00
|
|
|
|
|
|
|
"git.dotya.ml/wanderer/math-optim/report"
|
2022-06-27 21:10:33 +02:00
|
|
|
)
|
|
|
|
|
2022-07-13 17:35:18 +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 {
|
2022-07-13 17:35:18 +02:00
|
|
|
t.Errorf("wrong row title, want: %+q, got: %+q", want, got)
|
2022-06-27 21:10:33 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-27 21:56:44 +02:00
|
|
|
|
2022-07-13 17:35:18 +02:00
|
|
|
func TestParseBenchStats(t *testing.T) {
|
2022-06-27 21:56:44 +02:00
|
|
|
benchFuncStats := []FuncStats{
|
|
|
|
{
|
|
|
|
BenchName: "De Jong 5th",
|
2022-07-19 19:58:45 +02:00
|
|
|
BenchResults: []BenchRound{
|
2022-06-27 21:56:44 +02:00
|
|
|
{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-13 17:35:18 +02:00
|
|
|
|
2022-07-18 04:17:58 +02:00
|
|
|
wantResults := []float64{1336.3261400058473, 2169.7378893600176, 1737.765688971335, 1722.4993632597375, 342.37072192259393}
|
2022-07-13 17:35:18 +02:00
|
|
|
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))
|
2022-06-27 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2022-07-13 17:35:18 +02:00
|
|
|
if want.Title != got.Title {
|
|
|
|
t.Errorf("output titles differ, want: %q, got: %q", want.Title, got.Title)
|
2022-06-27 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2022-07-13 17:35:18 +02:00
|
|
|
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)
|
2022-06-27 21:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|