diff --git a/src/main/color/palette/palettes/miscellaneous/brittni.ts b/src/main/color/palette/palettes/miscellaneous/brittni.ts index c5d8976..364256e 100644 --- a/src/main/color/palette/palettes/miscellaneous/brittni.ts +++ b/src/main/color/palette/palettes/miscellaneous/brittni.ts @@ -50,10 +50,6 @@ export const BRITTNI: Palette = { _FF6BB5 ], - // TODO - Verify '#000000' does not contain '#FFFFFF' - // TODO - verify '#FFFFFF' does not contain '#000000' - // TODO - verify only keys values are palette hexes, '#000000, and '#FFFFFF' - // TODO - Unit Test - Verify AA.NORMAL Pass for all pairs CONTRAST_MAP: { '#000000': ['#0FFF4F', '#FF6BB5'], '#FFFFFF': ['#121212', '#0437F2', '#7A00F5'], diff --git a/src/test/color/palette/palette-colors/all-palette-colors.test.ts b/src/test/color/palette/palette-colors/all-palette-colors.test.ts index 4010f82..85bf409 100644 --- a/src/test/color/palette/palette-colors/all-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/all-palette-colors.test.ts @@ -31,7 +31,7 @@ import { checkComponents, checkForValidStringMap, p5ColorToColorComponents, - ColorComponents, checkForValidHexColorString + ColorComponents, checkForValidHexColorString, checkForEquivalentComponents } from 'unit-test/shared'; const p5: P5Lib = SketchContext.p5; @@ -73,8 +73,7 @@ function makeRGBKey(RGB: {R: number, G: number, B: number}): string { describe('all palette colors', (): void => { test('valid string map: ALL_PALETTE_COLORS', (): void => { - checkForValidStringMap(ALL_PALETTE_COLORS); - expect(ALL_PALETTE_COLORS.size).toBe(ALL_HEXES.length); + checkForValidStringMap(ALL_PALETTE_COLORS, ALL_HEXES.length); }); test('all colors are unique', (): void => { @@ -117,6 +116,10 @@ describe('all palette colors', (): void => { const rgb: P5Lib.Color = p5.color(c.RGB.R, c.RGB.G, c.RGB.B); const rgbComponents: ColorComponents = p5ColorToColorComponents(rgb); checkComponents(rgbComponents, c); + + checkForEquivalentComponents(hslComponents, hexComponents); + checkForEquivalentComponents(hslComponents, rgbComponents); + checkForEquivalentComponents(rgbComponents, hexComponents); } ); @@ -136,4 +139,8 @@ describe('all palette colors', (): void => { expect(new Set(ALL_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palette-colors/black/black-palette-colors.test.ts b/src/test/color/palette/palette-colors/black/black-palette-colors.test.ts index 8fac064..fb9ab59 100644 --- a/src/test/color/palette/palette-colors/black/black-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/black/black-palette-colors.test.ts @@ -32,4 +32,8 @@ describe('black palette colors', (): void => { expect(new Set(BLACK_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palette-colors/blue/blue-palette-colors.test.ts b/src/test/color/palette/palette-colors/blue/blue-palette-colors.test.ts index 8a3570a..eb32125 100644 --- a/src/test/color/palette/palette-colors/blue/blue-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/blue/blue-palette-colors.test.ts @@ -32,4 +32,8 @@ describe('blue palette colors', (): void => { expect(new Set(BLUE_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palette-colors/green/green-palette-colors.test.ts b/src/test/color/palette/palette-colors/green/green-palette-colors.test.ts index 10feb47..a718288 100644 --- a/src/test/color/palette/palette-colors/green/green-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/green/green-palette-colors.test.ts @@ -32,4 +32,8 @@ describe('green palette colors', (): void => { expect(new Set(GREEN_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palette-colors/pink/pink-palette-colors.test.ts b/src/test/color/palette/palette-colors/pink/pink-palette-colors.test.ts index e78f8af..c8d45f8 100644 --- a/src/test/color/palette/palette-colors/pink/pink-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/pink/pink-palette-colors.test.ts @@ -33,4 +33,8 @@ describe('pink palette colors', (): void => { expect(new Set(PINK_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palette-colors/purple/purple-palette-colors.test.ts b/src/test/color/palette/palette-colors/purple/purple-palette-colors.test.ts index 7e8a84e..15d267d 100644 --- a/src/test/color/palette/palette-colors/purple/purple-palette-colors.test.ts +++ b/src/test/color/palette/palette-colors/purple/purple-palette-colors.test.ts @@ -33,4 +33,8 @@ describe('purple palette colors', (): void => { expect(new Set(PURPLE_PALETTE_COLORS.keys)).toContain(hexString); } ); + + test.todo('all color objects are in the map'); + + test.todo('all keys match palette color hex'); }); diff --git a/src/test/color/palette/palettes/all-palettes.test.ts b/src/test/color/palette/palettes/all-palettes.test.ts new file mode 100644 index 0000000..d423abe --- /dev/null +++ b/src/test/color/palette/palettes/all-palettes.test.ts @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2024 brittni and the polar bear LLC. + * + * This file is a part of brittni and the polar bear's Generative Art Library, + * which is released under the GNU Affero General Public License, Version 3.0. + * You may not use this file except in compliance with the license. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. See LICENSE or go to + * https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. + */ + +import {StringMap} from 'map'; +import {Palette, PaletteColor} from 'palette'; +import {ALL_PALETTES, MISCELLANEOUS_PALETTES} from 'palettes'; + +import { + checkForPaletteInMap, + checkForPaletteNameKeyMatch, + checkForValidStringMap, + checkForValidContrastMap +} from 'unit-test/shared'; + +function getPaletteArray(map: StringMap): {palette: Palette}[] { + const palettes: Palette[] = Array.from(map.values); + return palettes.map((p: Palette): {palette: Palette} => { + return {palette: p} + }); +} + +const EXPECTED_PALETTES: {palette: Palette}[] = []; +EXPECTED_PALETTES.push( + ...(getPaletteArray(MISCELLANEOUS_PALETTES)) +); + +describe('all palettes tests', (): void => { + test('valid string map: ALL_PALETTES', (): void => { + checkForValidStringMap(ALL_PALETTES, EXPECTED_PALETTES.length); + }); + + test.each( + EXPECTED_PALETTES + )('$# palette successfully added to map: $palette.NAME', + ({palette}): void => { + checkForPaletteInMap(palette, ALL_PALETTES); + } + ); + + test('all keys match associated palette name', (): void => { + checkForPaletteNameKeyMatch(ALL_PALETTES); + }); + + test.each( + EXPECTED_PALETTES + )('$# palette has valid contrast map: $palette.NAME', + ({palette}): void => { + checkForValidContrastMap(palette); + } + ); + + test('all palettes are unique', (): void => { + const colorSets: Set> = new Set>(); + + for (const palette of ALL_PALETTES.values) { + const hexStrings: string[] = palette.COLORS.map((color: PaletteColor): string => { + return color.HEX; + }); + const hexSet: Set = new Set(hexStrings); + + expect(colorSets).not.toContainEqual(hexSet); + colorSets.add(hexSet); + } + }); +}); diff --git a/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts b/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts index c1a9bf6..8c30ada 100644 --- a/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts +++ b/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts @@ -18,22 +18,26 @@ import {Palette} from 'palette'; import {BRITTNI, MISCELLANEOUS_PALETTES} from 'palettes'; -import {checkForPaletteInMap, checkForValidStringMap} from 'unit-test/shared'; +import {checkForPaletteInMap, checkForPaletteNameKeyMatch, checkForValidStringMap} from 'unit-test/shared'; -describe('miscellaneous palettes map test', (): void => { - const ALL_MISC_PALETTES: {palette: Palette}[] = [ - {palette: BRITTNI} - ] +const EXPECTED_PALETTES: {palette: Palette}[] = [ + {palette: BRITTNI} +] - test('valid map: MISCELLANEOUS_PALETTES', (): void => { - checkForValidStringMap(MISCELLANEOUS_PALETTES, ALL_MISC_PALETTES.length); +describe('miscellaneous palettes map test', (): void => { + test('valid string map: MISCELLANEOUS_PALETTES', (): void => { + checkForValidStringMap(MISCELLANEOUS_PALETTES, EXPECTED_PALETTES.length); }); test.each( - ALL_MISC_PALETTES + EXPECTED_PALETTES )('$# palette successfully added to map: $palette.NAME', ({palette}): void => { checkForPaletteInMap(palette, MISCELLANEOUS_PALETTES); } ); + + test('all keys match associated palette name', (): void => { + checkForPaletteNameKeyMatch(MISCELLANEOUS_PALETTES); + }); }); diff --git a/src/test/shared/color.ts b/src/test/shared/color.ts index b7071ec..8e50c55 100644 --- a/src/test/shared/color.ts +++ b/src/test/shared/color.ts @@ -19,6 +19,7 @@ import P5Lib from 'p5'; import {Color, ColorSelector, ColorSelectorType} from 'color'; import {SketchContext} from 'context'; +import {checkNumberWithinAmount} from "./math"; const p5: P5Lib = SketchContext.p5; @@ -86,3 +87,9 @@ export function checkForValidHexColorStringWithAlpha(hex: string): void { const isValid: boolean = hexWithAlphaPattern.test(hex); expect(isValid).toBeTruthy(); } + +export function checkForEquivalentComponents(actual: ColorComponents, expected: ColorComponents): void { + checkNumberWithinAmount(actual.r, expected.r, 1); + checkNumberWithinAmount(actual.g, expected.g, 1); + checkNumberWithinAmount(actual.b, expected.b, 1); +} diff --git a/src/test/shared/index.ts b/src/test/shared/index.ts index 0d75f92..da9bf78 100644 --- a/src/test/shared/index.ts +++ b/src/test/shared/index.ts @@ -20,4 +20,4 @@ export * from './map'; export * from './math'; export * from './palette'; export * from './random'; -export * from './palette-color'; +export * from './palette-colors'; diff --git a/src/test/shared/palette-color.ts b/src/test/shared/palette-colors.ts similarity index 100% rename from src/test/shared/palette-color.ts rename to src/test/shared/palette-colors.ts diff --git a/src/test/shared/palette.ts b/src/test/shared/palette.ts index ad26fd3..2cc6235 100644 --- a/src/test/shared/palette.ts +++ b/src/test/shared/palette.ts @@ -18,9 +18,10 @@ import {StringMap} from 'map'; import {Palette, PaletteColor} from 'palette'; -import {ColorComponents} from './color'; +import {checkForValidHexColorString, ColorComponents} from './color'; import {checkForValidStringMap} from './map'; import {checkNumberWithinAmount} from './math'; +import {ColorContrastAssessor, ContrastFontSize, ContrastStandard} from "color-contrast"; export function checkComponents(actual: ColorComponents, expected: PaletteColor): void { checkNumberWithinAmount(actual.r, expected.RGB.R, 1); @@ -47,3 +48,45 @@ export function checkForPaletteInMap(palette: Palette, map: StringMap): expect(actualPalette).toBeTruthy(); expect(actualPalette).toEqual(palette); } + +export function checkForPaletteNameKeyMatch(map: StringMap): void { + for (const key of map.keys) { + const palette: Palette | undefined = map.get(key); + expect(palette).toBeTruthy(); + + if (palette) { + expect(palette.NAME).toBe(key); + } + } +} + +export function checkForValidContrastMap(palette: Palette): void { + checkForValidPalette(palette); + expect(palette.CONTRAST_MAP['#000000']).not.toContain('#FFFFFF'); + expect(palette.CONTRAST_MAP['#FFFFFF']).not.toContain('#000000'); + + const validHexes: string[] = palette.COLORS.map((color: PaletteColor): string => { + return color.HEX; + }); + validHexes.push('#000000'); + validHexes.push('#FFFFFF'); + + for (const key in palette.CONTRAST_MAP) { + checkForValidHexColorString(key); + expect(validHexes).toContain(key); + + for (const hex of palette.CONTRAST_MAP[key]) { + checkForValidHexColorString(hex); + expect(validHexes).toContain(hex); + + const meetsRatio: boolean = + ColorContrastAssessor.meetsContrastStandard( + key, + hex, + ContrastStandard.AA, + ContrastFontSize.NORMAL + ); + expect(meetsRatio).toBeTruthy(); + } + } +}