MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / TestDictionaryValidate

Function TestDictionaryValidate

go/attribute/attribute_test.go:123–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestDictionaryValidate(t *testing.T) {
124 a := assert.New(t)
125
126 checker := func(i int) error {
127 if i < 0 {
128 return fmt.Errorf("some error")
129 }
130 return nil
131 }
132 tb := Dictionary{}.Int("a", 1, "attribute a", checker).Float("b", float32(1), "attribute b", nil)
133 a.NoError(tb.Validate(map[string]interface{}{"a": 1}))
134 a.EqualError(tb.Validate(map[string]interface{}{"a": -1}), "attribute a error: some error")
135 a.EqualError(tb.Validate(map[string]interface{}{"_a": -1}), fmt.Sprintf(errUnsupportedAttribute, "_a"))
136 a.EqualError(tb.Validate(map[string]interface{}{"a": 1.0}), "attribute a must be of type int, but got float64")
137 a.NoError(tb.Validate(map[string]interface{}{"b": float32(1.0)}))
138 a.NoError(tb.Validate(map[string]interface{}{"b": 1}))
139}
140
141func TestParamsDocs(t *testing.T) {
142 a := assert.New(t)

Callers

nothing calls this directly

Calls 4

ErrorfMethod · 0.80
FloatMethod · 0.80
IntMethod · 0.80
ValidateMethod · 0.80

Tested by

no test coverage detected