go: mv util{_test}.go to a separate util pkg
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-10 20:54:48 +02:00
parent c0adff4b78
commit be55fc7d99
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 15 additions and 12 deletions

@ -10,6 +10,7 @@ import (
"time"
"git.dotya.ml/wanderer/math-optim/stats"
"git.dotya.ml/wanderer/math-optim/util"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
@ -88,14 +89,14 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, wg *sync.WaitGro
log.Panic(err)
}
if err := createPath(picPath); err != nil {
if err := util.CreatePath(picPath); err != nil {
log.Println(err)
}
filename := picPath +
fPrefix + "-" +
sanitiseFName(s.Algo) + "-" +
sanitiseFName(dim.BenchName) + "-" +
util.SanitiseFName(s.Algo) + "-" +
util.SanitiseFName(dim.BenchName) + "-" +
fmt.Sprint(s.Dimens) + "D-" +
fmt.Sprint(s.Generations) + "G-" +
fmt.Sprint(len(dim.Solution)) + "I" +

@ -1,7 +1,7 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package algo
package util
import (
"errors"
@ -10,13 +10,15 @@ import (
"strings"
)
func sanitiseFName(s string) string {
// SanitiseFName clears spaces from the string that is supposed to be a file
// name.
func SanitiseFName(s string) string {
return strings.ReplaceAll(s, " ", "_")
}
// createFolder creates a folder at the specified path, if it doesn't already
// CreateFolder creates a folder at the specified path, if it doesn't already
// exist.
func createFolder(path string) error {
func CreateFolder(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
@ -29,9 +31,9 @@ func createFolder(path string) error {
return err
}
// createPath creates all folders in the provided path, if they don't already
// CreatePath creates all folders in the provided path, if they don't already
// exist.
func createPath(path string) error {
func CreatePath(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {

@ -1,7 +1,7 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package algo
package util
import (
"os"
@ -12,7 +12,7 @@ import (
func TestCreateFolder(t *testing.T) {
// let's assume this will never exist in a clean project...
testPath := "whatever-path"
got := createFolder(testPath)
got := CreateFolder(testPath)
var want error
@ -28,7 +28,7 @@ func TestCreatePath(t *testing.T) {
// let's assume this, too, will never exist in a clean project...
testPathRoot := "whatever-path"
testPath := testPathRoot + "/whatever-subpath/subsubpath"
got := createPath(testPath)
got := CreatePath(testPath)
var want error