diff --git a/doc.go b/doc.go index 94a075547ee5f8e565bf446357854e17b4a78679..6a69ce73d1808c40b5da4d90841243a811176d2f 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,8 @@ // where input_file is a set of name-value pairs. These are defined with defaults // in rdprm.go. At the moment, we have package main -/* + +/* {"ini_temp", "20"}, {"final_temp", "1"}, {"n_step", "1000"}, diff --git a/main.go b/main.go index 76a936fa54f3914a8ce9c5a83f56f8e55284e701..e69a7cb2973720296bc6e7df00d1aa6cbb6c1355 100644 --- a/main.go +++ b/main.go @@ -21,9 +21,9 @@ const ( ) func main() { - if err := mc_work.MyMain (); err != nil { - fmt.Fprintln (os.Stderr, err) - os.Exit (exitFailure) + if err := mc_work.MyMain(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(exitFailure) } - os.Exit (exitSuccess) + os.Exit(exitSuccess) } diff --git a/mc_work/mc_work.go b/mc_work/mc_work.go index 572fb9ff4218a31d0c4d1ffd43ef149512fa18ff..7b65f85cf1a018eecdd4123734af5b813dedf902 100644 --- a/mc_work/mc_work.go +++ b/mc_work/mc_work.go @@ -8,7 +8,7 @@ import ( "io" "os" - "example.com/ackley_mc/ackley" + "example.com/ackley_mc/ackley" ) type mcPrm struct { diff --git a/mc_work/mc_work_test.go b/mc_work/mc_work_test.go index 89b6067c4c6bc32941b1331ca76a672095f2fca9..0cf25cf6649446f9630f864341ea870bc1f7cede 100644 --- a/mc_work/mc_work_test.go +++ b/mc_work/mc_work_test.go @@ -9,17 +9,16 @@ import ( "testing" ) - var tstTmpDir string func init() { var err error if tstTmpDir, err = os.MkdirTemp(".", "test_tmp*"); err != nil { - fmt.Fprintln (os.Stderr, "Failed to create temporary directory", tstTmpDir) + fmt.Fprintln(os.Stderr, "Failed to create temporary directory", tstTmpDir) os.Exit(1) } } - + func TestErr(t *testing.T) { rdrErr := strings.NewReader("\nrubbish") if err := realmain(rdrErr); err == nil { @@ -39,6 +38,7 @@ func TestTypo(t *testing.T) { // Make sure a typo in input does provoke an error t.Fatal("line with typo should provoke error\n", err, "\nInput", sTypo) } } + type gentest struct{ params, basename string } var set1 = []gentest{ @@ -69,27 +69,26 @@ ini_temp 0.18 final_temp 0.01 x_ini 7,1,7 n_step 100000`, "phasetrans"}, - } // addTestPath makes some of the loops below a bit more readable -func addTestPath (s string) string { - return tstTmpDir + string (os.PathSeparator) + s +func addTestPath(s string) string { + return tstTmpDir + string(os.PathSeparator) + s } // add OutNames uses the basename field and makes output names for // the value and x trajectory plot files and the csv file -func addOutNames (s gentest) string { +func addOutNames(s gentest) string { ret := s.params - for _, ss := range []string {"xPltName", "fOutName"} { + for _, ss := range []string{"xPltName", "fOutName"} { ret += "\n" + ss + " " + addTestPath(s.basename) } ret += "\nfPltName" + " " + addTestPath(s.basename) + "_fval" return ret + "\n" } func Test1(t *testing.T) { - for _, s:= range set1 { + for _, s := range set1 { instring := addOutNames(s) if err := realmain(strings.NewReader(instring)); err != nil { t.Fatal("set1 failed with\n", err, "\nInput:", s) @@ -126,10 +125,10 @@ func TestSetSuffix(t *testing.T) { func TestRemoveQuotes(t *testing.T) { var tdata = []struct { in, out string - } { + }{ {"hello", "hello"}, {"", ""}, - {`"`, ""}, + {`"`, ""}, {`""`, ""}, {`"""`, ""}, {`""a"`, "a"}, @@ -140,8 +139,8 @@ func TestRemoveQuotes(t *testing.T) { {`a""`, "a"}, } for _, ss := range tdata { - if out := RemoveQuotes (ss.in); out != ss.out { - t.Fatalf ("Wanted <%s>, got <%s>. Input was <%s>", ss.out, out, ss.in) + if out := RemoveQuotes(ss.in); out != ss.out { + t.Fatalf("Wanted <%s>, got <%s>. Input was <%s>", ss.out, out, ss.in) } } } diff --git a/mc_work/plot.go b/mc_work/plot.go index f38c9dd6bafb9914c769b1a86d286cae2d0e3fb9..4dc9d3cc57f46103f71e09dbcb28a18e9019acdf 100644 --- a/mc_work/plot.go +++ b/mc_work/plot.go @@ -40,6 +40,7 @@ func maketicks(axisDscrpt axticks.AxisDscrpt) []chart.Tick { } return t } + // maketicks this version works, but usually leaves you wanting one tick more. /*func alt_maketicks(axisDscrpt axticks.AxisDscrpt, prcsn int) []chart.Tick { xmin, xmax, delta, prcsn := axisDscrpt.Xmin, axisDscrpt.Xmax, axisDscrpt.Delta, axisDscrpt.Prcsn @@ -112,7 +113,7 @@ func plotfWrt(cprm *cprm, fname string) error { graph := chart.Chart{ Width: 800, - Title: "cost function", + Title: "cost function", Series: []chart.Series{ chart.ContinuousSeries{ // The function values Name: "cost", diff --git a/mc_work/set_suffix.go b/mc_work/set_suffix.go index 67c13c240a0b44c0938ba342ca512b6d1b242b50..81fc9be31d71eaa3a7d3a5d4900bbdfb69d5deeb 100644 --- a/mc_work/set_suffix.go +++ b/mc_work/set_suffix.go @@ -39,11 +39,11 @@ func setSuffix(fname, suffix string) (string, error) { // removeQuotes removes leading and trailing quotes from a string. // We do not check for single, unmatched quotes. If you want a file // called "fname you should use some other program. -func removeQuotes (s string) string { - for ; len(s) > 0 && s[0] == '"' ;{ +func removeQuotes(s string) string { + for len(s) > 0 && s[0] == '"' { s = s[1:] } - for ; len(s) > 0 && s[len(s)-1] == '"' ; { + for len(s) > 0 && s[len(s)-1] == '"' { s = s[:len(s)-1] } return s diff --git a/nothing_test.go b/nothing_test.go index 9ae26fa4ad62ea0dbfd93ef11b091a2626565081..647dac438a2ddb336c5b785d0ff282cda4d7332b 100644 --- a/nothing_test.go +++ b/nothing_test.go @@ -6,8 +6,8 @@ import ( "testing" ) -func TestNot (t *testing.T) { +func TestNot(t *testing.T) { if false { - t.Fatalf ("banana") + t.Fatalf("banana") } }