MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 86 lines 2.2 kB view raw
1import { test, summary } from './helpers.js'; 2 3console.log('TCO Shift/Comparison Operator Tests\n'); 4 5function identity(x) { 6 return x; 7} 8 9function shiftLeft(n) { 10 if (n <= 0) return identity(1) << 3; 11 return shiftLeft(n - 1); 12} 13test('f() << N result', shiftLeft(5), 8); 14 15function shiftRight(n) { 16 if (n <= 0) return identity(64) >> 2; 17 return shiftRight(n - 1); 18} 19test('f() >> N result', shiftRight(5), 16); 20 21function shiftRightUnsigned(n) { 22 if (n <= 0) return identity(-1) >>> 24; 23 return shiftRightUnsigned(n - 1); 24} 25test('f() >>> N result', shiftRightUnsigned(5), 255); 26 27function lessThan(n) { 28 if (n <= 0) return identity(3) < 5; 29 return lessThan(n - 1); 30} 31test('f() < N result', lessThan(3), true); 32 33function greaterThan(n) { 34 if (n <= 0) return identity(10) > 5; 35 return greaterThan(n - 1); 36} 37test('f() > N result', greaterThan(3), true); 38 39function lessEq(n) { 40 if (n <= 0) return identity(5) <= 5; 41 return lessEq(n - 1); 42} 43test('f() <= N result', lessEq(3), true); 44 45function greaterEq(n) { 46 if (n <= 0) return identity(5) >= 10; 47 return greaterEq(n - 1); 48} 49test('f() >= N result', greaterEq(3), false); 50 51function deepShiftLeft(n) { 52 if (n <= 0) return identity(1) << 3; 53 return deepShiftLeft(n - 1); 54} 55test('deep f()<<N value correct', deepShiftLeft(500), 8); 56 57function deepShiftRight(n) { 58 if (n <= 0) return identity(64) >> 2; 59 return deepShiftRight(n - 1); 60} 61test('deep f()>>N value correct', deepShiftRight(500), 16); 62 63function deepUnsignedShift(n) { 64 if (n <= 0) return identity(-1) >>> 24; 65 return deepUnsignedShift(n - 1); 66} 67test('deep f()>>>N value correct', deepUnsignedShift(500), 255); 68 69function recurseShiftArg(n) { 70 if (n <= 0) return 'done'; 71 return recurseShiftArg((n - 1) >> 0); 72} 73test('shift inside arg (tail-eligible)', recurseShiftArg(100000), 'done'); 74 75function ternaryShift(n) { 76 return n <= 0 ? identity(1) << 4 : ternaryShift(n - 1); 77} 78test('ternary with shift in then-branch', ternaryShift(5), 16); 79 80function ternaryBothShift(flag) { 81 return flag ? identity(1) << 2 : identity(1) >> 1; 82} 83test('ternary both shift true', ternaryBothShift(true), 4); 84test('ternary both shift false', ternaryBothShift(false), 0); 85 86summary();