chore(go): print algo-stamps without errors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-06-17 19:55:23 +02:00
parent b1278f431b
commit ffc8b90e98
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
5 changed files with 22 additions and 21 deletions

@ -4,7 +4,6 @@
package algo package algo
import ( import (
"log"
"sync" "sync"
) )
@ -16,9 +15,7 @@ type Values []float64
func DoRandomSearch(wg *sync.WaitGroup) { func DoRandomSearch(wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
if err := printRandomSearch("starting..."); err != nil { printRandomSearch("starting...")
log.Printf("randomSearch: error printing RandomSearch to stderr: %q", err)
}
} }
// DoStochasticHillClimbing performs a search using the 'Stochastic Hill // DoStochasticHillClimbing performs a search using the 'Stochastic Hill
@ -26,7 +23,5 @@ func DoRandomSearch(wg *sync.WaitGroup) {
func DoStochasticHillClimbing(wg *sync.WaitGroup) { func DoStochasticHillClimbing(wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
if err := printSHC("starting..."); err != nil { printSHC("starting...")
log.Printf("shc: error printing SHC to stderr: %q", err)
}
} }

@ -20,10 +20,15 @@ func fmtRandomSearchOut(input string) string {
return getRandomSearchLogPrefix() + " " + input return getRandomSearchLogPrefix() + " " + input
} }
func printRandomSearch(input string) error { func printRandomSearch(input string) {
_, err := fmt.Fprintln(os.Stderr, fmtRandomSearchOut(input)) if _, err := fmt.Fprintln(os.Stderr, fmtRandomSearchOut(input)); err != nil {
fmt.Fprintf(
return err os.Stdout,
getRandomSearchLogPrefix(),
"error while printing to stderr: %q\n * original message was: %q",
err, input,
)
}
} }
func genValsRandomSearch(dimens uint, vals []float64, uniform *distuv.Uniform) { func genValsRandomSearch(dimens uint, vals []float64, uniform *distuv.Uniform) {

@ -15,7 +15,5 @@ func TestFmtRandomSearchOut(t *testing.T) {
} }
func TestPrintRandomSearch(t *testing.T) { func TestPrintRandomSearch(t *testing.T) {
if err := printRandomSearch("whatever"); err != nil { printRandomSearch("whatever")
t.Errorf("error while printing to stderr: %q", err)
}
} }

@ -16,8 +16,13 @@ func fmtSHCOut(input string) string {
return getSHCLogPrefix() + " " + input return getSHCLogPrefix() + " " + input
} }
func printSHC(input string) error { func printSHC(input string) {
_, err := fmt.Fprintln(os.Stderr, fmtSHCOut(input)) if _, err := fmt.Fprintln(os.Stderr, fmtSHCOut(input)); err != nil {
fmt.Fprintf(
return err os.Stdout,
getSHCLogPrefix(),
"error while printing to stderr: %q\n * original message was: %q",
err, input,
)
}
} }

@ -15,7 +15,5 @@ func TestFmtSHCOut(t *testing.T) {
} }
func TestPrintSHC(t *testing.T) { func TestPrintSHC(t *testing.T) {
if err := printSHC("whatever"); err != nil { printSHC("whatever")
t.Errorf("error while printing to stderr: %q", err)
}
} }