Skip to content

Commit

Permalink
#189 Add new color (pumpkin vapour) to palette color maps and unit te…
Browse files Browse the repository at this point in the history
…sts (passing)
  • Loading branch information
azurepolarbear committed Nov 20, 2024
1 parent 0e48376 commit 5010397
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 650 deletions.
9 changes: 8 additions & 1 deletion src/main/color/palette/palette-colors/orange/pc-ffa852.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@
// black-pass
// luminance: 0.4987445986

// TODO - current step: Step 5: Add the Color to the `PaletteColor` Maps
// TODO - current step: Step 8: Add Documentation

import { ColorNameManager } from 'color';
import { Discriminators } from 'discriminator';
import { PaletteColor } from 'palette';

import { ALL_PALETTE_COLORS, ORANGE_PALETTE_COLORS } from '../palette-color-maps';

export const PC_FFA852: PaletteColor = {
HEX: '#FFA852',
RGB: { R: 255, G: 168, B: 82 },
HSL: { H: 30, S: 100, L: 66 },
NAME: 'pumpkin vapour',
DISCRIMINATOR: Discriminators.PALETTE_COLOR
};

ALL_PALETTE_COLORS.setUndefinedKey(PC_FFA852.HEX, PC_FFA852);
ORANGE_PALETTE_COLORS.setUndefinedKey(PC_FFA852.HEX, PC_FFA852);
ColorNameManager.addColor(PC_FFA852);
325 changes: 164 additions & 161 deletions src/test/color/palette/palette-colors/all-palette-colors.test.ts
Original file line number Diff line number Diff line change
@@ -1,161 +1,164 @@
// /*
// * 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 P5Lib from 'p5';
//
// import { Color } from 'color';
// import { PaletteColor } from 'palette';
// import { ALL_PALETTE_COLORS } from 'palette-colors';
// import { P5Context } from 'sketch-context';
//
// import {
// ColorComponents,
// BLACK_HEXES,
// BLUE_HEXES,
// BROWN_HEXES,
// GRAY_HEXES,
// GREEN_HEXES,
// PINK_HEXES,
// PURPLE_HEXES,
// RED_HEXES,
// checkComponents,
// checkForValidStringMap,
// p5ColorToColorComponents,
// checkForValidHexColorString,
// checkForEquivalentComponents,
// checkForValidPaletteColor, WHITE_HEXES
// } from 'unit-test/shared';
//
// const ALL_HEXES: { hexString: string }[] = [];
// ALL_HEXES.push(
// ...BLACK_HEXES,
// ...BLUE_HEXES,
// ...BROWN_HEXES,
// ...GRAY_HEXES,
// ...GREEN_HEXES,
// ...PINK_HEXES,
// ...PURPLE_HEXES,
// ...RED_HEXES,
// ...WHITE_HEXES
// );
//
// function makeHSLKey(HSL: { H: number; S: number; L: number }): string {
// let key: string = '';
// key += HSL.H.toString() + '.';
// key += HSL.S.toString() + '.';
// key += HSL.L.toString();
// return key;
// }
//
// function makeRGBKey(RGB: { R: number; G: number; B: number }): string {
// let key: string = '';
// key += RGB.R.toString() + '.';
// key += RGB.G.toString() + '.';
// key += RGB.B.toString();
// return key;
// }
//
// describe('all palette colors', (): void => {
// test('valid string map: ALL_PALETTE_COLORS', (): void => {
// checkForValidStringMap(ALL_PALETTE_COLORS, ALL_HEXES.length);
// });
//
// test.each(
// ALL_HEXES
// )('$# - successful addition of color: $hexString',
// ({ hexString }): void => {
// expect(hexString).toBeTruthy();
// checkForValidHexColorString(hexString);
//
// const pc: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
// expect(pc).toBeTruthy();
//
// if (pc) {
// expect(pc.HEX).toBe(hexString);
// }
// }
// );
//
// test.each(
// ALL_HEXES
// )('$# - valid color: $hexString',
// ({ hexString }): void => {
// expect(hexString).toBeTruthy();
// checkForValidHexColorString(hexString);
//
// const pc: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
// expect(pc).toBeTruthy();
//
// if (pc) {
// checkForValidPaletteColor(pc);
// }
// }
// );
//
// test('all colors are unique', (): void => {
// const hexValues: Set<string> = new Set<string>();
// const hslValues: Set<string> = new Set<string>();
// const rgbValues: Set<string> = new Set<string>();
// const names: Set<string> = new Set<string>();
//
// for (const c of ALL_PALETTE_COLORS.values) {
// const hex: string = c.HEX.toLowerCase();
// expect(hexValues).not.toContain(hex);
// hexValues.add(hex);
//
// const hsl: string = makeHSLKey(c.HSL);
// expect(hslValues).not.toContain(hsl);
// hslValues.add(hsl);
//
// const rgb: string = makeRGBKey(c.RGB);
// expect(rgbValues).not.toContain(rgb);
// rgbValues.add(rgb);
//
// const name: string = c.NAME.toLowerCase();
// expect(names).not.toContain(name);
// names.add(name);
// }
// });
//
// test.each(
// ALL_HEXES
// )('$# - consistent color: $hexString',
// ({ hexString }): void => {
// const p5: P5Lib = P5Context.p5;
// const c: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
// expect(c).toBeTruthy();
//
// if (c) {
// const hsl: P5Lib.Color = Color.getHSLColor(c.HSL.H, c.HSL.S, c.HSL.L);
// const hslComponents: ColorComponents = p5ColorToColorComponents(hsl);
// checkComponents(hslComponents, c);
//
// const hex: P5Lib.Color = p5.color(c.HEX);
// const hexComponents: ColorComponents = p5ColorToColorComponents(hex);
// checkComponents(hexComponents, c);
//
// 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);
// }
// }
// );
// });
/*
* 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 P5Lib from 'p5';

import { Color } from 'color';
import { PaletteColor } from 'palette';
import { ALL_PALETTE_COLORS } from 'palette-colors';
import { P5Context } from 'sketch-context';

import {
ColorComponents,
BLACK_HEXES,
BLUE_HEXES,
BROWN_HEXES,
GRAY_HEXES,
GREEN_HEXES,
ORANGE_HEXES,
PINK_HEXES,
PURPLE_HEXES,
RED_HEXES,
WHITE_HEXES,
checkComponents,
checkForValidStringMap,
p5ColorToColorComponents,
checkForValidHexColorString,
checkForEquivalentComponents,
checkForValidPaletteColor
} from 'unit-test/shared';

const ALL_HEXES: { hexString: string; }[] = [];
ALL_HEXES.push(
...BLACK_HEXES,
...BLUE_HEXES,
...BROWN_HEXES,
...GRAY_HEXES,
...GREEN_HEXES,
...ORANGE_HEXES,
...PINK_HEXES,
...PURPLE_HEXES,
...RED_HEXES,
...WHITE_HEXES
);

function makeHSLKey(HSL: { H: number; S: number; L: number; }): string {
let key: string = '';
key += HSL.H.toString() + '.';
key += HSL.S.toString() + '.';
key += HSL.L.toString();
return key;
}

function makeRGBKey(RGB: { R: number; G: number; B: number; }): string {
let key: string = '';
key += RGB.R.toString() + '.';
key += RGB.G.toString() + '.';
key += RGB.B.toString();
return key;
}

describe('all palette colors', (): void => {
test('valid string map: ALL_PALETTE_COLORS', (): void => {
checkForValidStringMap(ALL_PALETTE_COLORS, ALL_HEXES.length);
});

test.each(
ALL_HEXES
)('$# - successful addition of color: $hexString',
({ hexString }): void => {
expect(hexString).toBeTruthy();
checkForValidHexColorString(hexString);

const pc: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
expect(pc).toBeTruthy();

if (pc) {
expect(pc.HEX).toBe(hexString);
}
}
);

test.each(
ALL_HEXES
)('$# - valid color: $hexString',
({ hexString }): void => {
expect(hexString).toBeTruthy();
checkForValidHexColorString(hexString);

const pc: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
expect(pc).toBeTruthy();

if (pc) {
checkForValidPaletteColor(pc);
}
}
);

test('all colors are unique', (): void => {
const hexValues: Set<string> = new Set<string>();
const hslValues: Set<string> = new Set<string>();
const rgbValues: Set<string> = new Set<string>();
const names: Set<string> = new Set<string>();

for (const c of ALL_PALETTE_COLORS.values) {
const hex: string = c.HEX.toLowerCase();
expect(hexValues).not.toContain(hex);
hexValues.add(hex);

const hsl: string = makeHSLKey(c.HSL);
expect(hslValues).not.toContain(hsl);
hslValues.add(hsl);

const rgb: string = makeRGBKey(c.RGB);
expect(rgbValues).not.toContain(rgb);
rgbValues.add(rgb);

const name: string = c.NAME.toLowerCase();
expect(names).not.toContain(name);
names.add(name);
}
});

test.each(
ALL_HEXES
)('$# - consistent color: $hexString',
({ hexString }): void => {
const p5: P5Lib = P5Context.p5;
const c: PaletteColor | undefined = ALL_PALETTE_COLORS.get(hexString);
expect(c).toBeTruthy();

if (c) {
const hsl: P5Lib.Color = Color.getHSLColor(c.HSL.H, c.HSL.S, c.HSL.L);
const hslComponents: ColorComponents = p5ColorToColorComponents(hsl);
checkComponents(hslComponents, c);

const hex: P5Lib.Color = p5.color(c.HEX);
const hexComponents: ColorComponents = p5ColorToColorComponents(hex);
checkComponents(hexComponents, c);

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);
}
}
);
});
Loading

0 comments on commit 5010397

Please sign in to comment.