forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.ts
More file actions
53 lines (47 loc) · 1.67 KB
/
types_test.ts
File metadata and controls
53 lines (47 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @license
* Copyright 2018 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* Unit tests for -specific types.
*/
import {SymbolicTensor} from './engine/topology';
/**
* Unit tests for SymbolicTensor.
*/
describe('SymbolicTensor Test', () => {
it('Correct dtype and shape properties', () => {
const st1 = new SymbolicTensor('float32', [4, 6], null, [], {});
expect(st1.dtype).toEqual('float32');
expect(st1.shape).toEqual([4, 6]);
expect(st1.rank).toEqual(2);
});
it('Correct when operating on scalars', () => {
const scalar = new SymbolicTensor('float32', [], null, [], {});
expect(scalar.dtype).toEqual('float32');
expect(scalar.shape).toEqual([]);
expect(scalar.rank).toEqual(0);
});
it('Correct names and ids', () => {
const st1 = new SymbolicTensor(
'float32', [2, 2], null, [], {}, 'TestSymbolicTensor');
const st2 = new SymbolicTensor(
'float32', [2, 2], null, [], {}, 'TestSymbolicTensor');
expect(st1.name.indexOf('TestSymbolicTensor')).toEqual(0);
expect(st2.name.indexOf('TestSymbolicTensor')).toEqual(0);
// Explicit names of symbolic tensors should be unique.
expect(st1 === st2).toBe(false);
expect(st1.id).toBeGreaterThanOrEqual(0);
expect(st2.id).toBeGreaterThanOrEqual(0);
expect(st1.id === st2.id).toBe(false);
});
it('Invalid tensor name leads to error', () => {
expect(() => new SymbolicTensor('float32', [2, 2], null, [], {}, '!'))
.toThrowError();
});
});