refactored data-types to reduce plugin sizes
This commit is contained in:
+19
-17
@@ -7,7 +7,8 @@ package expr
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/types/fract"
|
||||
"git.portale-stac.it/go-pkg/expr/types/list"
|
||||
)
|
||||
|
||||
func TestFuncBase(t *testing.T) {
|
||||
@@ -35,10 +36,10 @@ func TestFuncBase(t *testing.T) {
|
||||
/* 19 */ {`isFract(1:3)`, true, nil},
|
||||
/* 20 */ {`isFract(3:1)`, false, nil},
|
||||
/* 21 */ {`isRational(3:1)`, true, nil},
|
||||
/* 22 */ {`fract("2.2(3)")`, kern.NewFraction(67, 30), nil},
|
||||
/* 23 */ {`fract("1.21(3)")`, kern.NewFraction(91, 75), nil},
|
||||
/* 24 */ {`fract(1.21(3))`, kern.NewFraction(91, 75), nil},
|
||||
/* 25 */ {`fract(1.21)`, kern.NewFraction(121, 100), nil},
|
||||
/* 22 */ {`fract("2.2(3)")`, fract.NewFraction(67, 30), nil},
|
||||
/* 23 */ {`fract("1.21(3)")`, fract.NewFraction(91, 75), nil},
|
||||
/* 24 */ {`fract(1.21(3))`, fract.NewFraction(91, 75), nil},
|
||||
/* 25 */ {`fract(1.21)`, fract.NewFraction(121, 100), nil},
|
||||
/* 26 */ {`dec(2)`, float64(2), nil},
|
||||
/* 27 */ {`dec(2.0)`, float64(2), nil},
|
||||
/* 28 */ {`dec("2.0")`, float64(2), nil},
|
||||
@@ -47,8 +48,8 @@ func TestFuncBase(t *testing.T) {
|
||||
/* 31 */ {`dec()`, nil, `dec(): too few params -- expected 1, got 0`},
|
||||
/* 32 */ {`dec(1,2,3)`, nil, `dec(): too many params -- expected 1, got 3`},
|
||||
/* 33 */ {`isBool(false)`, true, nil},
|
||||
/* 34 */ {`fract(1:2)`, kern.NewFraction(1, 2), nil},
|
||||
/* 35 */ {`fract(12,2)`, kern.NewFraction(6, 1), nil},
|
||||
/* 34 */ {`fract(1:2)`, fract.NewFraction(1, 2), nil},
|
||||
/* 35 */ {`fract(12,2)`, fract.NewFraction(6, 1), nil},
|
||||
/* 36 */ {`bool(2)`, true, nil},
|
||||
/* 37 */ {`bool(1:2)`, true, nil},
|
||||
/* 38 */ {`bool(1.0)`, true, nil},
|
||||
@@ -60,7 +61,7 @@ func TestFuncBase(t *testing.T) {
|
||||
/* 44 */ {`bool({1:"one"})`, true, nil},
|
||||
/* 45 */ {`dec(false)`, float64(0), nil},
|
||||
/* 46 */ {`dec(1:2)`, float64(0.5), nil},
|
||||
/* 47 */ {`dec([1])`, nil, `dec(): can't convert list to float`},
|
||||
/* 47 */ {`dec([1])`, nil, `dec(): can't convert array to float`},
|
||||
/* 48 */ {`eval("a=3"); a`, int64(3), nil},
|
||||
/* 49 */ {`int(5:2)`, int64(2), nil},
|
||||
|
||||
@@ -95,20 +96,21 @@ func TestFuncBaseFraction(t *testing.T) {
|
||||
section := "Builtin-Base-Fraction"
|
||||
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`fract(-0.5)`, kern.NewFraction(-1, 2), nil},
|
||||
/* 2 */ {`fract("")`, (*kern.FractionType)(nil), `bad syntax`},
|
||||
/* 3 */ {`fract("-1")`, kern.NewFraction(-1, 1), nil},
|
||||
/* 4 */ {`fract("+1")`, kern.NewFraction(1, 1), nil},
|
||||
/* 5 */ {`fract("1a")`, (*kern.FractionType)(nil), `strconv.ParseInt: parsing "1a": invalid syntax`},
|
||||
/* 1 */ {`fract(-0.5)`, fract.NewFraction(-1, 2), nil},
|
||||
/* 2 */ {`fract("")`, (*fract.FractionType)(nil), `bad syntax`},
|
||||
/* 3 */ {`fract("-1")`, fract.NewFraction(-1, 1), nil},
|
||||
/* 4 */ {`fract("+1")`, fract.NewFraction(1, 1), nil},
|
||||
/* 5 */ {`fract("1a")`, (*fract.FractionType)(nil), `strconv.ParseInt: parsing "1a": invalid syntax`},
|
||||
/* 6 */ {`fract(1,0)`, nil, `fract(): division by zero`},
|
||||
/* 7 */ {`fract(5, "1")`, nil, `fract(): expected integer, got string ("1")`},
|
||||
/* 8 */ {`fract(true)`, kern.NewFraction(1, 1), nil},
|
||||
/* 9 */ {`fract(false)`, kern.NewFraction(0, 1), nil},
|
||||
/* 8 */ {`fract(true)`, fract.NewFraction(1, 1), nil},
|
||||
/* 9 */ {`fract(false)`, fract.NewFraction(0, 1), nil},
|
||||
/* 10 */ {`1.2(3)`, fract.NewFraction(37, 30), nil},
|
||||
}
|
||||
|
||||
// t.Setenv("EXPR_PATH", ".")
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 8)
|
||||
// runTestSuiteSpec(t, section, inputs, 5)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
@@ -118,7 +120,7 @@ func TestFuncBaseOthers(t *testing.T) {
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`set("a", 3); a`, int64(3), nil},
|
||||
/* 2 */ {`set(true, 3)`, nil, `set(): the "name" parameter must be a string, got a bool (true)`},
|
||||
/* 3 */ {`seq(1,2,3)`, kern.NewLinkedListA(int64(1), int64(2), int64(3)), nil},
|
||||
/* 3 */ {`seq(1,2,3)`, list.NewLinkedListA(int64(1), int64(2), int64(3)), nil},
|
||||
// /* 4 */ {`seq(1,2,4)`, kern.NewLinkedListA(int64(1), int64(2), int64(3)), nil},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user