From 205254cdb0f918b2aef08d30102a2a82cee67823 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 2 Oct 2024 14:17:43 +0200 Subject: [PATCH] add clamp tests --- .../packages/core/utils/math/clamp.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/utils/math/clamp.test.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/utils/math/clamp.test.ts b/src/Umbraco.Web.UI.Client/src/packages/core/utils/math/clamp.test.ts new file mode 100644 index 0000000000..69f806953e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/utils/math/clamp.test.ts @@ -0,0 +1,25 @@ +import { expect } from '@open-wc/testing'; +import { clamp } from './math.js'; + +describe('clamp', () => { + it('should not allow the returned value to be lower than min', () => { + expect(clamp(-1, 0, 1)).to.equal(0); + expect(clamp(-100, 5, 100)).to.equal(5); + expect(clamp(-50, -7, 20)).to.equal(-7); + expect(clamp(100, 500, 502)).to.equal(500); + }); + + it('should not allow the returned value to be higher than max', () => { + expect(clamp(2, 0, 1)).to.equal(1); + expect(clamp(100, 5, 100)).to.equal(100); + expect(clamp(50, -7, 20)).to.equal(20); + expect(clamp(1000, 500, 502)).to.equal(502); + }); + + it('should return the value if it is within the min and max', () => { + expect(clamp(0, 0, 1)).to.equal(0); + expect(clamp(12, 10, 50)).to.equal(12); + expect(clamp(-48, -50, 50)).to.equal(-48); + expect(clamp(501, 500, 502)).to.equal(501); + }); +});