UNPKG

2.67 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright 2018 Google Inc. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * =============================================================================
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19var int64_tensors_1 = require("./int64_tensors");
20describe('int64 tensors', function () {
21 it('positive value', function () {
22 var x = new int64_tensors_1.Int64Scalar(42);
23 expect(x.dtype).toEqual('int64');
24 var valueArray = x.valueArray;
25 expect(valueArray.constructor.name).toEqual('Int32Array');
26 expect(valueArray.length).toEqual(2);
27 expect(valueArray[0]).toEqual(42);
28 expect(valueArray[1]).toEqual(0);
29 });
30 it('zero value', function () {
31 var x = new int64_tensors_1.Int64Scalar(0);
32 expect(x.dtype).toEqual('int64');
33 var valueArray = x.valueArray;
34 expect(valueArray.constructor.name).toEqual('Int32Array');
35 expect(valueArray.length).toEqual(2);
36 expect(valueArray[0]).toEqual(0);
37 expect(valueArray[1]).toEqual(0);
38 });
39 it('negative value', function () {
40 var x = new int64_tensors_1.Int64Scalar(-3);
41 expect(x.dtype).toEqual('int64');
42 var valueArray = x.valueArray;
43 expect(valueArray.constructor.name).toEqual('Int32Array');
44 expect(valueArray.length).toEqual(2);
45 expect(valueArray[0]).toEqual(-3);
46 expect(valueArray[1]).toEqual(-1);
47 });
48 it('Non-integer value leads to error', function () {
49 expect(function () { return new int64_tensors_1.Int64Scalar(0.4); }).toThrowError(/integer/);
50 expect(function () { return new int64_tensors_1.Int64Scalar(-3.2); }).toThrowError(/integer/);
51 });
52 it('Out-of-bound value leads to error', function () {
53 expect(function () { return new int64_tensors_1.Int64Scalar(2147483648); }).toThrowError(/bound/);
54 expect(function () { return new int64_tensors_1.Int64Scalar(2147483648 * 2); }).toThrowError(/bound/);
55 expect(function () { return new int64_tensors_1.Int64Scalar(-2147483648 - 1); }).toThrowError(/bound/);
56 });
57});