diff --git a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts index fef4993791035e1f03467f71e2688ed333e97c2b..bde78d3163d8355130dc5ef4b1df6e322e34eb2a 100644 --- a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts +++ b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts @@ -69,7 +69,76 @@ export function testArrayBuffer() : Result { tDataView.doTestDataViewFloats() }) //dataview end + //typedarray start + test('typedarray_testConstructor', () => { + var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + var int32 = new Int32Array(arr); + expect(int32.toString()).toEqual("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); + var buffer = new ArrayBuffer(64); + + int32 = new Int32Array(buffer); + expect(int32.byteLength).toEqual(64); + + var length = 1024; + var arrUnit8 = new Uint8Array(length); + for (var i = 0; i < length; i++) { + arrUnit8[i] = i; + } + var uint8 = new Uint8Array(arrUnit8); + expect(uint8.byteLength).toEqual(1024); + + length = 1024; + uint8 = new Uint8Array(length); + for (var i = 0; i < length; i++) { + uint8[i] = i; + } + + var float64 = new Float64Array(uint8); + expect(float64.length).toEqual(1024); + + int32 = new Int32Array(16); + expect(int32.length).toEqual(16); + }) + test('typedarray_from_different_type', () => { + const length = 16; + + + const dest_arrays = [ + new Uint8Array(length), + new Int8Array(length), + new Uint16Array(length), + new Int16Array(length), + new Uint32Array(length), + new Int32Array(length), + new Float32Array(length), + new Float64Array(length), + new Uint8ClampedArray(length) + ]; + + let uint8_array = new Uint8Array(length); + let int32_array = new Int32Array(length); + let float32_array = new Float32Array(length); + let float64_array = new Float64Array(length); + for (let i = 0; i < length; i++) { + uint8_array[i] = i; + int32_array[i] = i; + float32_array[i] = i; + float64_array[i] = i; + } + for (let i = 0; i < dest_arrays.length; i++) { + var typed_dest = dest_arrays[i] + typed_dest.set(uint8_array) + expect(typed_dest.length).toEqual(16) + typed_dest.set(int32_array) + expect(typed_dest.length).toEqual(16) + typed_dest.set(float32_array) + expect(typed_dest.length).toEqual(16) + typed_dest.set(float64_array) + expect(typed_dest.length).toEqual(16) + } + }) + //typedarray end //float32array start test('float32_testConstructor', () => { float32.testConstructor() diff --git a/uni_modules/uts-tests/utssdk/TFloat32Array.uts b/uni_modules/uts-tests/utssdk/TFloat32Array.uts index 1795e124f19df99641fc0a918815fc6f391ca9fd..caa6f98f58710f61ecd0981cade197190f0453ea 100644 --- a/uni_modules/uts-tests/utssdk/TFloat32Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat32Array.uts @@ -76,6 +76,16 @@ export class TFloat32Array { var array = [1, 2, 3] float32.set(array, 1); expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); + + let src = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]; + let typed_dest = new Float32Array(16); + typed_dest.set(src); + expect(typed_dest.toString()).toEqual("1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4"); + + let typed_src = new Float32Array(src); + typed_dest = new Float32Array(16); + typed_dest.set(typed_src); + expect(typed_dest.toString()).toEqual("1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4"); // #END } diff --git a/uni_modules/uts-tests/utssdk/TFloat64Array.uts b/uni_modules/uts-tests/utssdk/TFloat64Array.uts index 5e54ac2712068437390dcfbc704470cc03908494..e85abf3aeadc3a439b961ed87f0324f06f488010 100644 --- a/uni_modules/uts-tests/utssdk/TFloat64Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat64Array.uts @@ -76,6 +76,19 @@ export class TFloat64Array { float64.set([1, 2, 3], 1); float64.copyWithin(3, 0, 3); expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0"); + + let initialLargeArray : Array = new Array(10000, 0); + for (let i = 0; i < 5000; ++i) { + initialLargeArray[i] = i; + } + let initialLargeFloat64Array = new Float64Array(initialLargeArray); + let largeFloat64Array : Float64Array = new Float64Array(initialLargeFloat64Array); + largeFloat64Array.copyWithin(5000, 0); + for (let i = 0; i < 5000; ++i) { + if (largeFloat64Array[i + 5000] !== i) { + expect(true).toEqual(false); + } + } // #END } @@ -266,6 +279,25 @@ export class TFloat64Array { res = float64.slice(0, 1); expect(res.toString()).toEqual("1"); + + + + const size = 1000; + const initialFloat64Array = new Float64Array(size); + for (let i = 0; i < size; ++i) { + initialFloat64Array[i] = Math.random(); + } + + let arr : Float64Array; + let new_arr : Float64Array; + arr = new Float64Array(initialFloat64Array); + new_arr = arr.slice(1, -1); + for (let i = 1; i < size - 1; ++i) { + if (arr[i] !== new_arr[i - 1]) { + expect(true).toEqual(false); + break + } + } // #END } @@ -290,6 +322,19 @@ export class TFloat64Array { let sub = float64.subarray(0, 4); expect(sub.toString()).toEqual("1,2,3,0"); + + const size = 1000; + const initialFloat64Array = new Float64Array(size); + for (let i = 0; i < size; ++i) { + initialFloat64Array[i] = Math.random(); + } + let arr = new Float64Array(initialFloat64Array); + let new_arr = arr.subarray(1, size - 1); + for (let i = 1; i < size - 1; ++i) { + if (arr[i] !== new_arr[i - 1]) { + expect(true).toEqual(false); + } + } // #END } @@ -304,7 +349,7 @@ export class TFloat64Array { } arrayBufferSlice() { - + // #TEST ArrayBuffer.slice let buffer = new ArrayBuffer(16); let float64 = new Float64Array(buffer); @@ -315,7 +360,7 @@ export class TFloat64Array { let sliced = new Float64Array(res); expect(sliced[0]).toEqual(42); // #END - + } testSome() { // #TEST Float64Array.some