1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-28 13:48:56 +08:00
golearn/base/attributes_test.go
2014-08-03 15:16:38 +01:00

52 lines
1.3 KiB
Go

package base
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestFloatAttributeSysVal(t *testing.T) {
Convey("Given some float", t, func() {
x := "1.21"
attr := NewFloatAttribute()
Convey("When the float gets packed", func() {
packed := attr.GetSysValFromString(x)
Convey("And then unpacked", func() {
unpacked := attr.GetStringFromSysVal(packed)
Convey("The unpacked version should be the same", func() {
So(unpacked, ShouldEqual, x)
})
})
})
})
}
func TestCategoricalAttributeVal(t *testing.T) {
attr := NewCategoricalAttribute()
Convey("Given some string", t, func() {
x := "hello world!"
Convey("When the string gets converted", func() {
packed := attr.GetSysValFromString(x)
Convey("And then unconverted", func() {
unpacked := attr.GetStringFromSysVal(packed)
Convey("The unpacked version should be the same", func() {
So(unpacked, ShouldEqual, x)
})
})
})
})
Convey("Given some second string", t, func() {
x := "hello world 1!"
Convey("When the string gets converted", func() {
packed := attr.GetSysValFromString(x)
So(packed[0], ShouldEqual, 0x1)
Convey("And then unconverted", func() {
unpacked := attr.GetStringFromSysVal(packed)
Convey("The unpacked version should be the same", func() {
So(unpacked, ShouldEqual, x)
})
})
})
})
}