Skip to content

Commit ea632d9

Browse files
committed
[tfjs-converter] test encodeBase64, decodeBase64
1 parent 5df131d commit ea632d9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* =============================================================================
16+
*/
17+
import * as tfc from '@tensorflow/tfjs-core';
18+
19+
import {ExecutionContext} from '../../executor/execution_context';
20+
import {Node} from '../types';
21+
22+
import {executeOp} from './string_executor';
23+
import {createBoolAttr, createTensorAttr} from './test_helper';
24+
25+
describe('string', () => {
26+
let node: Node;
27+
const input1 = [tfc.tensor(['a'], [1], 'string')];
28+
const context = new ExecutionContext({}, {});
29+
30+
beforeEach(() => {
31+
node = {
32+
name: 'test',
33+
op: '',
34+
category: 'string',
35+
inputNames: ['input1'],
36+
inputs: [],
37+
inputParams: {str: createTensorAttr(0)},
38+
attrParams: {},
39+
children: []
40+
};
41+
});
42+
43+
describe('executeOp', () => {
44+
describe('DecodeBase64', () => {
45+
it('should call tfc.decodeBase64', () => {
46+
spyOn(tfc, 'decodeBase64');
47+
node.op = 'DecodeBase64';
48+
executeOp(node, {input1}, context);
49+
expect(tfc.decodeBase64).toHaveBeenCalledWith(input1[0]);
50+
});
51+
});
52+
describe('EncodeBase64', () => {
53+
it('should call tfc.encodeBase64', () => {
54+
spyOn(tfc, 'encodeBase64');
55+
node.op = 'EncodeBase64';
56+
node.attrParams.pad = createBoolAttr(true);
57+
executeOp(node, {input1}, context);
58+
expect(tfc.encodeBase64).toHaveBeenCalledWith(input1[0], true);
59+
});
60+
});
61+
});
62+
});

0 commit comments

Comments
 (0)