2022-06-27 21:10:33 +02:00
|
|
|
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package stats
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMakeTableHdr(t *testing.T) {
|
|
|
|
want := statsHdr{
|
|
|
|
Algo: "Random Search",
|
|
|
|
BenchFuncName: "Schwefel",
|
|
|
|
Dimens: 10,
|
|
|
|
Generations: 3000,
|
|
|
|
Iterations: 30,
|
|
|
|
}
|
|
|
|
got := makeTableHdr("Random Search", "Schwefel", 10, 3000, 30)
|
|
|
|
|
|
|
|
if want != got {
|
2022-06-28 00:44:58 +02:00
|
|
|
t.Errorf("wrong hdr, want: %+v, got: %+v", want, got)
|
2022-06-27 21:10:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewStatsHdr(t *testing.T) {
|
|
|
|
if want := newStatsHdr(); want == nil {
|
|
|
|
t.Error("could not create hdr")
|
|
|
|
}
|
|
|
|
}
|
2022-06-27 21:56:44 +02:00
|
|
|
|
|
|
|
func TestStatsSingleFunc(t *testing.T) {
|
|
|
|
testHdr := makeTableHdr("Aladeen Search", "De Jong 5th", 5, 3, 4)
|
|
|
|
benchFuncStats := []FuncStats{
|
|
|
|
{
|
|
|
|
BenchName: "De Jong 5th",
|
|
|
|
Solution: []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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
want := []interface{}{
|
|
|
|
"\n",
|
|
|
|
testHdr,
|
|
|
|
"\n",
|
|
|
|
statsRow{1336.3261400058473, 2169.7378893600176, 1737.765688971335, 1737.765688971335, 342.37072192259393},
|
|
|
|
"\n",
|
|
|
|
}
|
|
|
|
got := statsSingleFunc(testStats)
|
|
|
|
|
|
|
|
if len(want) != len(got) {
|
|
|
|
t.Errorf("outputs are of different sizes, want: %d, got: %d", len(want), len(got))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range want {
|
|
|
|
if want[i] != got[i] {
|
2022-06-28 00:44:58 +02:00
|
|
|
t.Errorf("outputs don't match, want: %+v, got: %+v", want, got)
|
2022-06-27 21:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|