math-optim/bench/functions_test.go
leo 3f77c573a6
All checks were successful
continuous-integration/drone/push Build is passing
chore: 2023
2023-01-12 23:35:51 +01:00

105 lines
2.1 KiB
Go

// Copyright 2023 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package bench
import (
"testing"
)
// nolint: ifshort
func TestSchwefel(t *testing.T) {
testInput := []float64{
-347.0688554171835,
-193.50664570036423,
305.82332552701894,
-364.7405491758999,
349.71016993542025,
477.5056089986731,
327.96509926732915,
-244.37404894905524,
474.44611085957047,
-129.7466908340217,
-255.09108362017673,
-74.55987259432703,
-359.81582787364243,
-300.5468299659283,
-444.1095229246622,
-470.636877835192,
-115.76955072388938,
415.09390685837457,
414.5583142419347,
279.18352845926813,
}
want := 8401.863276800143
got := Schwefel(testInput)
if want != got {
t.Errorf("incorrect Schwefel output, want: %f, got: %f", want, got)
}
}
// nolint: ifshort
func TestDeJong1st(t *testing.T) {
testInput := []float64{
-3.0511405599730756,
4.258129003215828,
4.1581352433635725,
-1.3120754688788683,
-0.534459370997058,
-1.3566518876859002,
-2.3056242054291176,
2.328340273635618,
2.9533390159087443,
0.6100735516633335,
-3.801849324611571,
2.4968697503272486,
-0.27358100201730196,
2.0444319451255977,
1.2321584915799555,
-3.517355379555882,
-1.8188004055714768,
-3.0549711074615726,
-2.7652144688950187,
4.116635614051347,
}
want := 144.4773277294281
got := DeJong1st(testInput)
if want != got {
t.Errorf("incorrect DeJong1st output, want: %f, got: %f", want, got)
}
}
// nolint: ifshort
func TestDeJong2nd(t *testing.T) {
testInput := []float64{
-0.29427650577602193,
-1.9789783390895765,
-2.7137778065280593,
-4.38267902085263,
-4.617877608383319,
-2.1529909200665474,
3.8798952350630653,
-0.6150024279011337,
-0.6692444051928748,
4.4649633199687475,
2.8643010641852413,
-4.263379259887743,
-4.2095036422081495,
-3.3511320414917134,
-4.949196593517949,
-2.273931370051001,
-0.130882052243404,
1.2001716295708604,
3.2510298731558507,
-1.7502969545890834,
}
want := -33.0
got := DeJong2nd(testInput)
if want != got {
t.Errorf("incorrect DeJong2nd output, want: %f, got: %f", want, got)
}
}