From 9b6ca5cb8d7849491939b37e423038d6883bf14e Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Fri, 6 Sep 2024 12:56:00 +0200 Subject: [PATCH] More tests --- src/utils/utils.ts | 9 +++++++-- tests/unit/utils/collections.test.ts | 2 +- tests/unit/utils/utils.test.ts | 13 +++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/unit/utils/utils.test.ts diff --git a/src/utils/utils.ts b/src/utils/utils.ts index ce5622c5..4ebd7eed 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -161,12 +161,17 @@ function tempColor(badness: number): [number, number, number] { let saturation = 1.0; let lightness = 0.75; try { - saturation = parseFloat( + const rSaturation = parseFloat( SDFGRenderer.getCssProperty('--overlay-color-saturation') ); - lightness = parseFloat( + if (rSaturation !== undefined && !Number.isNaN(rSaturation)) + saturation = rSaturation; + + const rLightness = parseFloat( SDFGRenderer.getCssProperty('--overlay-color-lightness') ); + if (rLightness !== undefined && !Number.isNaN(rLightness)) + lightness = rLightness; } catch (_ignored) { // Ignored. } diff --git a/tests/unit/utils/collections.test.ts b/tests/unit/utils/collections.test.ts index 7f11091f..20463216 100644 --- a/tests/unit/utils/collections.test.ts +++ b/tests/unit/utils/collections.test.ts @@ -1,6 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { AccessStack, LinkedStack } from "../../../src/utils/collections"; +import { AccessStack, LinkedStack } from '../../../src/utils/collections'; function testLinkedStackConstruction(): void { const lStack = new LinkedStack(); diff --git a/tests/unit/utils/utils.test.ts b/tests/unit/utils/utils.test.ts new file mode 100644 index 00000000..22c5aeeb --- /dev/null +++ b/tests/unit/utils/utils.test.ts @@ -0,0 +1,13 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + +import { getTempColorHslString } from '../../../src'; + +function testTempColor(): void { + expect(getTempColorHslString(1.0)).toBe('hsl(0,100%,75%)'); + expect(getTempColorHslString(0.0)).toBe('hsl(120,100%,75%)'); + expect(getTempColorHslString(0.5)).toBe('hsl(60,100%,75%)'); +} + +describe('Test utility functions', () => { + test('Badness to temperature color conversion', testTempColor); +});