math-optim/algo/algo_test.go

77 lines
1.4 KiB
Go
Raw Normal View History

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"
"os"
2022-06-14 22:34:52 +02:00
"sync"
"testing"
"git.dotya.ml/wanderer/math-optim/report"
2022-06-14 22:34:52 +02:00
)
var wg sync.WaitGroup
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()
wg.Add(1)
2022-06-14 22:34:52 +02:00
2022-12-24 11:30:22 +01:00
// use t.tmpdir
go DoRandomSearch(&wg, &m)
2022-06-14 22:34:52 +02:00
wg.Wait()
picsDir := report.GetPicsDir() + "-test-rs"
2022-12-24 11:30:22 +01:00
// attempt to clean up.
if err := os.RemoveAll(picsDir); err != nil {
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-12-24 11:30:22 +01:00
log.Println("pwd:", os.Getenv("PWD"))
// 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)
go DoStochasticHillClimbing(&wg, &m)
2022-06-14 22:34:52 +02:00
wg.Wait()
2022-07-08 21:40:04 +02:00
picsDir := report.GetPicsDir() + "-test-shc"
2022-12-24 11:30:22 +01:00
// attempt to clean up.
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-12-24 11:30:22 +01:00
log.Println("pwd:", os.Getenv("PWD"))
// clean up outdir.
if err := os.RemoveAll("out"); err != nil {
t.Error(err)
}
2022-06-14 22:34:52 +02:00
}