Skip to content

Commit

Permalink
[add] extended tests with modelset and modelrun
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecosta90 committed May 13, 2020
1 parent 7cf8b7c commit 79c69db
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {Tensor} from "../src/tensor";
import {DType} from "../src/DType";
import 'mocha';
import {expect} from 'chai';
import {Model} from "../src/Model";
import * as fs from "fs";
import {Backend} from "../src/Backend";

const mochaAsync = (fn: any) => {
return (done: any) => {
Expand Down Expand Up @@ -86,3 +89,41 @@ it("ai.tensorget negative testing", mochaAsync(async () => {
}));


it("ai.modelset positive testing", mochaAsync(async () => {
const nativeClient = createClient();
const aiclient = new RedisaiClient(nativeClient);
let model_blob: Buffer = fs.readFileSync("./tests/test_data/graph.pb");
const model = new Model(Backend.TF, "CPU", ["a", "b"], ["c"], model_blob);
const result = await aiclient.modelset("m1", model);
expect(result).to.equal('OK');
aiclient.end(true);
}));

it("ai.modelrun positive testing", mochaAsync(async () => {
const nativeClient = createClient();
const aiclient = new RedisaiClient(nativeClient);


const tensorA = new Tensor(DType.float32, [1, 2], [2, 3]);
const resultA = await aiclient.tensorset("tensorA", tensorA);
expect(resultA).to.equal('OK');

const tensorB = new Tensor(DType.float32, [1, 2], [3, 5]);
const resultB = await aiclient.tensorset("tensorB", tensorB);
expect(resultB).to.equal('OK');


let model_blob: Buffer = fs.readFileSync("./tests/test_data/graph.pb");
const model = new Model(Backend.TF, "CPU", ["a", "b"], ["c"], model_blob);
const resultModelSet = await aiclient.modelset("mymodel", model);
expect(resultModelSet).to.equal('OK');

const resultModelRun = await aiclient.modelrun("mymodel", ["tensorA","tensorB"], ["tensorC"]);
expect(resultModelRun).to.equal('OK');

const tensorC = await aiclient.tensorget("tensorC");
expect(tensorC.data[0]).to.closeTo(6.0,0.1);
expect(tensorC.data[1]).to.closeTo(15.0,0.1);

aiclient.end(true);
}));

0 comments on commit 79c69db

Please sign in to comment.