Update Jasmine to version 4
For the unit-tests that were updated in this patch, note that I settled on simply using `toEqual` comparisons rather than updating the custom matchers (since those don't seem necessary any more). Please refer to the following resources for additional information: - https://github.com/jasmine/jasmine/blob/main/release_notes/4.0.0.md - https://github.com/jasmine/jasmine-npm/blob/main/release_notes/4.0.0.md - https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0
This commit is contained in:
parent
38e574f1d5
commit
457ff0d54a
30
package-lock.json
generated
30
package-lock.json
generated
@ -39,7 +39,7 @@
|
||||
"gulp-rename": "^2.0.0",
|
||||
"gulp-replace": "^1.1.3",
|
||||
"gulp-zip": "^5.1.0",
|
||||
"jasmine": "^3.99.0",
|
||||
"jasmine": "^4.0.1",
|
||||
"jsdoc": "^3.6.7",
|
||||
"jstransformer-markdown-it": "^2.1.0",
|
||||
"merge-stream": "^2.0.0",
|
||||
@ -8475,22 +8475,22 @@
|
||||
}
|
||||
},
|
||||
"node_modules/jasmine": {
|
||||
"version": "3.99.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz",
|
||||
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==",
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-4.0.1.tgz",
|
||||
"integrity": "sha512-NAf9b80ie0pAXLW2l+Fxc8s0Q6SjVgi81jOyHJRQuZ+fPjbVAnXNfN2nIwf5yoRjoSTROyRiETjr9Cr+nNBTVw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^7.1.6",
|
||||
"jasmine-core": "~3.99.0"
|
||||
"jasmine-core": "^4.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"jasmine": "bin/jasmine.js"
|
||||
}
|
||||
},
|
||||
"node_modules/jasmine-core": {
|
||||
"version": "3.99.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.0.tgz",
|
||||
"integrity": "sha512-+ZDaJlEfRopINQqgE+hvzRyDIQDeKfqqTvF8RzXsvU1yE3pBDRud2+Qfh9WvGgRpuzqxyQJVI6Amy5XQ11r/3w==",
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.0.tgz",
|
||||
"integrity": "sha512-tq24OCqHElgU9KDpb/8O21r1IfotgjIzalfW9eCmRR40LZpvwXT68iariIyayMwi0m98RDt16aljdbwK0sBMmQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/jasmine/node_modules/glob": {
|
||||
@ -25134,13 +25134,13 @@
|
||||
}
|
||||
},
|
||||
"jasmine": {
|
||||
"version": "3.99.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.99.0.tgz",
|
||||
"integrity": "sha512-YIThBuHzaIIcjxeuLmPD40SjxkEcc8i//sGMDKCgkRMVgIwRJf5qyExtlJpQeh7pkeoBSOe6lQEdg+/9uKg9mw==",
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-4.0.1.tgz",
|
||||
"integrity": "sha512-NAf9b80ie0pAXLW2l+Fxc8s0Q6SjVgi81jOyHJRQuZ+fPjbVAnXNfN2nIwf5yoRjoSTROyRiETjr9Cr+nNBTVw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.1.6",
|
||||
"jasmine-core": "~3.99.0"
|
||||
"jasmine-core": "^4.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"glob": {
|
||||
@ -25160,9 +25160,9 @@
|
||||
}
|
||||
},
|
||||
"jasmine-core": {
|
||||
"version": "3.99.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.0.tgz",
|
||||
"integrity": "sha512-+ZDaJlEfRopINQqgE+hvzRyDIQDeKfqqTvF8RzXsvU1yE3pBDRud2+Qfh9WvGgRpuzqxyQJVI6Amy5XQ11r/3w==",
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.0.tgz",
|
||||
"integrity": "sha512-tq24OCqHElgU9KDpb/8O21r1IfotgjIzalfW9eCmRR40LZpvwXT68iariIyayMwi0m98RDt16aljdbwK0sBMmQ==",
|
||||
"dev": true
|
||||
},
|
||||
"jest-worker": {
|
||||
|
@ -32,7 +32,7 @@
|
||||
"gulp-rename": "^2.0.0",
|
||||
"gulp-replace": "^1.1.3",
|
||||
"gulp-zip": "^5.1.0",
|
||||
"jasmine": "^3.99.0",
|
||||
"jasmine": "^4.0.1",
|
||||
"jsdoc": "^3.6.7",
|
||||
"jstransformer-markdown-it": "^2.1.0",
|
||||
"merge-stream": "^2.0.0",
|
||||
|
@ -19,6 +19,7 @@ const Jasmine = require("jasmine");
|
||||
|
||||
async function runTests(results) {
|
||||
const jasmine = new Jasmine();
|
||||
jasmine.exitOnCompletion = false;
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
jasmine.loadConfig({
|
||||
@ -49,10 +50,7 @@ async function runTests(results) {
|
||||
suiteStarted(result) {},
|
||||
});
|
||||
|
||||
return new Promise(resolve => {
|
||||
jasmine.onComplete(resolve);
|
||||
jasmine.execute();
|
||||
});
|
||||
return jasmine.execute();
|
||||
}
|
||||
|
||||
exports.runTests = runTests;
|
||||
|
@ -21,52 +21,6 @@ import { PostScriptLexer, PostScriptParser } from "../../src/core/ps_parser.js";
|
||||
import { StringStream } from "../../src/core/stream.js";
|
||||
|
||||
describe("function", function () {
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
toMatchArray(util, customEqualityTesters) {
|
||||
return {
|
||||
compare(actual, expected) {
|
||||
const result = {};
|
||||
if (actual.length !== expected.length) {
|
||||
result.pass = false;
|
||||
result.message =
|
||||
"Array length: " +
|
||||
actual.length +
|
||||
", expected: " +
|
||||
expected.length;
|
||||
return result;
|
||||
}
|
||||
result.pass = true;
|
||||
for (let i = 0; i < expected.length; i++) {
|
||||
const a = actual[i],
|
||||
b = expected[i];
|
||||
if (Array.isArray(b)) {
|
||||
if (a.length !== b.length) {
|
||||
result.pass = false;
|
||||
break;
|
||||
}
|
||||
for (let j = 0; j < a.length; j++) {
|
||||
const suba = a[j],
|
||||
subb = b[j];
|
||||
if (suba !== subb) {
|
||||
result.pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (a !== b) {
|
||||
result.pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe("PostScriptParser", function () {
|
||||
function parse(program) {
|
||||
const stream = new StringStream(program);
|
||||
@ -81,34 +35,34 @@ describe("function", function () {
|
||||
const number = 999;
|
||||
const program = parse("{ " + number + " }");
|
||||
const expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("parses negative numbers", function () {
|
||||
const number = -999;
|
||||
const program = parse("{ " + number + " }");
|
||||
const expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("parses negative floats", function () {
|
||||
const number = 3.3;
|
||||
const program = parse("{ " + number + " }");
|
||||
const expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("parses operators", function () {
|
||||
const program = parse("{ sub }");
|
||||
const expectedProgram = ["sub"];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("parses if statements", function () {
|
||||
const program = parse("{ { 99 } if }");
|
||||
const expectedProgram = [3, "jz", 99];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("parses ifelse statements", function () {
|
||||
const program = parse("{ { 99 } { 44 } ifelse }");
|
||||
const expectedProgram = [5, "jz", 99, 6, "j", 44];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
it("handles missing brackets", function () {
|
||||
expect(function () {
|
||||
@ -119,7 +73,7 @@ describe("function", function () {
|
||||
const number = 3.3;
|
||||
const program = parse("{ " + number + " }#");
|
||||
const expectedProgram = [number];
|
||||
expect(program).toMatchArray(expectedProgram);
|
||||
expect(program).toEqual(expectedProgram);
|
||||
});
|
||||
});
|
||||
|
||||
@ -136,313 +90,313 @@ describe("function", function () {
|
||||
it("pushes stack", function () {
|
||||
const stack = evaluate("{ 99 }");
|
||||
const expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles if with true", function () {
|
||||
const stack = evaluate("{ 1 {99} if }");
|
||||
const expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles if with false", function () {
|
||||
const stack = evaluate("{ 0 {99} if }");
|
||||
const expectedStack = [];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles ifelse with true", function () {
|
||||
const stack = evaluate("{ 1 {99} {77} ifelse }");
|
||||
const expectedStack = [99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles ifelse with false", function () {
|
||||
const stack = evaluate("{ 0 {99} {77} ifelse }");
|
||||
const expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles nested if", function () {
|
||||
const stack = evaluate("{ 1 {1 {77} if} if }");
|
||||
const expectedStack = [77];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
|
||||
it("abs", function () {
|
||||
const stack = evaluate("{ -2 abs }");
|
||||
const expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("adds", function () {
|
||||
const stack = evaluate("{ 1 2 add }");
|
||||
const expectedStack = [3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("boolean and", function () {
|
||||
const stack = evaluate("{ true false and }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("bitwise and", function () {
|
||||
const stack = evaluate("{ 254 1 and }");
|
||||
const expectedStack = [254 & 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the inverse tangent of a number", function () {
|
||||
const stack = evaluate("{ 90 atan }");
|
||||
const expectedStack = [Math.atan(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles bitshifting ", function () {
|
||||
const stack = evaluate("{ 50 2 bitshift }");
|
||||
const expectedStack = [200];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the ceiling value", function () {
|
||||
const stack = evaluate("{ 9.9 ceiling }");
|
||||
const expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("copies", function () {
|
||||
const stack = evaluate("{ 99 98 2 copy }");
|
||||
const expectedStack = [99, 98, 99, 98];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the cosine of a number", function () {
|
||||
const stack = evaluate("{ 90 cos }");
|
||||
const expectedStack = [Math.cos(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("converts to int", function () {
|
||||
const stack = evaluate("{ 9.9 cvi }");
|
||||
const expectedStack = [9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("converts negatives to int", function () {
|
||||
const stack = evaluate("{ -9.9 cvi }");
|
||||
const expectedStack = [-9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("converts to real", function () {
|
||||
const stack = evaluate("{ 55.34 cvr }");
|
||||
const expectedStack = [55.34];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("divides", function () {
|
||||
const stack = evaluate("{ 6 5 div }");
|
||||
const expectedStack = [1.2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("maps division by zero to infinity", function () {
|
||||
const stack = evaluate("{ 6 0 div }");
|
||||
const expectedStack = [Infinity];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("duplicates", function () {
|
||||
const stack = evaluate("{ 99 dup }");
|
||||
const expectedStack = [99, 99];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("accepts an equality", function () {
|
||||
const stack = evaluate("{ 9 9 eq }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects an inequality", function () {
|
||||
const stack = evaluate("{ 9 8 eq }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("exchanges", function () {
|
||||
const stack = evaluate("{ 44 99 exch }");
|
||||
const expectedStack = [99, 44];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles exponentiation", function () {
|
||||
const stack = evaluate("{ 10 2 exp }");
|
||||
const expectedStack = [100];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("pushes false onto the stack", function () {
|
||||
const stack = evaluate("{ false }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the floor value", function () {
|
||||
const stack = evaluate("{ 9.9 floor }");
|
||||
const expectedStack = [9];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles greater than or equal to", function () {
|
||||
const stack = evaluate("{ 10 9 ge }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects less than for greater than or equal to", function () {
|
||||
const stack = evaluate("{ 8 9 ge }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles greater than", function () {
|
||||
const stack = evaluate("{ 10 9 gt }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects less than or equal for greater than", function () {
|
||||
const stack = evaluate("{ 9 9 gt }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("divides to integer", function () {
|
||||
const stack = evaluate("{ 2 3 idiv }");
|
||||
const expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("divides to negative integer", function () {
|
||||
const stack = evaluate("{ -2 3 idiv }");
|
||||
const expectedStack = [0];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("duplicates index", function () {
|
||||
const stack = evaluate("{ 4 3 2 1 2 index }");
|
||||
const expectedStack = [4, 3, 2, 1, 3];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles less than or equal to", function () {
|
||||
const stack = evaluate("{ 9 10 le }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects greater than for less than or equal to", function () {
|
||||
const stack = evaluate("{ 10 9 le }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the natural logarithm", function () {
|
||||
const stack = evaluate("{ 10 ln }");
|
||||
const expectedStack = [Math.log(10)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the base 10 logarithm", function () {
|
||||
const stack = evaluate("{ 100 log }");
|
||||
const expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("handles less than", function () {
|
||||
const stack = evaluate("{ 9 10 lt }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects greater than or equal to for less than", function () {
|
||||
const stack = evaluate("{ 10 9 lt }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("performs the modulo operation", function () {
|
||||
const stack = evaluate("{ 4 3 mod }");
|
||||
const expectedStack = [1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("multiplies two numbers (positive result)", function () {
|
||||
const stack = evaluate("{ 9 8 mul }");
|
||||
const expectedStack = [72];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("multiplies two numbers (negative result)", function () {
|
||||
const stack = evaluate("{ 9 -8 mul }");
|
||||
const expectedStack = [-72];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("accepts an inequality", function () {
|
||||
const stack = evaluate("{ 9 8 ne }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rejects an equality", function () {
|
||||
const stack = evaluate("{ 9 9 ne }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("negates", function () {
|
||||
const stack = evaluate("{ 4.5 neg }");
|
||||
const expectedStack = [-4.5];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("boolean not", function () {
|
||||
const stack = evaluate("{ true not }");
|
||||
const expectedStack = [false];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("bitwise not", function () {
|
||||
const stack = evaluate("{ 12 not }");
|
||||
const expectedStack = [-13];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("boolean or", function () {
|
||||
const stack = evaluate("{ true false or }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("bitwise or", function () {
|
||||
const stack = evaluate("{ 254 1 or }");
|
||||
const expectedStack = [254 | 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("pops stack", function () {
|
||||
const stack = evaluate("{ 1 2 pop }");
|
||||
const expectedStack = [1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rolls stack right", function () {
|
||||
const stack = evaluate("{ 1 3 2 2 4 1 roll }");
|
||||
const expectedStack = [2, 1, 3, 2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rolls stack left", function () {
|
||||
const stack = evaluate("{ 1 3 2 2 4 -1 roll }");
|
||||
const expectedStack = [3, 2, 2, 1];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("rounds a number", function () {
|
||||
const stack = evaluate("{ 9.52 round }");
|
||||
const expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates the sine of a number", function () {
|
||||
const stack = evaluate("{ 90 sin }");
|
||||
const expectedStack = [Math.sin(90)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates a square root (integer)", function () {
|
||||
const stack = evaluate("{ 100 sqrt }");
|
||||
const expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates a square root (float)", function () {
|
||||
const stack = evaluate("{ 99 sqrt }");
|
||||
const expectedStack = [Math.sqrt(99)];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("subtracts (positive result)", function () {
|
||||
const stack = evaluate("{ 6 4 sub }");
|
||||
const expectedStack = [2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("subtracts (negative result)", function () {
|
||||
const stack = evaluate("{ 4 6 sub }");
|
||||
const expectedStack = [-2];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("pushes true onto the stack", function () {
|
||||
const stack = evaluate("{ true }");
|
||||
const expectedStack = [true];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("truncates a number", function () {
|
||||
const stack = evaluate("{ 35.004 truncate }");
|
||||
const expectedStack = [35];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
it("calculates an exclusive or value", function () {
|
||||
const stack = evaluate("{ 3 9 xor }");
|
||||
const expectedStack = [10];
|
||||
expect(stack).toMatchArray(expectedStack);
|
||||
expect(stack).toEqual(expectedStack);
|
||||
});
|
||||
});
|
||||
|
||||
@ -465,9 +419,7 @@ describe("function", function () {
|
||||
for (let i = 0; i < samples.length; i++) {
|
||||
const out = new Float32Array(samples[i].output.length);
|
||||
fn(samples[i].input, 0, out, 0);
|
||||
expect(Array.prototype.slice.call(out, 0)).toMatchArray(
|
||||
samples[i].output
|
||||
);
|
||||
expect(Array.prototype.slice.call(out, 0)).toEqual(samples[i].output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,36 +18,6 @@ import { PredictorStream } from "../../src/core/predictor_stream.js";
|
||||
import { Stream } from "../../src/core/stream.js";
|
||||
|
||||
describe("stream", function () {
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
toMatchTypedArray(util, customEqualityTesters) {
|
||||
return {
|
||||
compare(actual, expected) {
|
||||
const result = {};
|
||||
if (actual.length !== expected.length) {
|
||||
result.pass = false;
|
||||
result.message =
|
||||
"Array length: " +
|
||||
actual.length +
|
||||
", expected: " +
|
||||
expected.length;
|
||||
return result;
|
||||
}
|
||||
result.pass = true;
|
||||
for (let i = 0, ii = expected.length; i < ii; i++) {
|
||||
const a = actual[i],
|
||||
b = expected[i];
|
||||
if (a !== b) {
|
||||
result.pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
describe("PredictorStream", function () {
|
||||
it("should decode simple predictor data", function () {
|
||||
const dict = new Dict();
|
||||
@ -65,9 +35,7 @@ describe("stream", function () {
|
||||
const predictor = new PredictorStream(input, /* length = */ 9, dict);
|
||||
const result = predictor.getBytes(6);
|
||||
|
||||
expect(result).toMatchTypedArray(
|
||||
new Uint8Array([100, 3, 101, 2, 102, 1])
|
||||
);
|
||||
expect(result).toEqual(new Uint8Array([100, 3, 101, 2, 102, 1]));
|
||||
|
||||
predictor.reset();
|
||||
const clampedResult = predictor.getBytes(6, /* forceClamped = */ true);
|
||||
|
Loading…
Reference in New Issue
Block a user