room_feature_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import (
  3. "reflect"
  4. "testing"
  5. "flag"
  6. . "github.com/smartystreets/goconvey/convey"
  7. "go-common/app/service/live/recommend/internal/conf"
  8. )
  9. func init() {
  10. flag.Set("conf", "../../cmd/test.toml")
  11. var err error
  12. if err = conf.Init(); err != nil {
  13. panic(err)
  14. }
  15. }
  16. func TestOneHotTextEncode(t *testing.T) {
  17. Convey("oneHotTextEncode", t, func() {
  18. arr := oneHotTextEncode("", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  19. So(reflect.DeepEqual(arr, []int64{1, 0, 0, 0, 0, 0}), ShouldBeTrue)
  20. arr = oneHotTextEncode("23人存活", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  21. So(reflect.DeepEqual(arr, []int64{0, 1, 0, 0, 0, 0}), ShouldBeTrue)
  22. arr = oneHotTextEncode("决赛圈", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  23. So(reflect.DeepEqual(arr, []int64{0, 0, 1, 0, 0, 0}), ShouldBeTrue)
  24. arr = oneHotTextEncode("正在抽奖", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  25. So(reflect.DeepEqual(arr, []int64{0, 0, 0, 1, 0, 0}), ShouldBeTrue)
  26. arr = oneHotTextEncode("上小时电台No.1", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  27. So(reflect.DeepEqual(arr, []int64{0, 0, 0, 0, 1, 0}), ShouldBeTrue)
  28. arr = oneHotTextEncode("年度五强主播", []string{"", ".*人存活", "决赛圈", "正在抽奖", ".*No\\.\\d+", "年度.*主播"})
  29. So(reflect.DeepEqual(arr, []int64{0, 0, 0, 0, 0, 1}), ShouldBeTrue)
  30. })
  31. }
  32. func TestOneHotEncode(t *testing.T) {
  33. Convey("oneHotEncode", t, func() {
  34. arr := oneHotEncode(78, []int64{23, 54, 100, 120})
  35. So(reflect.DeepEqual(arr, []int64{0, 0, 1, 0, 0}), ShouldBeTrue)
  36. arr = oneHotEncode(7, []int64{23, 54, 100, 120})
  37. So(reflect.DeepEqual(arr, []int64{1, 0, 0, 0, 0}), ShouldBeTrue)
  38. arr = oneHotEncode(200, []int64{23, 54, 100, 120})
  39. So(reflect.DeepEqual(arr, []int64{0, 0, 0, 0, 1}), ShouldBeTrue)
  40. })
  41. }
  42. func TestSliceArray(t *testing.T) {
  43. Convey("sliceArray", t, func() {
  44. arr := sliceArray([]int64{1, 2, 3, 4, 5, 6, 7, 8, 9}, 4)
  45. So(reflect.DeepEqual(arr[0], []int64{1, 2, 3, 4}), ShouldBeTrue)
  46. So(reflect.DeepEqual(arr[1], []int64{5, 6, 7, 8}), ShouldBeTrue)
  47. So(reflect.DeepEqual(arr[2], []int64{9}), ShouldBeTrue)
  48. })
  49. }
  50. func TestCreateRoomFeature(t *testing.T) {
  51. Convey("createRoomFeature", t, func() {
  52. c := conf.Conf
  53. arr := createFeature(c, 21, "决赛圈", 2000, 1000)
  54. So(reflect.DeepEqual(arr, []int64{21, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}), ShouldBeTrue)
  55. })
  56. }