github.com/wzzhu/tensor@v0.9.24/defaultenginefloat64_test.go (about) 1 package tensor 2 3 import ( 4 "testing" 5 "testing/quick" 6 ) 7 8 func TestFloat64Engine_makeArray(t *testing.T) { 9 10 // the uint16 is just to make sure that tests are correctly run. 11 // we don't want the quicktest to randomly generate a size that is so large 12 // that Go takes a long time just to allocate. We'll test the other sizes (like negative numbers) 13 // after the quick test. 14 f := func(sz uint16) bool { 15 size := int(sz) 16 e := Float64Engine{StdEng{}} 17 dt := Float64 18 arr := array{} 19 20 e.makeArray(&arr, dt, size) 21 22 if len(arr.Raw) != size*8 { 23 t.Errorf("Expected raw to be size*8. Got %v instead", len(arr.Raw)) 24 return false 25 } 26 v, ok := arr.Data().([]float64) 27 if !ok { 28 t.Errorf("Expected v to be []float32. Got %T instead", arr.Data()) 29 return false 30 } 31 32 if len(v) != size { 33 return false 34 } 35 return true 36 } 37 38 if err := quick.Check(f, nil); err != nil { 39 t.Errorf("Quick test failed %v", err) 40 } 41 42 }