Skip to content

Commit

Permalink
chore(test): remove documentation comment and normalize tests,
Browse files Browse the repository at this point in the history
also under rewrite alpha
  • Loading branch information
mineejo committed Nov 25, 2023
1 parent ba2a513 commit ed83810
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions component_effects/alpha_component_test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
// Copyright 2023 mineejo. All rights reserved. MIT license.

import { Rgb } from "../color/rgb.ts";
import { Rgba } from "../color/rgba.ts";
import { assertEquals } from "../dev_deps.ts";
import { alphaComponent } from "./alpha_component.ts";

/**
* ### Example
*
* ```ts
* const firstColor = alphaColor([255, 0, 0], true, 90);
* console.log(firstColor); // [255, 0, 0, 90];
*
* const secondColor = alphaColor([0, 255, 0], true);
* console.log(secondColor); // [0, 255, 0, 100];
*
* const thirdColor = alphaColor(secondColor, false);
* console.log(thirdColor); // [0, 255, 0];
* ```
*/
Deno.test("alpha color function correct", () => {
const redColorComponents: Rgb = [255, 0, 0];
const rgb: Rgb | Rgba = alphaComponent([...redColorComponents, 100], false);
const rgba: Rgb | Rgba = alphaComponent(rgb, true);
Deno.test("alpha color function correct", async (t) => {
await t.step("alpha value added correct", () => {
assertEquals(
alphaComponent([255, 0, 0], true),
[255, 0, 0, 100],
`"alphaComponent([255, 0, 0, 100], true)"`,
);

assertEquals(rgb, redColorComponents, `"rgb"`);
assertEquals(rgba, [...redColorComponents, 100], `"rgba"`);
assertEquals(
alphaComponent(rgb, true, 90),
[...redColorComponents, 90],
`"alphaColor(rgb, true, 90)"`,
);
assertEquals(
alphaComponent([255, 0, 0], true, 90),
[255, 0, 0, 90],
`"alphaComponent([255, 0, 0], true, 90)"`,
);
});

await t.step("alpha value removed correct", () => {
assertEquals(
alphaComponent([255, 0, 0, 100], false),
[255, 0, 0],
`"alphaComponent([255, 0, 0, 100], false)"`,
);

assertEquals(
alphaComponent([255, 0, 0, 100], false, 90),
[255, 0, 0],
`"alphaComponent([255, 0, 0, 100], false)"`,
);
});

await t.step("alpha value overwritten correct", () => {
assertEquals(
alphaComponent([255, 0, 0, 50], true, 90),
[255, 0, 0, 90],
`"alphaComponent([255, 0, 0, 50], true, 90)"`,
);
});
});

0 comments on commit ed83810

Please sign in to comment.