Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ackley_mc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
ackley_mc
Commits
9cff8eaa
Commit
9cff8eaa
authored
3 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Used to have a function for appending png filenames. Now more general.
parent
a925ff8b
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ackwork/ackwork_test.go
+30
-10
30 additions, 10 deletions
ackwork/ackwork_test.go
ackwork/dorun.go
+4
-1
4 additions, 1 deletion
ackwork/dorun.go
ackwork/export_test.go
+1
-1
1 addition, 1 deletion
ackwork/export_test.go
ackwork/plot.go
+34
-3
34 additions, 3 deletions
ackwork/plot.go
with
69 additions
and
15 deletions
ackwork/ackwork_test.go
+
30
−
10
View file @
9cff8eaa
...
...
@@ -138,20 +138,40 @@ func TestPlot(t *testing.T) {
}
}
func
Test
MakepngName
(
t
*
testing
.
T
)
{
func
Test
SetSuffix
(
t
*
testing
.
T
)
{
var
tdata
=
[]
struct
{
in
string
out
string
in
,
suffix
,
want
string
}{
{
"boo"
,
"boo.png"
},
{
"boo."
,
"boo.png"
},
{
"a.png"
,
"a.png"
},
{
"/boo/foo/a.PNG"
,
"/boo/foo/a.PNG"
},
{
"a/b/c/d.svg"
,
"a/b/c/d.png"
},
{
"boo."
,
".csv"
,
"boo.csv"
},
//xxx
{
"boo"
,
"csv"
,
"boo.csv"
},
{
"boo."
,
"csv"
,
"boo.csv"
},
{
"boo"
,
".csv"
,
"boo.csv"
},
{
"boo.csv"
,
".csv"
,
"boo.csv"
},
{
"/boo/blah/boo"
,
".csv"
,
"/boo/blah/boo.csv"
},
{
"/a/b/c.svg"
,
".png"
,
"/a/b/c.png"
},
{
"boo."
,
""
,
"boo"
},
{
"boo"
,
""
,
"boo"
},
}
for
_
,
s
:=
range
tdata
{
if
tmp
,
err
:=
SetSuffix
(
s
.
in
,
s
.
suffix
);
err
!=
nil
{
t
.
Fatal
(
"setSuffix error handling"
,
s
)
}
else
{
if
tmp
!=
s
.
want
{
t
.
Fatal
(
"Wanted"
,
s
.
want
,
"got"
,
tmp
,
"working on"
,
s
)
}
}
}
}
// Check that errors are generated
func
TestSetSuffixErr
(
t
*
testing
.
T
)
{
var
tdata
=
[]
struct
{
in
,
suffix
string
}{
{
""
,
""
},
{
"."
,
""
}
}
for
_
,
s
:=
range
tdata
{
if
tmp
:=
MakepngName
(
s
.
in
);
tmp
!=
s
.
out
{
t
.
Fatal
(
"
Wanted"
,
s
.
ou
t
,
"got"
,
tmp
)
if
_
,
err
:=
SetSuffix
(
s
.
in
,
s
.
suffix
);
err
==
nil
{
t
.
Fatal
(
"
setSuffix
s
h
ou
ld return error on"
,
s
)
}
}
}
This diff is collapsed.
Click to expand it.
ackwork/dorun.go
+
4
−
1
View file @
9cff8eaa
...
...
@@ -71,7 +71,10 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
return
err
}
if
mcPrm
.
fPltName
!=
""
{
mcPrm
.
fPltName
=
makepngName
(
mcPrm
.
fPltName
)
var
err
error
if
mcPrm
.
fPltName
,
err
=
setSuffix
(
mcPrm
.
fPltName
,
".png"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"plot filename: %w"
,
err
)
}
if
cprm
.
fPlt
,
err
=
os
.
Create
(
mcPrm
.
fPltName
);
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
ackwork/export_test.go
+
1
−
1
View file @
9cff8eaa
package
ackwork
var
MakepngName
=
makepngName
var
SetSuffix
=
setSuffix
This diff is collapsed.
Click to expand it.
ackwork/plot.go
+
34
−
3
View file @
9cff8eaa
...
...
@@ -6,6 +6,7 @@
package
ackwork
import
(
"errors"
"fmt"
"io"
"math"
...
...
@@ -20,7 +21,7 @@ import (
// If it ends in something else, replace the ending with png.
// We have stalinistically decided that we will only write png output.
// svg is nicer, but the files can become silly big.
func
makepngName
(
fname
string
)
string
{
func
X
makepngName
(
fname
string
)
string
{
const
dotpng
=
".png"
ext
:=
filepath
.
Ext
(
fname
)
switch
ext
{
...
...
@@ -36,6 +37,36 @@ func makepngName(fname string) string {
return
"hello"
}
// setSuffix takes a name and makes sure the desired suffix is at the end
// of the filename.
func
setSuffix
(
fname
,
suffix
string
)
(
string
,
error
)
{
if
len
(
fname
)
==
0
{
return
""
,
errors
.
New
(
"setSuffix given empty fname"
)
}
if
suffix
==
""
{
// no suffix might not be an error. Just
if
fname
[
len
(
fname
)
-
1
]
==
'.'
{
// remove any trailing dot
fname
=
fname
[
0
:
len
(
fname
)
-
1
]
}
if
len
(
fname
)
>
0
{
return
fname
,
nil
}
return
""
,
errors
.
New
(
"setSuffix got empty filename"
)
}
if
suffix
[
0
]
!=
'.'
{
suffix
=
"."
+
suffix
}
oldExt
:=
filepath
.
Ext
(
fname
)
switch
oldExt
{
case
suffix
:
return
fname
,
nil
case
""
:
return
fname
+
suffix
,
nil
default
:
return
fname
[
0
:
len
(
fname
)
-
len
(
oldExt
)]
+
suffix
,
nil
}
}
// maketicks gives reasonable default tick locations
func
maketicks
(
axisDscrpt
axticks
.
AxisDscrpt
,
prcsn
int
)
[]
chart
.
Tick
{
xmin
,
delta
,
prcsn
:=
axisDscrpt
.
Xmin
,
axisDscrpt
.
Delta
,
axisDscrpt
.
Prcsn
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment