2023-02-05 13:28:05 +01:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package cec2020
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
// TestRastrigin checks that the Rastrigin func performs as expected.
|
|
|
|
func TestRastrigin(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 343.97127081044846
|
|
|
|
got := Rastrigin(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect Rastrigin output, want: %f, got: %f", want, got)
|
|
|
|
}
|
|
|
|
}
|
2023-02-09 23:55:22 +01:00
|
|
|
|
|
|
|
func TestHighConditionedElliptic(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 1.630609804125232e+06
|
|
|
|
got := HighConditionedElliptic(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGHBat(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 158.83404437332385
|
|
|
|
got := HGBat(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRosenbrock(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 270378.6217883186
|
|
|
|
got := Rosenbrock(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAckley(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 10.420166703127961
|
|
|
|
got := Ackley(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
2023-02-09 23:56:41 +01:00
|
|
|
|
2023-02-09 23:58:29 +01:00
|
|
|
func TestDiscus(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 7.364737863641793e+06
|
|
|
|
got := Discus(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:56:41 +01:00
|
|
|
func TestSchafferExpanded(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 15.903821248304322
|
|
|
|
got := SchafferExpanded(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|
2023-02-09 23:57:36 +01:00
|
|
|
|
|
|
|
func TestWeierstrass(t *testing.T) {
|
|
|
|
testInput := []float64{
|
|
|
|
-2.7137778065280593,
|
|
|
|
-1.9789783390895765,
|
|
|
|
-4.38267902085263,
|
|
|
|
-4.617877608383319,
|
|
|
|
-2.1529909200665474,
|
|
|
|
-3.801849324611571,
|
|
|
|
2.4968697503272486,
|
|
|
|
-0.27358100201730196,
|
|
|
|
2.0444319451255977,
|
|
|
|
3.8798952350630653,
|
|
|
|
-0.6150024279011337,
|
|
|
|
2.8643010641852413,
|
|
|
|
-0.6692444051928748,
|
|
|
|
4.4649633199687475,
|
|
|
|
3.2510298731558507,
|
|
|
|
-4.2095036422081495,
|
|
|
|
-0.130882052243404,
|
|
|
|
1.2001716295708604,
|
|
|
|
-0.29427650577602193,
|
|
|
|
}
|
|
|
|
want := 39.69284047936819
|
|
|
|
got := Weierstrass(testInput)
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("incorrect output, want: %f, got: %v", want, got)
|
|
|
|
}
|
|
|
|
}
|