|
| 1 | +// To test: Build Pyret, then cd to this directory, and type |
| 2 | +// node jsnums-test.js |
| 3 | + |
| 4 | +var Jasmine = require('jasmine'); |
| 5 | +var jazz = new Jasmine(); |
| 6 | +const R = require("requirejs"); |
| 7 | +var build = process.env["PHASE"] || "build/phaseA"; |
| 8 | +R.config({ |
| 9 | + waitSeconds: 15000, |
| 10 | + paths: { |
| 11 | + "pyret-base": "../../" + build |
| 12 | + } |
| 13 | +}); |
| 14 | +R(["pyret-base/js/js-numbers"], function(JN) { |
| 15 | + var sampleErrorBacks = { |
| 16 | + throwDomainError: function() { throw 'domainError'; }, |
| 17 | + throwLogNonPositive: function() { throw 'logNonPositive'; }, |
| 18 | + }; |
| 19 | + describe("check exceptions in js-numbers methods that can't be tested in Pyret", function() { |
| 20 | + it("bnpExp", function() { |
| 21 | + // BigInteger.*.expt calls bnPow, which calls bnpExp |
| 22 | + // shd raise exc for too-large |
| 23 | + expect(function() { JN.makeBignum(2).expt(JN.makeBignum(0xffffffff + 1), sampleErrorBacks); }).toThrow('domainError'); |
| 24 | + |
| 25 | + // BigInteger.*.log |
| 26 | + // should raise exception for arg <= 0 |
| 27 | + expect(function() { JN.makeBignum(-1).log(sampleErrorBacks); }).toThrow('logNonPositive'); |
| 28 | + |
| 29 | + // BigInteger.*asin |
| 30 | + // should raise exception for arg ∉ [-1, +1] |
| 31 | + expect(function() { JN.makeBignum(-1.5).asin(sampleErrorBacks); }).toThrow('domainError'); |
| 32 | + expect(function() { JN.makeBignum(+1.5).asin(sampleErrorBacks); }).toThrow('domainError'); |
| 33 | + |
| 34 | + // BigInteger.*acos |
| 35 | + // should raise exception for arg ∉ [-1, +1] |
| 36 | + expect(function() { JN.makeBignum(-1.5).acos(sampleErrorBacks); }).toThrow('domainError'); |
| 37 | + expect(function() { JN.makeBignum(+1.5).acos(sampleErrorBacks); }).toThrow('domainError'); |
| 38 | + |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + jazz.execute(); |
| 43 | + |
| 44 | +}); |
0 commit comments