本文整理汇总了Golang中github.com/cpmech/gosl/chk.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Test_ind01
func Test_ind01(tst *testing.T) {
//verbose()
chk.PrintTitle("ind01. representation and copying")
rnd.Init(0)
nbases := 3
A := get_individual(0, nbases)
B := A.GetCopy()
chk.Scalar(tst, "ova0", 1e-17, B.Ovas[0], 123)
chk.Scalar(tst, "ova1", 1e-17, B.Ovas[1], 345)
chk.Scalar(tst, "oor0", 1e-17, B.Oors[0], 10)
chk.Scalar(tst, "oor1", 1e-17, B.Oors[1], 20)
chk.Scalar(tst, "oor2", 1e-17, B.Oors[2], 30)
fmts := map[string][]string{"int": {" %d"}, "flt": {" %.1f"}, "str": {" %q"}, "key": {" %x"}, "byt": {" %q"}, "fun": {" %q"}}
oA := A.Output(fmts, false)
oB := B.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
io.Pfyel("%v\n\n", oB)
chk.String(tst, oA, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
chk.String(tst, oB, " 1 20 300 4.4 5.5 666.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
A.SetFloat(1, 33)
A.SetFloat(2, 88)
oA = A.Output(fmts, false)
io.Pfyel("\n%v\n", oA)
chk.String(tst, oA, " 1 20 300 4.4 33.0 88.0 \"abc\" \"b\" \"c\" 53 47 41 \"ABC\" \"DEF\" \"GHI\" \"f0\" \"f1\" \"f2\"")
}
开发者ID:postfix,项目名称:goga-1,代码行数:31,代码来源:t_individual_test.go
示例2: Test_parsing03
func Test_parsing03(tst *testing.T) {
//verbose()
chk.PrintTitle("parsing03")
keys := []string{"ux", "uy", "uz", "pl", "sl"}
k1, k2, k3 := []string{"ex1", "ex2"}, []string{"more1", "more2"}, []string{"a", "b", "c"}
allkeys := JoinKeys4(keys, k1, k2, k3, "")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl ex1 ex2 more1 more2 a b c")
allkeys = JoinKeys4(keys, k1, k2, k3, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl, ex1 ex2, more1 more2, a b c")
r0, r1, r2, r3 := SplitKeys4(allkeys)
Pfblue2("r0 = %v\n", r0)
Pfblue2("r1 = %v\n", r1)
Pfblue2("r2 = %v\n", r2)
Pfblue2("r3 = %v\n", r3)
chk.Strings(tst, "r0", r0, keys)
chk.Strings(tst, "r1", r1, k1)
chk.Strings(tst, "r2", r2, k2)
chk.Strings(tst, "r3", r3, k3)
allkeys = JoinKeys4(keys, []string{}, k2, []string{}, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl,, more1 more2,")
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:29,代码来源:t_parsing_test.go
示例3: Test_args01
func Test_args01(tst *testing.T) {
//verbose()
chk.PrintTitle("args01")
fn, fnk := ArgToFilename(0, "simulation", ".sim", true)
Pforan("fn = %v\n", fn)
Pforan("fnk = %v\n", fnk)
chk.String(tst, fn, "simulation.sim")
chk.String(tst, fnk, "simulation")
resFloat := ArgToFloat(1, 456)
chk.Scalar(tst, "456", 1e-17, resFloat, 456)
resInt := ArgToInt(1, 123)
if resInt != 123 {
tst.Errorf("test failed: resInt != 123\n")
return
}
resBool := ArgToBool(1, true)
if !resBool {
tst.Errorf("test failed: resBool != true\n")
return
}
resString := ArgToString(1, "myname")
chk.String(tst, resString, "myname")
tab := ArgsTable(
"1 2 3 INPUT PARAMETERS 3 2 1",
"first argument", "first", true,
"second argument", "second", "string",
"third argument", "third", 123,
"fourth argument", "fourth", 666.0,
)
Pf("\n%v\n", tab)
chk.String(tst, tab,
` 1 2 3 INPUT PARAMETERS 3 2 1
===================================
description key value
-----------------------------------
first argument first true
second argument second string
third argument third 123
fourth argument fourth 666
===================================
`)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:51,代码来源:t_args_test.go
示例4: Test_parsing02
func Test_parsing02(tst *testing.T) {
//verbose()
chk.PrintTitle("parsing02")
keys := []string{"ux", "uy", "uz", "pl", "sl"}
skeys := JoinKeys(keys)
kkeys := SplitKeys(skeys)
Pforan("keys = %+v\n", keys)
Pforan("skeys = %q\n", skeys)
Pforan("kkeys = %+v\n", kkeys)
chk.Strings(tst, "keys", keys, kkeys)
k1, k2 := []string{"ex1", "ex2"}, []string{"more1", "more2"}
allkeys := JoinKeys3(keys, k1, k2, "")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl ex1 ex2 more1 more2")
allkeys = JoinKeys3(keys, k1, k2, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl, ex1 ex2, more1 more2")
r0, r1, r2 := SplitKeys3(allkeys)
Pfblue2("r0 = %v\n", r0)
Pfblue2("r1 = %v\n", r1)
Pfblue2("r2 = %v\n", r2)
chk.Strings(tst, "r0", r0, keys)
chk.Strings(tst, "r1", r1, k1)
chk.Strings(tst, "r2", r2, k2)
allkeys = JoinKeys3(keys, []string{}, k2, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl,, more1 more2")
allkeys = JoinKeys3(keys, []string{}, []string{}, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, "ux uy uz pl sl,,")
allkeys = JoinKeys3([]string{}, k1, k2, ",")
Pfpink("allkeys = %q\n", allkeys)
chk.String(tst, allkeys, ", ex1 ex2, more1 more2")
r0, r1, r2 = SplitKeys3("a ,b c,")
Pfblue2("r0 = %v\n", r0)
Pfblue2("r1 = %v\n", r1)
Pfblue2("r2 = %v\n", r2)
chk.Strings(tst, "r0", r0, []string{"a"})
chk.Strings(tst, "r1", r1, []string{"b", "c"})
chk.Strings(tst, "r2", r2, []string{})
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:50,代码来源:t_parsing_test.go
示例5: Test_parsing05
func Test_parsing05(tst *testing.T) {
//verbose()
chk.PrintTitle("parsing05. split by spaces quoted")
str := " arg1 arg2 ' hello world' '' \" another hello world \" "
res := SplitSpacesQuoted(str)
Pforan("res = %q\n", res)
chk.String(tst, res[0], "arg1")
chk.String(tst, res[1], "arg2")
chk.String(tst, res[2], "' hello world'")
chk.String(tst, res[3], "''")
chk.String(tst, res[4], "\" another hello world \"")
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:14,代码来源:t_parsing_test.go
示例6: checkinput
func checkinput(tst *testing.T, m *Mesh, nverts, ncells int, X [][]float64, vtags, ctags, parts []int, types []string, V [][]int, etags, ftags [][]int) {
if len(m.Verts) != nverts {
tst.Errorf("nverts is incorrect: %d != %d", len(m.Verts), nverts)
return
}
if len(m.Cells) != ncells {
tst.Errorf("ncells is incorrect: %d != %d", len(m.Cells), ncells)
return
}
io.Pfyel("\nvertices:\n")
for i, v := range m.Verts {
io.Pf("%+v\n", v)
chk.Vector(tst, io.Sf("vertex %2d: X", v.Id), 1e-15, v.X, X[v.Id])
if v.Tag != vtags[i] {
tst.Errorf("vtag is incorrect: %d != %d", v.Tag, vtags[i])
return
}
}
io.Pfyel("\ncells:\n")
for i, c := range m.Cells {
io.Pf("%+v\n", c)
if c.Tag != ctags[i] {
tst.Errorf("ctag is incorrect: %d != %d", c.Tag, ctags[i])
return
}
if c.Part != parts[i] {
tst.Errorf("part is incorrect: %d != %d", c.Part, parts[i])
return
}
chk.String(tst, types[i], c.Type)
chk.Ints(tst, io.Sf("cell %2d : V", c.Id), c.V, V[c.Id])
chk.Ints(tst, io.Sf("cell %2d : edgetags", c.Id), c.EdgeTags, etags[c.Id])
}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:34,代码来源:t_mesh_test.go
示例7: Test_basic02
func Test_basic02(tst *testing.T) {
//verbose()
chk.PrintTitle("basic02")
res := IntSf("%4d", []int{1, 2, 3}) // note that an inner space is always added
Pforan("res = %q\n", res)
chk.String(tst, res, " 1 2 3")
res = DblSf("%8.3f", []float64{1, 2, 3}) // note that an inner space is always added
Pforan("res = %q\n", res)
chk.String(tst, res, " 1.000 2.000 3.000")
res = StrSf("%s", []string{"a", "b", "c"}) // note that an inner space is always added
Pforan("res = %q\n", res)
chk.String(tst, res, "a b c")
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:17,代码来源:t_basic_test.go
示例8: Test_parsing06
func Test_parsing06(tst *testing.T) {
//verbose()
chk.PrintTitle("parsing06. extract within brackets")
str := "(arg1, (arg2.1, arg2.2), arg3, arg4, (arg5.1,arg5.2, arg5.3 ) )"
res := SplitWithinParentheses(str)
Pforan("%q\n", str)
for _, r := range res {
Pf("%q\n", r)
}
chk.String(tst, res[0], "arg1")
chk.String(tst, res[1], "arg2.1 arg2.2")
chk.String(tst, res[2], "arg3")
chk.String(tst, res[3], "arg4")
chk.String(tst, res[4], "arg5.1 arg5.2 arg5.3 ")
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:17,代码来源:t_parsing_test.go
示例9: Test_draw02
func Test_draw02(tst *testing.T) {
chk.PrintTitle("draw02")
d := Fmt{"red", "o", "--", 1.2, -1, "gofem", 2}
l := d.GetArgs("clip_on=0")
io.Pforan("l = %q\n", l)
chk.String(tst, l, "clip_on=0,color='red',marker='o',ls='--',lw=1.2,label='gofem',markevery=2")
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:9,代码来源:t_drawing_test.go
示例10: Test_ind02
func Test_ind02(tst *testing.T) {
//verbose()
chk.PrintTitle("ind02. copy into")
rnd.Init(0)
nbases := 1
A := get_individual(0, nbases)
B := get_individual(1, nbases)
fmts := map[string][]string{
"int": {"%2d", "%4d", "%5d"}, // ints
"flt": {"%6g", "%6g", "%5g"}, // floats
"str": {"%4s", "%2s", "%2s"}, // strings
"key": {"%3x", "%3x", "%3x"}, // keys
"byt": {"%4s", "%4s", "%4s"}, // bytes
"fun": {"%3s", "%3s", "%3s"}, // funcs
}
io.Pfpink("A = %v\n", A.Output(fmts, false))
io.Pfcyan("B = %v\n", B.Output(fmts, false))
var ops OpsData
ops.SetDefault()
ops.Pc = 1.0
ops.Cuts = []int{1, 2}
ops.Xrange = [][]float64{{0, 1}, {-20, 20}, {-300, 300}}
a := A.GetCopy()
b := A.GetCopy()
IndCrossover(a, b, A, B, 0, &ops)
io.Pforan("a = %v\n", a.Output(fmts, false))
io.Pfblue2("b = %v\n", b.Output(fmts, false))
chk.Ints(tst, "a.Ints ", a.Ints, []int{1, -20, 300})
chk.Ints(tst, "b.Ints ", b.Ints, []int{-1, 20, -300})
chk.Strings(tst, "a.Strings", a.Strings, []string{"abc", "Y", "c"})
chk.Strings(tst, "b.Strings", b.Strings, []string{"X", "b", "Z"})
// TODO: add other tests here
io.Pf("\n")
x := get_individual(0, nbases)
x.Ovas = []float64{0, 0}
x.Oors = []float64{0, 0, 0}
io.Pfblue2("x = %v\n", x.Output(fmts, false))
B.CopyInto(x)
chk.Scalar(tst, "ova0", 1e-17, x.Ovas[0], 200)
chk.Scalar(tst, "ova1", 1e-17, x.Ovas[1], 100)
chk.Scalar(tst, "oor0", 1e-17, x.Oors[0], 15)
chk.Scalar(tst, "oor1", 1e-17, x.Oors[1], 25)
chk.Scalar(tst, "oor2", 1e-17, x.Oors[2], 35)
io.Pforan("x = %v\n", x.Output(fmts, false))
chk.String(tst, x.Output(fmts, false), B.Output(fmts, false))
}
开发者ID:postfix,项目名称:goga-1,代码行数:57,代码来源:t_individual_test.go
示例11: Test_texreport01
func Test_texreport01(tst *testing.T) {
//verbose()
chk.PrintTitle("texreport01")
l1 := TexNum("", 123.456, true)
l2 := TexNum("", 123.456e-8, true)
l3 := TexNum("%.1e", 123.456e+8, true)
l4 := TexNum("%.2e", 123.456e-8, false)
Pforan("l1 = %v\n", l1)
Pforan("l2 = %v\n", l2)
Pforan("l3 = %v\n", l3)
Pforan("l4 = %v\n", l4)
chk.String(tst, l1, "123.456")
chk.String(tst, l2, "1.23456\\cdot 10^{-6}")
chk.String(tst, l3, "1.2\\cdot 10^{10}")
chk.String(tst, l4, "1.23e-06")
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:18,代码来源:t_texreport_test.go
示例12: Test_parsing04
func Test_parsing04(tst *testing.T) {
//verbose()
chk.PrintTitle("parsing04")
keys := []string{"ux", "uy", "uz"}
skeys := JoinKeysPre("R", keys)
Pforan("keys = %+v\n", keys)
Pforan("skeys = %q\n", skeys)
chk.String(tst, skeys, "Rux Ruy Ruz")
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:11,代码来源:t_parsing_test.go
示例13: Test_args01
func Test_args01(tst *testing.T) {
//verbose()
chk.PrintTitle("args01")
fn, fnk := ArgToFilename(0, "simulation", ".sim", true)
Pforan("fn = %v\n", fn)
Pforan("fnk = %v\n", fnk)
chk.String(tst, fn, "simulation.sim")
chk.String(tst, fnk, "simulation")
resFloat := ArgToFloat(1, 456)
chk.Scalar(tst, "456", 1e-17, resFloat, 456)
resInt := ArgToInt(1, 123)
if resInt != 123 {
tst.Errorf("test failed: resInt != 123\n")
return
}
resBool := ArgToBool(1, true)
if !resBool {
tst.Errorf("test failed: resBool != true\n")
return
}
resString := ArgToString(1, "myname")
chk.String(tst, resString, "myname")
Pf("\n%v\n", ArgsTable(
"first argument", "first", true,
"second argument", "second", "string",
"third argument", "third", 123,
"fourth argument", "fourth", 666.0,
))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:36,代码来源:t_args_test.go
示例14: Test_fileIO4
func Test_fileIO4(tst *testing.T) {
//verbose()
chk.PrintTitle("fileIO4")
theline := "Hello World !!!"
WriteFileSD("/tmp/gosl", "filestring.txt", theline)
f, err := OpenFileR("/tmp/gosl/filestring.txt")
if err != nil {
chk.Panic("%v", err)
}
ReadLinesFile(f, func(idx int, line string) (stop bool) {
Pforan("line = %v\n", line)
chk.String(tst, line, theline)
return
})
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:19,代码来源:t_fileio_test.go
示例15: Test_encoder01
func Test_encoder01(tst *testing.T) {
//verbose()
chk.PrintTitle("encoder01")
// writer and encoder
var w test_writer
enc := GetEncoder(&w, "json")
s_in := test_struct{A: 1, B: 2}
enc.Encode(&s_in)
io.Pforan("w = %q\n", string(w))
chk.String(tst, "{\"A\":1,\"B\":2}\n", string(w))
// reader and decoder
var r test_reader
dec := GetDecoder(&r, "json")
var s_out test_struct
dec.Decode(&s_out)
io.Pforan("r = %v\n", r)
// TODO: implement test here
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:21,代码来源:t_encoder_test.go
示例16: Test_fileIO1
func Test_fileIO1(tst *testing.T) {
//verbose()
chk.PrintTitle("fileIO1")
fn := "test/user/file.sim"
chk.String(tst, "file.sim", filepath.Base(fn))
chk.String(tst, ".sim", filepath.Ext(fn))
chk.String(tst, "file", FnKey(fn))
chk.String(tst, ".sim", FnExt(fn))
chk.String(tst, "test/user/file", PathKey(fn))
gn := "test/user/file.h5"
chk.String(tst, "file.h5", filepath.Base(gn))
chk.String(tst, ".h5", filepath.Ext(gn))
chk.String(tst, "file", FnKey(gn))
chk.String(tst, ".h5", FnExt(gn))
chk.String(tst, "test/user/file", PathKey(gn))
Pf("\n")
Pf("fn = %s\n", fn)
Pf("base = %s\n", filepath.Base(fn))
Pf("ext = %s\n", filepath.Ext(fn))
Pf("fnk = %s\n", FnKey(fn))
Pf("\n")
fn = "test/user/file"
chk.String(tst, "file", filepath.Base(fn))
chk.String(tst, "", filepath.Ext(fn))
chk.String(tst, "file", FnKey(fn))
chk.String(tst, "test/user/file", PathKey(fn))
Pf("\n")
Pf("fn = %s\n", fn)
Pf("base = %s\n", filepath.Base(fn))
Pf("ext = %s\n", filepath.Ext(fn))
Pf("fnk = %s\n", FnKey(fn))
Pf("\n")
fn = "test/user/file."
chk.String(tst, "file.", filepath.Base(fn))
chk.String(tst, ".", filepath.Ext(fn))
chk.String(tst, "file", FnKey(fn))
chk.String(tst, "test/user/file", PathKey(fn))
Pf("\n")
Pf("fn = %s\n", fn)
Pf("base = %s\n", filepath.Base(fn))
Pf("ext = %s\n", filepath.Ext(fn))
Pf("fnk = %s\n", FnKey(fn))
Pf("\n")
fn = "test/user/f.extension"
chk.String(tst, "f.extension", filepath.Base(fn))
chk.String(tst, ".extension", filepath.Ext(fn))
chk.String(tst, "f", FnKey(fn))
chk.String(tst, "test/user/f", PathKey(fn))
Pf("\n")
Pf("fn = %s\n", fn)
Pf("base = %s\n", filepath.Base(fn))
Pf("ext = %s\n", filepath.Ext(fn))
Pf("fnk = %s\n", FnKey(fn))
Pf("pathkey = %s\n", PathKey(fn))
Pf("\n")
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:66,代码来源:t_fileio_test.go
注:本文中的github.com/cpmech/gosl/chk.String函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论