michael@0: function map_test(t, cases) michael@0: { michael@0: for (var i = 0; i < cases.length; i++) { michael@0: function c() { return t(cases[i].input); } michael@0: var expected = cases[i].expected; michael@0: assertEq(c(), expected); michael@0: } michael@0: } michael@0: michael@0: function lsh_inner(n) michael@0: { michael@0: var r; michael@0: for (var i = 0; i < 35; i++) michael@0: r = 0x1 << n; michael@0: return r; michael@0: } michael@0: map_test (lsh_inner, michael@0: [{input: 15, expected: 32768}, michael@0: {input: 55, expected: 8388608}, michael@0: {input: 1, expected: 2}, michael@0: {input: 0, expected: 1}]); michael@0: michael@0: function rsh_inner(n) michael@0: { michael@0: var r; michael@0: for (var i = 0; i < 35; i++) michael@0: r = 0x11010101 >> n; michael@0: return r; michael@0: } michael@0: map_test (rsh_inner, michael@0: [{input: 8, expected: 1114369}, michael@0: {input: 5, expected: 8914952}, michael@0: {input: 35, expected: 35659808}, michael@0: {input: -1, expected: 0}]); michael@0: michael@0: function ursh_inner(n) michael@0: { michael@0: var r; michael@0: for (var i = 0; i < 35; i++) michael@0: r = -55 >>> n; michael@0: return r; michael@0: } michael@0: map_test (ursh_inner, michael@0: [{input: 8, expected: 16777215}, michael@0: {input: 33, expected: 2147483620}, michael@0: {input: 0, expected: 4294967241}, michael@0: {input: 1, expected: 2147483620}]); michael@0: michael@0: function doMath_inner(cos) michael@0: { michael@0: var s = 0; michael@0: var sin = Math.sin; michael@0: for (var i = 0; i < 200; i++) michael@0: s = -Math.pow(sin(i) + cos(i * 0.75), 4); michael@0: return s; michael@0: } michael@0: function doMath() { michael@0: return doMath_inner(Math.cos); michael@0: } michael@0: assertEq(doMath(), -0.5405549555611059);