From 74ffb66f40678f9279d9bbc7a4a31ac3eba7573d Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Wed, 18 Dec 2024 00:53:44 +0530 Subject: [PATCH 1/6] Refactor test helper functions for improved readability and consistency --- test/helpers/test.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/helpers/test.js b/test/helpers/test.js index dcc6c128..eef0e626 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -59,31 +59,31 @@ }, // ---------- - equalsWithVariance: function ( value1, value2, variance ) { - return Math.abs( value1 - value2 ) <= variance; + equalsWithVariance: function (value1, value2, variance) { + return Math.abs(value1 - value2) <= variance; }, // ---------- - assessNumericValue: function ( assert, value1, value2, variance, message ) { - assert.ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance ); + assessNumericValue: function (assert, actual, expected, variance, message) { + assert.ok( + Util.equalsWithVariance(actual, expected, variance), + message + " Actual: " + actual + " Expected: " + expected + " Variance: " + variance + ); }, // ---------- assertPointsEquals: function (assert, pointA, pointB, precision, message) { - Util.assessNumericValue(assert, pointA.x, pointB.x, precision, message + " x: "); - Util.assessNumericValue(assert, pointA.y, pointB.y, precision, message + " y: "); + Util.assessNumericValue(assert, pointA.x, pointB.x, precision, message + " x: "); + Util.assessNumericValue(assert, pointA.y, pointB.y, precision, message + " y: "); }, // ---------- - assertRectangleEquals: function (assert, rectA, rectB, precision, message) { - Util.assessNumericValue(assert, rectA.x, rectB.x, precision, message + " x: "); - Util.assessNumericValue(assert, rectA.y, rectB.y, precision, message + " y: "); - Util.assessNumericValue(assert, rectA.width, rectB.width, precision, - message + " width: "); - Util.assessNumericValue(assert, rectA.height, rectB.height, precision, - message + " height: "); - Util.assessNumericValue(assert, rectA.degrees, rectB.degrees, precision, - message + " degrees: "); + assertRectangleEquals: function (assert, rectA, rectB, precision, message) { + Util.assessNumericValue(assert, rectA.x, rectB.x, precision, message + " x: "); + Util.assessNumericValue(assert, rectA.y, rectB.y, precision, message + " y: "); + Util.assessNumericValue(assert, rectA.width, rectB.width, precision, message + " width: "); + Util.assessNumericValue(assert, rectA.height, rectB.height, precision, message + " height: "); + Util.assessNumericValue(assert, rectA.degrees, rectB.degrees, precision, message + " degrees: "); }, // ---------- From 33c3d4b38099d4b8f0ef6b833c024ec878babdb6 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Thu, 19 Dec 2024 15:24:34 +0530 Subject: [PATCH 2/6] Corrected arguments name and fixed the identation issue --- test/helpers/test.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/helpers/test.js b/test/helpers/test.js index eef0e626..eb860cbf 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -59,31 +59,31 @@ }, // ---------- - equalsWithVariance: function (value1, value2, variance) { - return Math.abs(value1 - value2) <= variance; + equalsWithVariance: function (actual, expected, variance) { + return Math.abs(actual - expected) <= variance; }, // ---------- assessNumericValue: function (assert, actual, expected, variance, message) { - assert.ok( - Util.equalsWithVariance(actual, expected, variance), - message + " Actual: " + actual + " Expected: " + expected + " Variance: " + variance - ); + assert.ok( + Util.equalsWithVariance(actual, expected, variance), + message + " Actual: " + actual + " Expected: " + expected + " Variance: " + variance + ); }, // ---------- - assertPointsEquals: function (assert, pointA, pointB, precision, message) { - Util.assessNumericValue(assert, pointA.x, pointB.x, precision, message + " x: "); - Util.assessNumericValue(assert, pointA.y, pointB.y, precision, message + " y: "); + assertPointEquals: function (assert, actualPoint, expectedPoint, precision, message) { + Util.assessNumericValue(assert, actualPoint.x, expectedPoint.x, precision, message + " x: "); + Util.assessNumericValue(assert, actualPoint.y, expectedPoint.y, precision, message + " y: "); }, // ---------- - assertRectangleEquals: function (assert, rectA, rectB, precision, message) { - Util.assessNumericValue(assert, rectA.x, rectB.x, precision, message + " x: "); - Util.assessNumericValue(assert, rectA.y, rectB.y, precision, message + " y: "); - Util.assessNumericValue(assert, rectA.width, rectB.width, precision, message + " width: "); - Util.assessNumericValue(assert, rectA.height, rectB.height, precision, message + " height: "); - Util.assessNumericValue(assert, rectA.degrees, rectB.degrees, precision, message + " degrees: "); + assertRectangleEquals: function (assert, actualRect, expectedRect, precision, message) { + Util.assessNumericValue(assert, actualRect.x, expectedRect.x, precision, message + " x: "); + Util.assessNumericValue(assert, actualRect.y, expectedRect.y, precision, message + " y: "); + Util.assessNumericValue(assert, actualRect.width, expectedRect.width, precision, message + " width: "); + Util.assessNumericValue(assert, actualRect.height, expectedRect.height, precision, message + " height: "); + Util.assessNumericValue(assert, actualRect.degrees, expectedRect.degrees, precision, message + " degrees: "); }, // ---------- From 15627ee18ee34a6382dd449be4093b08e548c133 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Thu, 19 Dec 2024 15:52:14 +0530 Subject: [PATCH 3/6] Bump version to 5.0.1 and update argument names for clarity in helper functions --- package-lock.json | 4 ++-- test/helpers/test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c92de879..55381341 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "openseadragon", - "version": "5.0.0", + "version": "5.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "openseadragon", - "version": "5.0.0", + "version": "5.0.1", "license": "BSD-3-Clause", "devDependencies": { "eslint-plugin-compat": "^4.1.2", diff --git a/test/helpers/test.js b/test/helpers/test.js index eb860cbf..7e34babd 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -59,8 +59,8 @@ }, // ---------- - equalsWithVariance: function (actual, expected, variance) { - return Math.abs(actual - expected) <= variance; + equalsWithVariance: function (value1, value2, variance) { + return Math.abs(value1 - value2) <= variance; }, // ---------- From a0fcfc20add9f3a271a88fb253bd337fe9b5ff4b Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Thu, 19 Dec 2024 16:12:27 +0530 Subject: [PATCH 4/6] Correct function names in test helpers for consistency --- package-lock.json | 6 +++--- test/helpers/test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55381341..a1bb9b6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "openseadragon", - "version": "5.0.1", + "version": "5.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "openseadragon", - "version": "5.0.1", + "version": "5.0.0", "license": "BSD-3-Clause", "devDependencies": { "eslint-plugin-compat": "^4.1.2", @@ -5217,4 +5217,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/helpers/test.js b/test/helpers/test.js index 7e34babd..2745bcb0 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -59,7 +59,7 @@ }, // ---------- - equalsWithVariance: function (value1, value2, variance) { + equalsWithVariance: function (value1, value2, variance) { return Math.abs(value1 - value2) <= variance; }, @@ -72,13 +72,13 @@ }, // ---------- - assertPointEquals: function (assert, actualPoint, expectedPoint, precision, message) { + assertPointsEquals: function (assert, actualPoint, expectedPoint, precision, message) { Util.assessNumericValue(assert, actualPoint.x, expectedPoint.x, precision, message + " x: "); Util.assessNumericValue(assert, actualPoint.y, expectedPoint.y, precision, message + " y: "); }, // ---------- - assertRectangleEquals: function (assert, actualRect, expectedRect, precision, message) { + assertRectangleEquals: function (assert, actualRect, expectedRect, precision, message) { Util.assessNumericValue(assert, actualRect.x, expectedRect.x, precision, message + " x: "); Util.assessNumericValue(assert, actualRect.y, expectedRect.y, precision, message + " y: "); Util.assessNumericValue(assert, actualRect.width, expectedRect.width, precision, message + " width: "); From 8fdd639bf0ef76c84c92e0b7bd28a02a447d72d5 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Thu, 19 Dec 2024 16:30:04 +0530 Subject: [PATCH 5/6] Rename parameters in helper functions for clarity and consistency --- test/helpers/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/helpers/test.js b/test/helpers/test.js index 2745bcb0..4e94c365 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -59,8 +59,8 @@ }, // ---------- - equalsWithVariance: function (value1, value2, variance) { - return Math.abs(value1 - value2) <= variance; + equalsWithVariance: function (actual, expected, variance) { + return Math.abs(actual - expected) <= variance; }, // ---------- @@ -78,7 +78,7 @@ }, // ---------- - assertRectangleEquals: function (assert, actualRect, expectedRect, precision, message) { + assertRectangleEquals: function (assert, actualRect, expectedRect, precision, message) { Util.assessNumericValue(assert, actualRect.x, expectedRect.x, precision, message + " x: "); Util.assessNumericValue(assert, actualRect.y, expectedRect.y, precision, message + " y: "); Util.assessNumericValue(assert, actualRect.width, expectedRect.width, precision, message + " width: "); From d31562e34fc45f3201c222c89e108a983eeb82ed Mon Sep 17 00:00:00 2001 From: Harsh Kumar Gupta Date: Fri, 20 Dec 2024 00:31:40 +0530 Subject: [PATCH 6/6] Fix the function arguments for the required file --- test/modules/events.js | 8 ++++---- test/modules/navigator.js | 31 +++++++++++++++------------- test/modules/rectangle.js | 43 +++++++++++++++------------------------ test/modules/spring.js | 4 ++-- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/test/modules/events.js b/test/modules/events.js index 2c26c0f5..2bf83e1a 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -333,10 +333,10 @@ assert.equal( quickClick, expected.quickClick, expected.description + 'clickHandler event.quick matches expected (' + expected.quickClick + ')' ); } if ('speed' in expected) { - Util.assessNumericValue(expected.speed, speed, 1.0, expected.description + 'Drag speed '); + Util.assessNumericValue(assert, speed, expected.speed, 1.0, expected.description + 'Drag speed'); } if ('direction' in expected) { - Util.assessNumericValue(expected.direction, direction, 0.2, expected.description + 'Drag direction '); + Util.assessNumericValue(assert, direction, expected.direction, 0.2, expected.description + 'Drag direction'); } }; @@ -868,7 +868,7 @@ simulateDblTap(); var zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(assert, originalZoom, zoom, epsilon, + Util.assessNumericValue(assert, zoom, originalZoom, epsilon, "Zoom on double tap should be prevented"); // Reset event handler to original @@ -878,7 +878,7 @@ originalZoom *= viewer.zoomPerClick; zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(assert, originalZoom, zoom, epsilon, + Util.assessNumericValue(assert, zoom, originalZoom, epsilon, "Zoom on double tap should not be prevented"); diff --git a/test/modules/navigator.js b/test/modules/navigator.js index cb5c425f..4f1e3bfc 100644 --- a/test/modules/navigator.js +++ b/test/modules/navigator.js @@ -52,15 +52,15 @@ var assessNavigatorLocation = function (assert, expectedX, expectedY) { navigatorElement = navigatorElement || $(".navigator"); - Util.assessNumericValue(assert, expectedX, navigatorElement.offset().left, 10, ' Navigator x Position'); - Util.assessNumericValue(assert, expectedY, navigatorElement.offset().top, 10, ' Navigator y Position'); + Util.assessNumericValue(assert, navigatorElement.offset().left, expectedX, 10, ' Navigator x Position'); + Util.assessNumericValue(assert, navigatorElement.offset().top, expectedY, 10, ' Navigator y Position'); }; var assessNavigatorSize = function (assert, expectedWidth, expectedHeight, msg) { msg = msg || ""; navigatorElement = navigatorElement || $(".navigator"); - Util.assessNumericValue(assert, expectedWidth, navigatorElement.width(), 2, ' Navigator Width ' + msg); - Util.assessNumericValue(assert, expectedHeight, navigatorElement.height(), 2, ' Navigator Height ' + msg); + Util.assessNumericValue(assert, navigatorElement.width(), expectedWidth, 2, ' Navigator Width ' + msg); + Util.assessNumericValue(assert, navigatorElement.height(), expectedHeight, 2, ' Navigator Height ' + msg); }; var assessNavigatorAspectRatio = function (assert, expectedAspectRatio, variance, msg) { @@ -68,8 +68,8 @@ navigatorElement = navigatorElement || $(".navigator"); Util.assessNumericValue( assert, - expectedAspectRatio, navigatorElement.width() / navigatorElement.height(), + expectedAspectRatio, variance, ' Navigator Aspect Ratio ' + msg ); @@ -80,13 +80,14 @@ navigatorElement = navigatorElement || $(".navigator"); Util.assessNumericValue( assert, - expectedArea, navigatorElement.width() * navigatorElement.height(), + expectedArea, Math.max(navigatorElement.width(), navigatorElement.height()), ' Navigator Area ' + msg ); }; + var navigatorRegionBoundsInPoints = function () { var regionBoundsInPoints, expectedDisplayRegionWidth, @@ -142,22 +143,23 @@ var expectedBounds = navigatorRegionBoundsInPoints(); Util.assessNumericValue( assert, - expectedBounds.width, displayRegion.width() + viewer.navigator.totalBorderWidths.x, + expectedBounds.width, 2, status + ' Width synchronization' ); Util.assessNumericValue( assert, - expectedBounds.height, displayRegion.height() + viewer.navigator.totalBorderWidths.y, + expectedBounds.height, 2, status + ' Height synchronization' ); - Util.assessNumericValue(assert, expectedBounds.x, displayRegion.position().left, 2, status + ' Left synchronization'); - Util.assessNumericValue(assert, expectedBounds.y, displayRegion.position().top, 2, status + ' Top synchronization'); + Util.assessNumericValue(assert, displayRegion.position().left, expectedBounds.x, 2, status + ' Left synchronization'); + Util.assessNumericValue(assert, displayRegion.position().top, expectedBounds.y, 2, status + ' Top synchronization'); }; + var waitForViewer = function () { return function (assert, handler, count, lastDisplayRegionLeft, lastDisplayWidth) { var viewerAndNavigatorDisplayReady = false, @@ -271,14 +273,15 @@ } Util.assessNumericValue( assert, - 1 / viewer.source.aspectRatio / 2, viewer.viewport.getCenter().y, + 1 / viewer.source.aspectRatio / 2, yPositionVariance, ' Viewer at center, y coord' ); - Util.assessNumericValue(assert, 0.5, viewer.viewport.getCenter().x, 0.4, ' Viewer at center, x coord'); + Util.assessNumericValue(assert, viewer.viewport.getCenter().x, 0.5, 0.4, ' Viewer at center, x coord'); }; + var assessViewerInCorner = function (theContentCorner, assert) { return function () { var expectedXCoordinate, expectedYCoordinate; @@ -301,8 +304,8 @@ if (viewer.viewport.getBounds().width < 1) { Util.assessNumericValue( assert, - expectedXCoordinate, viewer.viewport.getBounds().x, + expectedXCoordinate, 0.04, ' Viewer at ' + theContentCorner + ', x coord' ); @@ -310,8 +313,8 @@ if (viewer.viewport.getBounds().height < 1 / viewer.source.aspectRatio) { Util.assessNumericValue( assert, - expectedYCoordinate, viewer.viewport.getBounds().y, + expectedYCoordinate, 0.04, ' Viewer at ' + theContentCorner + ', y coord' ); diff --git a/test/modules/rectangle.js b/test/modules/rectangle.js index 18ae8b3b..dbfc7ca0 100644 --- a/test/modules/rectangle.js +++ b/test/modules/rectangle.js @@ -22,37 +22,26 @@ assert.strictEqual(rect.degrees, 0, 'rect.degrees should be 0'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, -405); - Util.assessNumericValue(assert, Math.sqrt(2) / 2, rect.x, precision, - 'rect.x should be sqrt(2)/2'); - Util.assessNumericValue(assert, -Math.sqrt(2) / 2, rect.y, precision, - 'rect.y should be -sqrt(2)/2'); - Util.assessNumericValue(assert, 2, rect.width, precision, - 'rect.width should be 2'); - Util.assessNumericValue(assert, 1, rect.height, precision, - 'rect.height should be 1'); - assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + Util.assessNumericValue(assert, rect.x, Math.sqrt(2) / 2, precision, 'rect.x should be sqrt(2)/2'); + Util.assessNumericValue(assert, rect.y, -Math.sqrt(2) / 2, precision, 'rect.y should be -sqrt(2)/2'); + Util.assessNumericValue(assert, rect.width, 2, precision, 'rect.width should be 2'); + Util.assessNumericValue(assert, rect.height, 1, precision, 'rect.height should be 1'); + assert.strictEqual(rect.degrees, 45, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, 135); - Util.assessNumericValue(assert, -Math.sqrt(2), rect.x, precision, - 'rect.x should be -sqrt(2)'); - Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, - 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(assert, 2, rect.width, precision, - 'rect.width should be 2'); - Util.assessNumericValue(assert, 1, rect.height, precision, - 'rect.height should be 1'); - assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + Util.assessNumericValue(assert, rect.x, -Math.sqrt(2), precision, 'rect.x should be -sqrt(2)'); + Util.assessNumericValue(assert, rect.y, -Math.sqrt(2), precision, 'rect.y should be -sqrt(2)'); + Util.assessNumericValue(assert, rect.width, 2, precision, 'rect.width should be 2'); + Util.assessNumericValue(assert, rect.height, 1, precision, 'rect.height should be 1'); + assert.strictEqual(rect.degrees, 45, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 1, 585); - Util.assessNumericValue(assert, 0, rect.x, precision, - 'rect.x should be 0'); - Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, - 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(assert, 1, rect.width, precision, - 'rect.width should be 1'); - Util.assessNumericValue(assert, 1, rect.height, precision, - 'rect.height should be 1'); - assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + Util.assessNumericValue(assert, rect.x, 0, precision, 'rect.x should be 0'); + Util.assessNumericValue(assert, rect.y, -Math.sqrt(2), precision, 'rect.y should be -sqrt(2)'); + Util.assessNumericValue(assert, rect.width, 1, precision, 'rect.width should be 1'); + Util.assessNumericValue(assert, rect.height, 1, precision, 'rect.height should be 1'); + assert.strictEqual(rect.degrees, 45, 'rect.degrees should be 45'); + }); QUnit.test('getTopLeft', function(assert) { diff --git a/test/modules/spring.js b/test/modules/spring.js index c71839f8..57a6dad7 100644 --- a/test/modules/spring.js +++ b/test/modules/spring.js @@ -36,7 +36,7 @@ now = 500; spring.update(); - Util.assessNumericValue(assert, 5.5, spring.current.value, 0.00001, 'current value after first update'); + Util.assessNumericValue(assert, spring.current.value, 5.5, 0.00001, 'current value after first update'); assert.equal(spring.target.value, 6, 'target value after first update'); now = 1000; @@ -65,7 +65,7 @@ now = 500; spring.update(); - Util.assessNumericValue(assert, 1.41421, spring.current.value, 0.00001, 'current value after first update'); + Util.assessNumericValue(assert, spring.current.value, 1.41421, 0.00001, 'current value after first update'); assert.equal(spring.target.value, 2, 'target value after first update'); now = 1000;