bigint-and-bigint.js (4505B)
1 // Copyright (C) 2017 Josh Wolfe. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: Non-strict equality comparison of BigInt values 5 esid: sec-abstract-equality-comparison 6 info: | 7 1. If Type(x) is the same as Type(y), then 8 a. Return the result of performing Strict Equality Comparison x === y. 9 10 sec-numeric-types-bigint-equal 11 BigInt::equal (x, y) 12 13 The abstract operation BigInt::equal with two arguments x and y of BigInt type returns true if x and y have the same mathematical integer value and false otherwise. 14 15 features: [BigInt] 16 ---*/ 17 assert.sameValue(0n == 0n, true, 'The result of (0n == 0n) is true'); 18 assert.sameValue(1n == 1n, true, 'The result of (1n == 1n) is true'); 19 assert.sameValue(-1n == -1n, true, 'The result of (-1n == -1n) is true'); 20 assert.sameValue(0n == -0n, true, 'The result of (0n == -0n) is true'); 21 assert.sameValue(-0n == 0n, true, 'The result of (-0n == 0n) is true'); 22 assert.sameValue(0n == 1n, false, 'The result of (0n == 1n) is false'); 23 assert.sameValue(1n == 0n, false, 'The result of (1n == 0n) is false'); 24 assert.sameValue(0n == -1n, false, 'The result of (0n == -1n) is false'); 25 assert.sameValue(-1n == 0n, false, 'The result of (-1n == 0n) is false'); 26 assert.sameValue(1n == -1n, false, 'The result of (1n == -1n) is false'); 27 assert.sameValue(-1n == 1n, false, 'The result of (-1n == 1n) is false'); 28 29 assert.sameValue( 30 0x1fffffffffffff01n == 0x1fffffffffffff01n, 31 true, 32 'The result of (0x1fffffffffffff01n == 0x1fffffffffffff01n) is true' 33 ); 34 35 assert.sameValue( 36 0x1fffffffffffff01n == 0x1fffffffffffff02n, 37 false, 38 'The result of (0x1fffffffffffff01n == 0x1fffffffffffff02n) is false' 39 ); 40 41 assert.sameValue( 42 0x1fffffffffffff02n == 0x1fffffffffffff01n, 43 false, 44 'The result of (0x1fffffffffffff02n == 0x1fffffffffffff01n) is false' 45 ); 46 47 assert.sameValue( 48 -0x1fffffffffffff01n == -0x1fffffffffffff01n, 49 true, 50 'The result of (-0x1fffffffffffff01n == -0x1fffffffffffff01n) is true' 51 ); 52 53 assert.sameValue( 54 -0x1fffffffffffff01n == -0x1fffffffffffff02n, 55 false, 56 'The result of (-0x1fffffffffffff01n == -0x1fffffffffffff02n) is false' 57 ); 58 59 assert.sameValue( 60 -0x1fffffffffffff02n == -0x1fffffffffffff01n, 61 false, 62 'The result of (-0x1fffffffffffff02n == -0x1fffffffffffff01n) is false' 63 ); 64 65 assert.sameValue( 66 0x10000000000000000n == 0n, 67 false, 68 'The result of (0x10000000000000000n == 0n) is false' 69 ); 70 71 assert.sameValue( 72 0n == 0x10000000000000000n, 73 false, 74 'The result of (0n == 0x10000000000000000n) is false' 75 ); 76 77 assert.sameValue( 78 0x10000000000000000n == 1n, 79 false, 80 'The result of (0x10000000000000000n == 1n) is false' 81 ); 82 83 assert.sameValue( 84 1n == 0x10000000000000000n, 85 false, 86 'The result of (1n == 0x10000000000000000n) is false' 87 ); 88 89 assert.sameValue( 90 0x10000000000000000n == -1n, 91 false, 92 'The result of (0x10000000000000000n == -1n) is false' 93 ); 94 95 assert.sameValue( 96 -1n == 0x10000000000000000n, 97 false, 98 'The result of (-1n == 0x10000000000000000n) is false' 99 ); 100 101 assert.sameValue( 102 0x10000000000000001n == 0n, 103 false, 104 'The result of (0x10000000000000001n == 0n) is false' 105 ); 106 107 assert.sameValue( 108 0n == 0x10000000000000001n, 109 false, 110 'The result of (0n == 0x10000000000000001n) is false' 111 ); 112 113 assert.sameValue( 114 -0x10000000000000000n == 0n, 115 false, 116 'The result of (-0x10000000000000000n == 0n) is false' 117 ); 118 119 assert.sameValue( 120 0n == -0x10000000000000000n, 121 false, 122 'The result of (0n == -0x10000000000000000n) is false' 123 ); 124 125 assert.sameValue( 126 -0x10000000000000000n == 1n, 127 false, 128 'The result of (-0x10000000000000000n == 1n) is false' 129 ); 130 131 assert.sameValue( 132 1n == -0x10000000000000000n, 133 false, 134 'The result of (1n == -0x10000000000000000n) is false' 135 ); 136 137 assert.sameValue( 138 -0x10000000000000000n == -1n, 139 false, 140 'The result of (-0x10000000000000000n == -1n) is false' 141 ); 142 143 assert.sameValue( 144 -1n == -0x10000000000000000n, 145 false, 146 'The result of (-1n == -0x10000000000000000n) is false' 147 ); 148 149 assert.sameValue( 150 -0x10000000000000001n == 0n, 151 false, 152 'The result of (-0x10000000000000001n == 0n) is false' 153 ); 154 155 assert.sameValue( 156 0n == -0x10000000000000001n, 157 false, 158 'The result of (0n == -0x10000000000000001n) is false' 159 ); 160 161 assert.sameValue( 162 0x10000000000000000n == 0x100000000n, 163 false, 164 'The result of (0x10000000000000000n == 0x100000000n) is false' 165 ); 166 167 assert.sameValue( 168 0x100000000n == 0x10000000000000000n, 169 false, 170 'The result of (0x100000000n == 0x10000000000000000n) is false' 171 ); 172 173 reportCompare(0, 0);