-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.go
More file actions
34 lines (26 loc) · 975 Bytes
/
Copy pathfunction.go
File metadata and controls
34 lines (26 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package script
import (
"github.com/dolphindb/api-go/v3/api"
"github.com/dolphindb/api-go/v3/example/util"
"github.com/dolphindb/api-go/v3/logging"
"github.com/dolphindb/api-go/v3/model"
)
// CheckFunction checks whether the RunFunc is valid.
func CheckFunction(db api.DolphinDB) {
l, err := model.NewDataTypeListFromRawData(model.DtDouble, []float64{1.5, 2.5, 7})
util.AssertNil(err)
df, err := db.RunFunc("sum", []model.DataForm{model.NewVector(l)})
util.AssertNil(err)
util.AssertEqual(df.String(), "double(11)")
_, err = db.RunScript("def f(a,b) {return a+b};")
util.AssertNil(err)
arg0, err := model.NewDataType(model.DtInt, int32(1))
util.AssertNil(err)
arg1, err := model.NewDataType(model.DtInt, int32(2))
util.AssertNil(err)
df, err = db.RunFunc("f", []model.DataForm{model.NewScalar(arg0),
model.NewScalar(arg1)})
util.AssertNil(err)
util.AssertEqual(df.String(), "int(3)")
logging.Info("example.script", "check function successful")
}