2023-01-12 23:35:51 +01:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
2022-06-14 22:34:52 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package algo
|
|
|
|
|
|
|
|
import (
|
2022-12-24 11:30:22 +01:00
|
|
|
"log"
|
2022-06-28 23:42:15 +02:00
|
|
|
"os"
|
2022-06-14 22:34:52 +02:00
|
|
|
"sync"
|
|
|
|
"testing"
|
2022-07-12 16:56:49 +02:00
|
|
|
|
|
|
|
"git.dotya.ml/wanderer/math-optim/report"
|
2022-06-14 22:34:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2022-07-16 22:05:15 +02:00
|
|
|
var m sync.Mutex
|
|
|
|
|
2022-06-14 22:34:52 +02:00
|
|
|
func TestDoRandomSearchExec(t *testing.T) {
|
2022-12-24 11:30:22 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-06-28 23:42:15 +02:00
|
|
|
wg.Add(1)
|
2022-06-14 22:34:52 +02:00
|
|
|
|
2022-12-24 11:30:22 +01:00
|
|
|
// use t.tmpdir
|
2022-07-16 22:05:15 +02:00
|
|
|
go DoRandomSearch(&wg, &m)
|
2022-06-14 22:34:52 +02:00
|
|
|
|
2022-06-28 23:42:15 +02:00
|
|
|
wg.Wait()
|
2022-06-20 03:32:48 +02:00
|
|
|
|
2022-08-20 12:42:20 +02:00
|
|
|
picsDir := report.GetPicsDir() + "-test-rs"
|
2022-07-12 16:56:49 +02:00
|
|
|
|
2022-12-24 11:30:22 +01:00
|
|
|
// attempt to clean up.
|
2022-07-12 16:56:49 +02:00
|
|
|
if err := os.RemoveAll(picsDir); err != nil {
|
2022-06-28 23:42:15 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-07-16 17:01:01 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-08-20 12:42:20 +02:00
|
|
|
|
2022-12-24 11:30:22 +01:00
|
|
|
log.Println("pwd:", os.Getenv("PWD"))
|
2022-08-20 12:42:20 +02:00
|
|
|
// clean up outdir.
|
|
|
|
if err := os.RemoveAll("out"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-14 22:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDoSHCExec(t *testing.T) {
|
2022-12-24 11:30:22 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2022-06-14 22:34:52 +02:00
|
|
|
wg.Add(1)
|
|
|
|
|
2022-07-16 22:05:15 +02:00
|
|
|
go DoStochasticHillClimbing(&wg, &m)
|
2022-06-14 22:34:52 +02:00
|
|
|
|
|
|
|
wg.Wait()
|
2022-07-08 21:40:04 +02:00
|
|
|
|
2022-08-20 12:42:20 +02:00
|
|
|
picsDir := report.GetPicsDir() + "-test-shc"
|
2022-07-12 16:56:49 +02:00
|
|
|
|
2022-12-24 11:30:22 +01:00
|
|
|
// attempt to clean up.
|
2022-07-12 16:56:49 +02:00
|
|
|
if err := os.RemoveAll(picsDir); err != nil {
|
2022-07-08 21:40:04 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-07-16 17:01:01 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-08-20 12:42:20 +02:00
|
|
|
|
2022-12-24 11:30:22 +01:00
|
|
|
log.Println("pwd:", os.Getenv("PWD"))
|
2022-08-20 12:42:20 +02:00
|
|
|
// clean up outdir.
|
|
|
|
if err := os.RemoveAll("out"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-06-14 22:34:52 +02:00
|
|
|
}
|