67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package algo
|
|
|
|
import (
|
|
"os"
|
|
"sync"
|
|
"testing"
|
|
|
|
"git.dotya.ml/wanderer/math-optim/report"
|
|
)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var m sync.Mutex
|
|
|
|
func TestDoRandomSearchExec(t *testing.T) {
|
|
wg.Add(1)
|
|
|
|
go DoRandomSearch(&wg, &m)
|
|
|
|
wg.Wait()
|
|
|
|
picsDir := report.GetPicsDir() + "-test-rs"
|
|
|
|
if err := os.RemoveAll(picsDir); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
// if `stat` on picsDir succeeds now, something is wrong (namely the
|
|
// clean-up apparently did not succeed).
|
|
if _, err := os.Stat(picsDir); err == nil {
|
|
t.Error("picsDir should have already been cleaned up")
|
|
}
|
|
|
|
// clean up outdir.
|
|
if err := os.RemoveAll("out"); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestDoSHCExec(t *testing.T) {
|
|
wg.Add(1)
|
|
|
|
go DoStochasticHillClimbing(&wg, &m)
|
|
|
|
wg.Wait()
|
|
|
|
picsDir := report.GetPicsDir() + "-test-shc"
|
|
|
|
if err := os.RemoveAll(picsDir); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
// if `stat` on picsDir succeeds now, something is wrong (namely the
|
|
// clean-up apparently did not succeed).
|
|
if _, err := os.Stat(picsDir); err == nil {
|
|
t.Error("picsDir should have already been cleaned up")
|
|
}
|
|
|
|
// clean up outdir.
|
|
if err := os.RemoveAll("out"); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|