Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[OVJS] Avoid of usage global variables in tests (#26393)

Alicja Miloszewska41394bb0e6a0
diff --git a/src/bindings/js/node/tests/unit/basic.test.js b/src/bindings/js/node/tests/unit/basic.test.js
index 4b4913fb52b..d84aabeb912 100644
--- a/src/bindings/js/node/tests/unit/basic.test.js
+++ b/src/bindings/js/node/tests/unit/basic.test.js
@@ -4,21 +4,29 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
+const epsilon = 0.5;
describe('ov basic tests.', () => {
+ let testXml = null;
+ let core = null;
+ let model = null;
+ let compiledModel = null;
+ let modelLike = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+ testXml = getModelPath().xml;
});
- const testXml = getModelPath().xml;
- const core = new ov.Core();
- const model = core.readModelSync(testXml);
- const compiledModel = core.compileModelSync(model, 'CPU');
- const modelLike = [[model],
- [compiledModel]];
+ beforeEach(() => {
+ core = new ov.Core();
+ model = core.readModelSync(testXml);
+ compiledModel = core.compileModelSync(model, 'CPU');
+ modelLike = [model, compiledModel];
+ });
it('Core.getAvailableDevices()', () => {
const devices = core.getAvailableDevices();
@@ -164,18 +172,19 @@ describe('ov basic tests.', () => {
});
- describe('Output class', () => {
+ describe('ov.Model/ov.CompiledModel output()', () => {
- it('Output type', () => {
+ it('model.output() type', () => {
assert.ok(model.output() instanceof ov.Output);
});
- it('ConstOutput type', () => {
+ it('compiledModel.output() type', () => {
assert.ok(compiledModel.output() instanceof ov.ConstOutput);
});
- modelLike.forEach(([obj]) => {
- it('Output getters and properties', () => {
+ it('output() methods/properties', () => {
+
+ modelLike.forEach((obj) => {
assert.strictEqual(obj.outputs.length, 1);
// tests for an obj with one output
assert.strictEqual(obj.output().toString(), 'fc_out');
@@ -186,60 +195,53 @@ describe('ov basic tests.', () => {
assert.strictEqual(obj.output().getAnyName(), 'fc_out');
assert.strictEqual(obj.output().anyName, 'fc_out');
});
- });
+ });
});
- describe('Input class for ov::Input<const ov::Node>', () => {
+ describe('ov.Model/ov.CompiledModel input()', () => {
- it('Output type', () => {
+ it('ov.Model.input() type', () => {
assert.ok(model.input() instanceof ov.Output);
});
- it('ConstOutput type', () => {
+ it('ov.CompiledModel.input() type', () => {
assert.ok(compiledModel.input() instanceof ov.ConstOutput);
});
- modelLike.forEach(([obj]) => {
- it('input() is typeof object', () => {
- assert.strictEqual(typeof obj.input(), 'object');
- });
+ it('input() methods/properties', () => {
+ modelLike.forEach((obj) => {
- it('inputs property', () => {
+ assert.strictEqual(typeof obj.input(), 'object');
assert.strictEqual(obj.inputs.length, 1);
- });
-
- it('input().toString()', () => {
assert.strictEqual(obj.input().toString(), 'data');
- });
-
- it('input(idx: number).ToString() method', () => {
assert.strictEqual(obj.input(0).toString(), 'data');
- });
-
- it('input(tensorName: string).ToString() method', () => {
assert.strictEqual(obj.input('data').toString(), 'data');
- });
-
- it('input().getAnyName() and anyName', () => {
assert.strictEqual(obj.input().getAnyName(), 'data');
assert.strictEqual(obj.input().anyName, 'data');
- });
- it('input(idx).shape property with dimensions', () => {
assert.deepStrictEqual(obj.input(0).shape, [1, 3, 32, 32]);
assert.deepStrictEqual(obj.input(0).getShape(), [1, 3, 32, 32]);
});
+
});
});
describe('Test exportModel()/importModel()', () => {
- const userStream = compiledModel.exportModelSync();
- const epsilon = 0.5;
- const tensor = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
- const inferRequest = compiledModel.createInferRequest();
- const res1 = inferRequest.infer([tensor]);
+ let tensor = null;
+ let userStream = null;
+ let res1 = null;
+
+ before(() => {
+ tensor = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
+ const compiledModel = core.compileModelSync(model, 'CPU');
+ userStream = compiledModel.exportModelSync();
+ const inferRequest = compiledModel.createInferRequest();
+ res1 = inferRequest.infer([tensor]);
+ });
it('Test importModelSync(stream, device)', () => {
const newCompiled = core.importModelSync(userStream, 'CPU');
diff --git a/src/bindings/js/node/tests/unit/compiled_model.test.js b/src/bindings/js/node/tests/unit/compiled_model.test.js
index 2d1169b0783..d433cf3b8e9 100644
--- a/src/bindings/js/node/tests/unit/compiled_model.test.js
+++ b/src/bindings/js/node/tests/unit/compiled_model.test.js
@@ -4,21 +4,28 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
describe('ov.CompiledModel tests', () => {
+
+ let testXml = null;
+ let core = null;
+ let compiledModel = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+ testXml = getModelPath().xml;
+ core = new ov.Core();
+ });
+
+ beforeEach(() => {
+ const properties = {
+ 'AUTO_BATCH_TIMEOUT': '1',
+ };
+ compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);
});
-
- const testXml = getModelPath().xml;
- const core = new ov.Core();
- const properties = {
- 'AUTO_BATCH_TIMEOUT': '1',
- };
- const compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);
describe('getProperty()', () => {
it('returns the value of property from compiled model', () => {
@@ -39,7 +46,7 @@ describe('ov.CompiledModel tests', () => {
describe('setProperty()', () => {
it('sets a properties for compiled model', () => {
- properties['AUTO_BATCH_TIMEOUT'] = '1000';
+ const properties = {'AUTO_BATCH_TIMEOUT': '1000'};
assert.doesNotThrow(() => compiledModel.setProperty(properties));
});
@@ -64,7 +71,7 @@ describe('ov.CompiledModel tests', () => {
});
it('returns the set property of the compiled model', () => {
- properties['AUTO_BATCH_TIMEOUT'] = '123';
+ const properties = {'AUTO_BATCH_TIMEOUT': '123'};
compiledModel.setProperty(properties);
assert.strictEqual(compiledModel.getProperty('AUTO_BATCH_TIMEOUT'), 123);
});
diff --git a/src/bindings/js/node/tests/unit/core.test.js b/src/bindings/js/node/tests/unit/core.test.js
index 69d8720d97a..bec05980c18 100644
--- a/src/bindings/js/node/tests/unit/core.test.js
+++ b/src/bindings/js/node/tests/unit/core.test.js
@@ -4,11 +4,14 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it } = require('node:test');
+const { describe, it, beforeEach } = require('node:test');
describe('ov.Core tests', () => {
- const core = new ov.Core();
+ let core = null;
+ beforeEach(() => {
+ core = new ov.Core();
+ });
it('Core.setProperty()', () => {
const tmpDir = '/tmp';
diff --git a/src/bindings/js/node/tests/unit/infer_request.test.js b/src/bindings/js/node/tests/unit/infer_request.test.js
index 8dc16cd1954..d1ee057cd77 100644
--- a/src/bindings/js/node/tests/unit/infer_request.test.js
+++ b/src/bindings/js/node/tests/unit/infer_request.test.js
@@ -4,7 +4,7 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, isModelAvailable, getModelPath } = require('./utils.js');
const epsilon = 0.5; // To avoid very small numbers
@@ -12,51 +12,53 @@ const testXml = getModelPath().xml;
describe('ov.InferRequest tests', () => {
+ let compiledModel = null;
+ let tensorData = null;
+ let tensor = null;
+ let resTensor = null;
+ let tensorLike = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+
+ const core = new ov.Core();
+ const model = core.readModelSync(testXml);
+ compiledModel = core.compileModelSync(model, 'CPU');
+
+ tensorData = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
+ tensor = new ov.Tensor(
+ ov.element.f32,
+ [1, 3, 32, 32],
+ tensorData,
+ );
+ resTensor = new ov.Tensor(
+ ov.element.f32,
+ [1, 10],
+ tensorData.slice(-10),
+ );
+ tensorLike = [tensor, tensorData];
});
- const core = new ov.Core();
- const model = core.readModelSync(testXml);
- const compiledModel = core.compileModelSync(model, 'CPU');
-
- const inferRequest = compiledModel.createInferRequest();
- const inferRequestAsync = compiledModel.createInferRequest();
-
- const tensorData = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
- const tensor = new ov.Tensor(
- ov.element.f32,
- [1, 3, 32, 32],
- tensorData,
- );
- const resTensor = new ov.Tensor(
- ov.element.f32,
- [1, 10],
- tensorData.slice(-10),
- );
-
- const tensorLike = [[tensor],
- [tensorData]];
-
- describe('InferRequest', () => {
-
- tensorLike.forEach(([tl]) => {
- const result = inferRequest.infer({ data: tl });
- const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
- it(`Test infer(inputData: { [inputName: string]: ${label} })`, () => {
+ describe('infer() method', () => {
+ let inferRequest = null;
+ beforeEach(() => {
+ inferRequest = compiledModel.createInferRequest();
+ });
+
+ it('Test infer(inputData: {inputName: string]: Tensor[]/TypedArray[]}', () => {
+ tensorLike.forEach((tl) => {
+ const result = inferRequest.infer({ data: tl });
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, 10);
});
});
- tensorLike.forEach(([tl]) => {
- const result = inferRequest.infer([tl]);
- const label = tl instanceof Float32Array ? 'TypedArray[]' : 'Tensor[]';
- it(`Test infer(inputData: ${label})`, () => {
+ it('Test infer(inputData: Tensor[]/TypedArray[])', () => {
+ tensorLike.forEach((tl) => {
+ const result = inferRequest.infer([tl]);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, 10);
});
-
});
it('Test infer(TypedArray) throws', () => {
@@ -65,29 +67,39 @@ describe('ov.InferRequest tests', () => {
{message: /TypedArray cannot be passed directly into infer\(\) method./});
});
- const buffer = new ArrayBuffer(tensorData.length);
- const inputMessagePairs = [
- ['string', 'Cannot create a tensor from the passed Napi::Value.'],
- [tensorData.slice(-10), 'Memory allocated using shape and element::type mismatch passed data\'s size'],
- [new Float32Array(buffer, 4), 'TypedArray.byteOffset has to be equal to zero.'],
- [{}, /Invalid argument/], // Test for object that is not Tensor
- ];
+ it('Test for invalid input data', () => {
+ const buffer = new ArrayBuffer(tensorData.length);
+ const inputMessagePairs = [
+ ['string', 'Cannot create a tensor from the passed Napi::Value.'],
+ [tensorData.slice(-10), 'Memory allocated using shape and element::type mismatch passed data\'s size'],
+ [new Float32Array(buffer, 4), 'TypedArray.byteOffset has to be equal to zero.'],
+ [{}, /Invalid argument/], // Test for object that is not Tensor
+ ];
+
+ inputMessagePairs.forEach( ([tl, msg]) => {
- inputMessagePairs.forEach( ([tl, msg]) => {
- it(`Test infer([data]) throws ${msg}`, () => {
assert.throws(
() => inferRequest.infer([tl]),
- {message: new RegExp(msg)});
- });
- it(`Test infer({ data: tl}) throws ${msg}`, () => {
+ { message: new RegExp(msg) }, 'infer([data]) throws');
+
assert.throws(
() => inferRequest.infer({data: tl}),
- {message: new RegExp(msg)});
+ { message: new RegExp(msg) }, 'infer({ data: tl}) throws');
+
});
+
+ });
+
+ });
+
+ describe('inferAsync() method', () => {
+ let inferRequest = null;
+ before( () => {
+ inferRequest = compiledModel.createInferRequest();
});
it('Test inferAsync(inputData: { [inputName: string]: Tensor })', () => {
- inferRequestAsync.inferAsync({ data: tensor }).then(result => {
+ inferRequest.inferAsync({ data: tensor }).then(result => {
assert.ok(result['fc_out'] instanceof ov.Tensor);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, 10);}
@@ -95,7 +107,7 @@ describe('ov.InferRequest tests', () => {
});
it('Test inferAsync(inputData: Tensor[])', () => {
- inferRequestAsync.inferAsync([ tensor ]).then(result => {
+ inferRequest.inferAsync([ tensor ]).then(result => {
assert.ok(result['fc_out'] instanceof ov.Tensor);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, 10);
@@ -104,18 +116,26 @@ describe('ov.InferRequest tests', () => {
it('Test inferAsync([data]) throws: Cannot create a tensor from the passed Napi::Value.', () => {
assert.throws(
- () => inferRequestAsync.inferAsync(['string']).then(),
+ () => inferRequest.inferAsync(['string']).then(),
/Cannot create a tensor from the passed Napi::Value./
);
});
it('Test inferAsync({ data: "string"}) throws: Cannot create a tensor from the passed Napi::Value.', () => {
assert.throws(
- () => inferRequestAsync.inferAsync({data: 'string'}).then(),
+ () => inferRequest.inferAsync({data: 'string'}).then(),
/Cannot create a tensor from the passed Napi::Value./
);
});
+ });
+
+ describe('setters', () => {
+ let inferRequest = null;
+ beforeEach(() => {
+ inferRequest = compiledModel.createInferRequest();
+ });
+
it('Test setInputTensor(tensor)', () => {
inferRequest.setInputTensor(tensor);
const t1 = inferRequest.getInputTensor();
@@ -238,38 +258,44 @@ describe('ov.InferRequest tests', () => {
);
});
- const irGetters = compiledModel.createInferRequest();
- irGetters.setInputTensor(tensor);
- irGetters.infer();
+ });
+
+ describe('getters', () => {
+ let inferRequest = null;
+ beforeEach(() => {
+ inferRequest = compiledModel.createInferRequest();
+ inferRequest.setInputTensor(tensor);
+ inferRequest.infer();
+ });
it('Test getTensor(tensorName)', () => {
- const t1 = irGetters.getTensor('data');
+ const t1 = inferRequest.getTensor('data');
assert.ok(t1 instanceof ov.Tensor);
assert.deepStrictEqual(tensor.data[0], t1.data[0]);
});
it('Test getTensor(Output)', () => {
- const input = irGetters.getCompiledModel().input();
- const t1 = irGetters.getTensor(input);
+ const input = inferRequest.getCompiledModel().input();
+ const t1 = inferRequest.getTensor(input);
assert.ok(t1 instanceof ov.Tensor);
assert.deepStrictEqual(tensor.data[0], t1.data[0]);
});
it('Test getInputTensor()', () => {
- const t1 = irGetters.getInputTensor();
+ const t1 = inferRequest.getInputTensor();
assert.ok(t1 instanceof ov.Tensor);
assert.deepStrictEqual(tensor.data[0], t1.data[0]);
});
it('Test getInputTensor(idx)', () => {
- const t1 = irGetters.getInputTensor(0);
+ const t1 = inferRequest.getInputTensor(0);
assert.ok(t1 instanceof ov.Tensor);
assert.deepStrictEqual(tensor.data[0], t1.data[0]);
});
it('Test getOutputTensor(idx?)', () => {
- const res1 = irGetters.getOutputTensor();
- const res2 = irGetters.getOutputTensor(0);
+ const res1 = inferRequest.getOutputTensor();
+ const res2 = inferRequest.getOutputTensor(0);
assert.ok(res1 instanceof ov.Tensor);
assert.ok(res2 instanceof ov.Tensor);
assert.deepStrictEqual(res1.data[0], res2.data[0]);
@@ -284,6 +310,6 @@ describe('ov.InferRequest tests', () => {
const res1 = ir.infer([tensorData]);
assert.deepStrictEqual(res1['fc_out'].data[0], res2['fc_out'].data[0]);
});
- });
+ });
});
diff --git a/src/bindings/js/node/tests/unit/model.test.js b/src/bindings/js/node/tests/unit/model.test.js
index e374c0b3ab3..e71226e756e 100644
--- a/src/bindings/js/node/tests/unit/model.test.js
+++ b/src/bindings/js/node/tests/unit/model.test.js
@@ -4,19 +4,24 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
describe('ov.Model tests', () => {
+ let testXml = null;
+ let core = null;
+ let model = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+ testXml = getModelPath().xml;
+ core = new ov.Core();
});
- const testXml = getModelPath().xml;
- const core = new ov.Core();
- const model = core.readModelSync(testXml);
- const clonedModel = model.clone();
+ beforeEach(() => {
+ model = core.readModelSync(testXml);
+ });
describe('Model.isDynamic()', () => {
it('should return a boolean value indicating if the model is dynamic', () => {
@@ -61,10 +66,6 @@ describe('ov.Model tests', () => {
});
});
describe('Model.setFriendlyName()', () => {
- it('sets a friendly name for the model', () => {
- assert.doesNotThrow(() => model.setFriendlyName('MyFriendlyName'));
- });
-
it('throws an error when called without a string argument', () => {
assert.throws(
() => model.setFriendlyName(),
@@ -97,7 +98,7 @@ describe('ov.Model tests', () => {
it('handles setting an empty string as a friendly name', () => {
assert.doesNotThrow(() => model.setFriendlyName(''));
- assert.strictEqual(model.getFriendlyName(), 'Model1');
+ assert.strictEqual(model.getFriendlyName(), model.getName());
});
});
@@ -166,10 +167,12 @@ describe('ov.Model tests', () => {
describe('Model.clone()', () => {
it('should return an object of type model', () => {
+ const clonedModel = model.clone();
assert.ok(clonedModel instanceof ov.Model, 'clone() should return a model');
});
it('should return a model that is a clone of the calling model', () => {
+ const clonedModel = model.clone();
assert.deepStrictEqual(clonedModel, model, 'Cloned Model should be exactly equal to the calling model');
});
diff --git a/src/bindings/js/node/tests/unit/pre_post_processor.test.js b/src/bindings/js/node/tests/unit/pre_post_processor.test.js
index f3068f52581..adb02dc082e 100644
--- a/src/bindings/js/node/tests/unit/pre_post_processor.test.js
+++ b/src/bindings/js/node/tests/unit/pre_post_processor.test.js
@@ -4,18 +4,25 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');
describe('ov.preprocess.PrePostProcessor tests', () => {
+ let testXml = null;
+ let core = null;
+ let model = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+ testXml = getModelPath().xml;
+ core = new ov.Core();
+
});
- const testXml = getModelPath().xml;
- const core = new ov.Core();
- const model = core.readModelSync(testXml);
+ beforeEach(() => {
+ model = core.readModelSync(testXml);
+ });
describe('PrePostProcess', () => {
diff --git a/src/bindings/js/node/tests/unit/read_model.test.js b/src/bindings/js/node/tests/unit/read_model.test.js
index 47fc584fe54..ab0add15d59 100644
--- a/src/bindings/js/node/tests/unit/read_model.test.js
+++ b/src/bindings/js/node/tests/unit/read_model.test.js
@@ -5,23 +5,30 @@
const fs = require('node:fs');
const { addon: ov } = require('../..');
const assert = require('assert');
-const { describe, it, before } = require('node:test');
+const { describe, it, before, beforeEach } = require('node:test');
const { testModels, isModelAvailable, getModelPath } = require('./utils.js');
const { xml: modelPath, bin: weightsPath } = getModelPath();
describe('Tests for reading model.', () => {
+ let modelFile = null;
+ let modelStr = null;
+ let weightsFile = null;
+ let weightsTensor= null;
+ let core = null;
+
before(async () => {
await isModelAvailable(testModels.testModelFP32);
+ modelFile = fs.readFileSync(modelPath);
+ modelStr = fs.readFileSync(modelPath, 'utf8');
+ weightsFile = fs.readFileSync(weightsPath);
});
- const modelFile = fs.readFileSync(modelPath);
- const modelStr = fs.readFileSync(modelPath, 'utf8');
- const weightsFile = fs.readFileSync(weightsPath);
- const weightsTensor = new ov.Tensor(ov.element.u8, [weightsFile.buffer.byteLength], new Uint8Array(weightsFile.buffer));
-
- const core = new ov.Core();
+ beforeEach(() => {
+ core = new ov.Core();
+ weightsTensor = new ov.Tensor(ov.element.u8, [weightsFile.buffer.byteLength], new Uint8Array(weightsFile.buffer));
+ });
describe('Core.readModeSync', () => {
it('readModeSync(xmlPath) ', () => {
diff --git a/src/bindings/js/node/tests/unit/tensor.test.js b/src/bindings/js/node/tests/unit/tensor.test.js
index 45d974f54cd..5f03030d98c 100644
--- a/src/bindings/js/node/tests/unit/tensor.test.js
+++ b/src/bindings/js/node/tests/unit/tensor.test.js
@@ -4,26 +4,33 @@
const { addon: ov } = require('../..');
const assert = require('assert');
-const { test, describe, it } = require('node:test');
+const { test, describe, it, before } = require('node:test');
const getRandomBigInt = require('random-bigint');
describe('ov.Tensor tests', () => {
- const shape = [1, 3, 224, 224];
- const elemNum = 1 * 3 * 224 * 224;
- const data = Float32Array.from({ length: elemNum }, () => Math.random() );
- const params = [
- [ov.element.i8, 'i8', Int8Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u8, 'u8', Uint8Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i16, 'i16', Int16Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u16, 'u16', Uint16Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i32, 'i32', Int32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.u32, 'u32', Uint32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.f32, 'f32', Float32Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.f64, 'f64', Float64Array.from({ length: elemNum }, () => Math.random() )],
- [ov.element.i64, 'i64', BigInt64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
- [ov.element.u64, 'u64', BigUint64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
- ];
+ let shape = null;
+ let elemNum = null;
+ let data = null;
+ let params =null;
+
+ before(() => {
+ shape = [1, 3, 224, 224];
+ elemNum = 1 * 3 * 224 * 224;
+ data = Float32Array.from({ length: elemNum }, () => Math.random() );
+ params = [
+ [ov.element.i8, 'i8', Int8Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u8, 'u8', Uint8Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i16, 'i16', Int16Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u16, 'u16', Uint16Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i32, 'i32', Int32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.u32, 'u32', Uint32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.f32, 'f32', Float32Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.f64, 'f64', Float64Array.from({ length: elemNum }, () => Math.random() )],
+ [ov.element.i64, 'i64', BigInt64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
+ [ov.element.u64, 'u64', BigUint64Array.from({ length: elemNum }, () => getRandomBigInt(10) )],
+ ];
+ });
test('Test for number of arguments in tensor', () => {
assert.throws( () => new ov.Tensor(ov.element.f32, shape, data, params),
@@ -38,9 +45,8 @@ describe('ov.Tensor tests', () => {
});
describe('Tensor data', () => {
-
- params.forEach(([type, stringType, data]) => {
- it(`set tensor data with ${stringType} element type`, () => {
+ it('set tensor data with element type', () => {
+ params.forEach(([type, stringType, data]) => {
const tensor = new ov.Tensor(type, shape, data);
assert.deepStrictEqual(tensor.data, data);
});
@@ -192,14 +198,16 @@ describe('ov.Tensor tests', () => {
});
describe('Tensor element type', () => {
- params.forEach(([elemType, val]) => {
- it(`comparison of ov.element.${elemType} to string ${val}`, () => {
+ it('comparisons of ov.element to string', () => {
+ params.forEach(([elemType, val]) => {
+
assert.strictEqual(elemType, val);
});
});
- params.forEach(([elemType, , data]) => {
- it(`comparison of ov.element ${elemType} got from Tensor object`, () => {
+ it('comparisons of ov.element got from Tensor object', () => {
+ params.forEach(([elemType, , data]) => {
+
const tensor = new ov.Tensor(elemType, shape, data);
assert.strictEqual(tensor.getElementType(), elemType);
});