util_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 gorse Project Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package base
  15. import (
  16. "testing"
  17. "github.com/stretchr/testify/assert"
  18. )
  19. func TestNewMatrix32(t *testing.T) {
  20. a := NewMatrix32(3, 4)
  21. assert.Equal(t, 3, len(a))
  22. assert.Equal(t, 4, len(a[0]))
  23. assert.Equal(t, 4, len(a[0]))
  24. assert.Equal(t, 4, len(a[0]))
  25. }
  26. func TestRangeInt(t *testing.T) {
  27. a := RangeInt(7)
  28. assert.Equal(t, 7, len(a))
  29. for i := range a {
  30. assert.Equal(t, i, a[i])
  31. }
  32. }
  33. func TestRepeatFloat32s(t *testing.T) {
  34. a := RepeatFloat32s(3, 0.1)
  35. assert.Equal(t, []float32{0.1, 0.1, 0.1}, a)
  36. }
  37. func TestNewMatrixInt(t *testing.T) {
  38. m := NewMatrixInt(4, 3)
  39. assert.Equal(t, 4, len(m))
  40. for _, v := range m {
  41. assert.Equal(t, 3, len(v))
  42. }
  43. }
  44. func TestNewTensor32(t *testing.T) {
  45. a := NewTensor32(3, 4, 5)
  46. assert.Equal(t, 3, len(a))
  47. assert.Equal(t, 4, len(a[0]))
  48. assert.Equal(t, 5, len(a[0][0]))
  49. }