• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Test data for double encoding and decoding.
3 */
4goog.module('protobuf.binary.doubleTestPairs');
5
6const BufferDecoder = goog.require('protobuf.binary.BufferDecoder');
7const {createBufferDecoder} = goog.require('protobuf.binary.bufferDecoderHelper');
8
9/**
10 * An array of Pairs of double values and their bit representation.
11 * This is used to test encoding and decoding from the protobuf wire format.
12 * @return {!Array<{name: string, doubleValue:number, bufferDecoder:
13 *     !BufferDecoder}>}
14 */
15function getDoublePairs() {
16  const doublePairs = [
17    {
18      name: 'zero',
19      doubleValue: 0,
20      bufferDecoder:
21          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
22    },
23    {
24      name: 'minus zero',
25      doubleValue: -0,
26      bufferDecoder:
27          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80)
28    },
29    {
30      name: 'one',
31      doubleValue: 1,
32      bufferDecoder:
33          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F)
34    },
35    {
36      name: 'minus one',
37      doubleValue: -1,
38      bufferDecoder:
39          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF)
40    },
41
42    {
43      name: 'PI',
44      doubleValue: Math.PI,
45      bufferDecoder:
46          createBufferDecoder(0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40)
47
48    },
49    {
50      name: 'max value',
51      doubleValue: Number.MAX_VALUE,
52      bufferDecoder:
53          createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F)
54    },
55    {
56      name: 'min value',
57      doubleValue: Number.MIN_VALUE,
58      bufferDecoder:
59          createBufferDecoder(0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
60    },
61    {
62      name: 'Infinity',
63      doubleValue: Infinity,
64      bufferDecoder:
65          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F)
66    },
67    {
68      name: 'minus Infinity',
69      doubleValue: -Infinity,
70      bufferDecoder:
71          createBufferDecoder(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF)
72    },
73    {
74      name: 'Number.MAX_SAFE_INTEGER',
75      doubleValue: Number.MAX_SAFE_INTEGER,
76      bufferDecoder:
77          createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x43)
78    },
79    {
80      name: 'Number.MIN_SAFE_INTEGER',
81      doubleValue: Number.MIN_SAFE_INTEGER,
82      bufferDecoder:
83          createBufferDecoder(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0xC3)
84    },
85  ];
86  return [...doublePairs];
87}
88
89exports = {getDoublePairs};
90