vector_test.go 795 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package R
  2. import (
  3. "testing"
  4. "github.com/stretchrcom/testify/assert"
  5. )
  6. func TestNumericVector(t *testing.T) {
  7. Init()
  8. data := []float64{10, 2, 51, 48}
  9. actual := NewNumericVector(data)
  10. assert.Equal(t, len(data), actual.Len())
  11. assert.Panics(t, func() {
  12. actual.boundsCheck(-1)
  13. })
  14. for i, x := range data {
  15. assert.Equal(t, x, actual.Get(i))
  16. }
  17. actual.Set(2, 31)
  18. assert.Equal(t, 31, actual.Get(2))
  19. assert.Panics(t, func() {
  20. actual.Set(5, 1)
  21. })
  22. }
  23. func TestComplexVector(t *testing.T) {
  24. Init()
  25. data := []complex128{complex(1, 2), complex(1.1, 4.5)}
  26. actual := NewComplexVector(data)
  27. assert.Equal(t, len(data), actual.Len())
  28. for i, x := range data {
  29. assert.Equal(t, x, actual.Get(i))
  30. }
  31. actual.Set(1, complex(10, 11.2))
  32. assert.Equal(t, complex(10, 11.2), actual.Get(1))
  33. }