From aa0f966098a52c78dfb85a9eea5b3c481406ed04 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Sun, 22 Aug 2021 14:36:02 +0200 Subject: [PATCH] Added a few snapshot tests --- .eslintrc.js | 7 ++-- package.json | 1 - snapshots/noise2D.png | Bin 0 -> 3247 bytes snapshots/noise3D.png | Bin 0 -> 4228 bytes snapshots/noise4D.png | Bin 0 -> 3807 bytes snapshots/permutationTable.png | Bin 0 -> 340 bytes test/matches-snapshot.js | 65 +++++++++++++++++++++++++++++++++ test/simplex-noise-test.js | 27 +++++++++++--- 8 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 snapshots/noise2D.png create mode 100644 snapshots/noise3D.png create mode 100644 snapshots/noise4D.png create mode 100644 snapshots/permutationTable.png create mode 100644 test/matches-snapshot.js diff --git a/.eslintrc.js b/.eslintrc.js index c6d6015..dad4626 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,9 @@ module.exports = { 'env': { 'browser': true, - 'node': true + 'node': true, + 'mocha': true, + 'es2017': true }, 'extends': 'eslint:recommended', 'globals': { @@ -9,9 +11,6 @@ module.exports = { 'define': false, 'Float32Array': false }, - 'plugins': [ - 'mocha' - ], 'rules': { 'indent': [ 'error', diff --git a/package.json b/package.json index 8c5fd32..70e8d27 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "eslint": "^7.32.0", "eslint-config-standard": "^16.0.3", "eslint-plugin-import": "^2.24.1", - "eslint-plugin-mocha": "^9.0.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "mocha": "^9.1.0", diff --git a/snapshots/noise2D.png b/snapshots/noise2D.png new file mode 100644 index 0000000000000000000000000000000000000000..45abf0d58ccaabdd3bda29092a8d53730e39f3dc GIT binary patch literal 3247 zcmV;g3{dllP)c>v%(UZ5K{=APM;OD;vpCCYZ3QdPd@m*w}xVlgU{l1x%Oc6MiH=fVv%&{v)Z z{|`c{+&$$wIKN){$P(B010S~y@yXM#|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zFOEWAU=obN z;R%KD+3NMruXvtSd4rR2SZ@n*{roK5p=vjr7gQnO&SIH_VO6hTBSL?kdOQG$JZ>7< z_|vNwKfO99w8`fMapqyZ+bE}@+(D`%#{=nbFb;2C%(>iGB|OP6^<>?XfJ9~$Ab003 zFVDv=;S-Cooy2GEeZ9}ByowZ}u7kBEeu9F@`AyV7Sy8MU$M)Fw0Xu%=5$sLosYfj3 z%+Ym4&c3^fkTl+8Osiu>7tgO#szht~XgT+daw+t>FR~61)wI1a3WejCRL9(Mw}1Nh zxlC@ZCoZDQBh9g}>Gg~A7*z4JtFa$Yr8rD--O5uB=)^SQpx6Z!+x^j#e5n5Q_7B9r zC!=Q-+V*!!pl~&dh%(qVYttaLG}?vN_q`I`u=|Fb{4~Jm=0#E;nn%py;_2<1I~HCA zlP*}I-DZ=!7g2X;sI1z)%6mZ1Lv7$c(vDamxua3_?Y>{y3txk3?}gKX2~$@?jwX+xIrRHT{U24(f->}ZwqNH!d7;))o$Q+AGh)J{OT-4 zWm&Wbgj($;qwCS3^O)vlWHsxL@LOll++E;a*_DTQ#_PQmd>OvDjqB-ZUyDvc#CST3ElOp~Td#7* h^Q(!;OJ^F_@c(aH#L=O+xS0R|002ovPDHLkV1hiRfM5Us literal 0 HcmV?d00001 diff --git a/snapshots/noise3D.png b/snapshots/noise3D.png new file mode 100644 index 0000000000000000000000000000000000000000..6e01a34833341be18870f09f3021ffda952d9cb6 GIT binary patch literal 4228 zcmV-~5PR>5P)4`Gt%A#(*ND#K*5uVEoBQq2Jzo8_&5N+QqhGl-*ODr z<22+D?&-sX)x{IZIMnwOrxA&NJbKq{1lwP?F#{3|{O!ld^A{hpHSbYy5uGPd6}b3A z0tf~IJH&ed=U%7r1upH-(Hz*U-g`L6K;`E)uq(@z+=Mt|^|V#vICcX;zYf&3{5B%V zDG&*P5zqi~_mC$tE#=ouKAcbk1TI+;9VQHr@+;V&@@YTQA?hDG$Tj_eqOUxDzQsZj zDP%bV;3V?F5Mcz?LI~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3B%0 V?FEDk84Umc002ovPDHLkV1l}wSw;W= literal 0 HcmV?d00001 diff --git a/snapshots/permutationTable.png b/snapshots/permutationTable.png new file mode 100644 index 0000000000000000000000000000000000000000..e997e53d79414b4819fd97b0fb1f7d92505c7d34 GIT binary patch literal 340 zcmV-a0jvIrP)Zq16xkj69u_4qjQ$~4T}sha|6s4!-nQ$#Tqap_}I!c z^%w%LypwVY_7C&^87JDZe>`miBRqMl_WFPZl>5_P#g;+k0UCW=Qk~yC(E$vF^Om*oeBpW{ixq2l)qz6uN&}YDG6HZBL z19hdgNL5o{pi7#o=o2Lrph4j|lwx<$=Tw#wfM+@1sOC>yq>sj>_Q!6P)CB value == png.data[i*4]); + if(!identical) { + console.log(png.data); + writeImageSnapshot(actual, imageFilename.replace('.png', '.error.png')); + throw new Error('expected data to be identitcal'); + } + +} +exports.assertMatchesImage = assertMatchesImage; + +function writeImageSnapshot(actual, imageFilename) { + const png = new PNG({ + colorType: 0, + inputColorType: 0, + bitDepth: 16, + width: actual.width, + height: actual.height, + inputHasAlpha: false, + }); + if (actual.data.length*4 !== png.data.length) { + console.warn(actual.data.length, png.data.length); + throw new Error('Expected actual.data.length to match png.data.length'); + } + png.data.forEach((_,i, a) => a[i] = (i%4==3) ? 255 : actual.data[(i/4)|0]); + + fs.writeFileSync(path.join(snapshotsPath, imageFilename), PNG.sync.write(png.pack(), {colorType: 0} )); +} + +function sampleFunctionToImageData(f, width, height) { + let imageData = { + width, + height, + data: new Uint8ClampedArray(width*height) + }; + for(let y = 0; y < height; y++) { + for (let x = 0; x < width; x++) { + imageData.data[y*width+x] = f(x, y); + } + } + return imageData; +} +exports.sampleFunctionToImageData = sampleFunctionToImageData; \ No newline at end of file diff --git a/test/simplex-noise-test.js b/test/simplex-noise-test.js index 103f11c..8004404 100644 --- a/test/simplex-noise-test.js +++ b/test/simplex-noise-test.js @@ -1,8 +1,7 @@ -/* global describe, it, beforeEach */ - -var SimplexNoise = require('../simplex-noise'); -var Alea = require('alea'); -var assert = require('chai').assert; +const SimplexNoise = require('../simplex-noise'); +const Alea = require('alea'); +const assert = require('chai').assert; +const {assertMatchesImage, sampleFunctionToImageData} = require('./matches-snapshot.js'); describe('SimplexNoise', function() { function getRandom() { @@ -25,6 +24,12 @@ describe('SimplexNoise', function() { assert.equal(aTable[i], i); } }); + it('matches snapshot', function() { + var table = SimplexNoise._buildPermutationTable(getRandom()); + + const actual = {width: 16, height: 16, data: new Uint8ClampedArray(table)}; + assertMatchesImage(actual, 'permutationTable.png'); + }); }); describe('constructor', function() { @@ -96,6 +101,10 @@ describe('SimplexNoise', function() { it('should return similar values for similar inputs', function() { assert(Math.abs(simplex.noise2D(0.1, 0.2) - simplex.noise2D(0.101, 0.202)) < 0.1); }); + it('should match snapshot', function() { + const actual = sampleFunctionToImageData((x,y)=>simplex.noise2D(x/10,y/10)*128+128, 64, 64); + assertMatchesImage(actual, 'noise2D.png'); + }); }); describe('noise3D', function() { @@ -121,6 +130,10 @@ describe('SimplexNoise', function() { it('should return similar values for similar inputs', function() { assert(Math.abs(simplex.noise3D(0.1, 0.2, 0.3) - simplex.noise3D(0.101, 0.202, 0.303)) < 0.1); }); + it('should match snapshot', function() { + const actual = sampleFunctionToImageData((x,y)=>simplex.noise3D(x/10,y/10,(x+y)/2)*128+128, 64, 64); + assertMatchesImage(actual, 'noise3D.png'); + }); }); describe('noise4D', function() { @@ -150,6 +163,10 @@ describe('SimplexNoise', function() { simplex.noise4D(0.101, 0.202, 0.303, 0.404) ) < 0.1); }); + it('should match snapshot', function() { + const actual = sampleFunctionToImageData((x,y)=>simplex.noise4D(x/10,y/10,x/4,y/3)*128+128, 64, 64); + assertMatchesImage(actual, 'noise4D.png'); + }); }); }); });