diff --git a/jest.config.ts b/jest.config.ts index c8bc35c..b1928ec 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -29,6 +29,7 @@ const config: JestConfigWithTsJest = { '^map$': '/src/main/map', '^math$': '/src/main/math', '^palette$': '/src/main/color/palette', + '^palettes$': '/src/main/color/palette/palettes', '^palette-colors$': '/src/main/color/palette/palette-colors', '^random$': '/src/main/random', '^unit-test/shared$': '/src/test/shared' diff --git a/src/test/color/color.test.ts b/src/test/color/color.test.ts index 64f8dbd..b0c4c22 100644 --- a/src/test/color/color.test.ts +++ b/src/test/color/color.test.ts @@ -19,15 +19,15 @@ import P5Lib from 'p5'; import {Color} from 'color'; import {SketchContext} from 'context'; +import {_0437F2, _0FFF4F, _7A00F5, _FF6BB5} from 'palette-colors'; import { - checkForValidHexColorString, checkForValidHexColorStringWithAlpha, ColorComponents, + checkForValidHexColorString, + checkForValidHexColorStringWithAlpha, colorToColorComponents, p5ColorToColorComponents -} from '../shared/color'; -import {PaletteColor} from "palette"; -import {_0437F2, _0FFF4F, _7A00F5, _FF6BB5} from "palette-colors"; +} from 'unit-test/shared'; const p5: P5Lib = SketchContext.p5; @@ -80,19 +80,21 @@ describe('color tests', (): void => { test.each( [ - _0437F2, - _0FFF4F, - _7A00F5, - _FF6BB5 + {hex: _0437F2.HEX, paletteColor: _0437F2}, + {hex: _0FFF4F.HEX, paletteColor: _0FFF4F}, + {hex: _7A00F5.HEX, paletteColor: _7A00F5}, + {hex: _FF6BB5.HEX, paletteColor: _FF6BB5} ] - )('color built with PaletteColor object', - (c: PaletteColor): void => { + )('$# color built with PaletteColor object: $hex', + ({hex, paletteColor}): void => { + expect(hex).toBeTruthy(); const expected: ColorComponents = { - r: c.RGB.R, g: c.RGB.G, b: c.RGB.B, a: 255 + r: paletteColor.RGB.R, g: paletteColor.RGB.G, b: paletteColor.RGB.B, a: 255 } - const expectedName: string = c.NAME; - const color: Color = new Color(c); + const expectedName: string = paletteColor.NAME; + + const color: Color = new Color(paletteColor); expect(colorToColorComponents(color)).toEqual(expected); expect(p5ColorToColorComponents(color.color)).toEqual(expected); expect(color.name).toBe(expectedName); diff --git a/src/test/color/palette/palettes/miscellaneous/brittni.test.ts b/src/test/color/palette/palettes/miscellaneous/brittni.test.ts index d1c4fa5..0f9908c 100644 --- a/src/test/color/palette/palettes/miscellaneous/brittni.test.ts +++ b/src/test/color/palette/palettes/miscellaneous/brittni.test.ts @@ -15,7 +15,22 @@ * See the GNU Affero General Public License for more details. */ -// import {BRITTNI} from 'palettes'; +import {PaletteColor} from 'palette'; +import {_0437F2, _0FFF4F, _121212, _7A00F5, _FF6BB5} from 'palette-colors'; +import {BRITTNI} from 'palettes'; -// TODO - brittni unit tests -// TODO - misc map unit tests +import {checkForValidPalette} from 'unit-test/shared'; + +describe('BRITTNI palette tests', (): void => { + const colors: PaletteColor[] = [ + _121212, + _0437F2, + _0FFF4F, + _7A00F5, + _FF6BB5 + ] + + test('BRITTNI palette is valid', (): void => { + checkForValidPalette(BRITTNI, colors); + }); +}); diff --git a/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts b/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts new file mode 100644 index 0000000..1cce25b --- /dev/null +++ b/src/test/color/palette/palettes/miscellaneous/miscellaneous-palettes.test.ts @@ -0,0 +1,40 @@ +/* + * 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 {Palette} from 'palette'; +import {BRITTNI, MISCELLANEOUS_PALETTES} from 'palettes'; + +import {checkForPaletteInMap, checkForValidStringMap} from 'unit-test/shared'; + +describe('miscellaneous palettes map test', (): void => { + const ALL_MISC_PALETTES: [{name: string, palette: Palette}] = [ + {name: BRITTNI.NAME, palette: BRITTNI} + ] + + test('valid map: MISCELLANEOUS_PALETTES', (): void => { + checkForValidStringMap(MISCELLANEOUS_PALETTES, ALL_MISC_PALETTES.length); + }); + + test.each( + ALL_MISC_PALETTES + )('$# palette successfully added to map: $name', + ({name, palette}): void => { + expect(name).toBeTruthy(); + checkForPaletteInMap(palette, MISCELLANEOUS_PALETTES); + } + ); +}); diff --git a/src/test/shared/map.ts b/src/test/shared/map.ts index 16f2109..ce8082b 100644 --- a/src/test/shared/map.ts +++ b/src/test/shared/map.ts @@ -17,7 +17,7 @@ import {StringMap} from 'map'; -export function checkForValidStringMap(map: StringMap): void { +export function checkForValidStringMap(map: StringMap, expectedSize?: number): void { expect(map).toBeTruthy(); expect(map.size).toBeGreaterThan(0); @@ -28,4 +28,8 @@ export function checkForValidStringMap(map: StringMap): void { expect(values.length).toBe(keys.length); expect(keys.length).toBe(map.size); + + if (expectedSize) { + expect(map.size).toBe(expectedSize); + } } diff --git a/src/test/shared/palette.ts b/src/test/shared/palette.ts index 9da4700..ad26fd3 100644 --- a/src/test/shared/palette.ts +++ b/src/test/shared/palette.ts @@ -15,9 +15,11 @@ * See the GNU Affero General Public License for more details. */ -import {PaletteColor} from 'palette'; +import {StringMap} from 'map'; +import {Palette, PaletteColor} from 'palette'; import {ColorComponents} from './color'; +import {checkForValidStringMap} from './map'; import {checkNumberWithinAmount} from './math'; export function checkComponents(actual: ColorComponents, expected: PaletteColor): void { @@ -25,3 +27,23 @@ export function checkComponents(actual: ColorComponents, expected: PaletteColor) checkNumberWithinAmount(actual.g, expected.RGB.G, 1); checkNumberWithinAmount(actual.b, expected.RGB.B, 1); } + +export function checkForValidPalette(palette: Palette, expectedColors?: PaletteColor[]): void { + expect(palette).toBeTruthy(); + expect(palette.NAME).toBeTruthy(); + expect(palette.SOURCE).toBeTruthy(); + expect(palette.COLORS).toBeTruthy(); + expect(palette.COLORS.length).toBeGreaterThanOrEqual(2); + + if (expectedColors) { + expect(palette.COLORS).toEqual(expectedColors); + } +} + +export function checkForPaletteInMap(palette: Palette, map: StringMap): void { + checkForValidStringMap(map); + checkForValidPalette(palette); + const actualPalette: Palette | undefined = map.get(palette.NAME); + expect(actualPalette).toBeTruthy(); + expect(actualPalette).toEqual(palette); +}