-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,012 additions
and
1,317 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import chroma from '../index.js'; | ||
|
||
describe('Some tests for chroma.color()', () => { | ||
it('hsv interpolation white <-> red', () => { | ||
const result = chroma('white').interpolate('red', 0.5, 'hsv'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('use mix as alias', () => { | ||
const result = chroma('white').mix('red', 0.5, 'hsv'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('alternative mix syntax', () => { | ||
const result = chroma.mix('red', 'blue', 0.25, 'rgb'); | ||
expect(result.hex()).toBe('#bf0040'); | ||
}); | ||
|
||
it('hsl interpolation white <-> red', () => { | ||
const result = chroma('white').interpolate('red', 0.5, 'hsl'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('rgb interpolation white <-> red', () => { | ||
const result = chroma('white').interpolate('red', 0.5, 'rgb'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('hsv interpolation red <-> white', () => { | ||
const result = chroma('red').interpolate('white', 0.5, 'hsv'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('hsl interpolation red <-> white', () => { | ||
const result = chroma('red').interpolate('white', 0.5, 'hsl'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('rgb interpolation red <-> white', () => { | ||
const result = chroma('red').interpolate('white', 0.5, 'rgb'); | ||
expect(result.hex()).toBe('#ff8080'); | ||
}); | ||
|
||
it('interpolation short function', () => { | ||
const interpolateFn = (t) => chroma.interpolate('#ff0000', '#ffffff', t, 'hsv').hex(); | ||
|
||
expect(interpolateFn(0)).toBe('#ff0000'); | ||
expect(interpolateFn(0.5)).toBe('#ff8080'); | ||
expect(interpolateFn(1)).toBe('#ffffff'); | ||
}); | ||
|
||
it('num interpolation white <-> red', () => { | ||
const result = chroma(0xffffff).interpolate(0xff0000, 0.5, 'num'); | ||
expect(result.hex()).toBe('#ff7fff'); | ||
}); | ||
|
||
it('num interpolation red <-> white', () => { | ||
const result = chroma(0xff0000).interpolate(0xffffff, 0.5, 'num'); | ||
expect(result.hex()).toBe('#ff7fff'); | ||
}); | ||
|
||
it('interpolation short function with num provided', () => { | ||
const interpolateFn = (t) => chroma.interpolate(0xff0000, 0xffffff, t, 'num').hex(); | ||
|
||
expect(interpolateFn(0)).toBe('#ff0000'); | ||
expect(interpolateFn(0.5)).toBe('#ff7fff'); | ||
expect(interpolateFn(1)).toBe('#ffffff'); | ||
}); | ||
|
||
it('interpolate in num', () => { | ||
const result = chroma.interpolate(chroma.num(0xffffe0), chroma.num(0x102180), 0.5, 'num'); | ||
expect(result.hex()).toBe('#8810b0'); | ||
expect(result.num()).toBe(8917168); | ||
}); | ||
|
||
it('interpolate in hsv', () => { | ||
const result = chroma.interpolate('white', 'black', 0.5, 'hsv'); | ||
expect(result.hex()).toBe('#808080'); | ||
}); | ||
|
||
it('interpolate in hsl', () => { | ||
const result = chroma.interpolate('lightyellow', 'navy', 0.5, 'hsl'); | ||
expect(result.hex()).toBe('#31ff98'); | ||
}); | ||
|
||
it('interpolate in lrgb', () => { | ||
const result = chroma.interpolate('red', 'blue', 0.5, 'lrgb'); | ||
expect(result.hex()).toBe('#b400b4'); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import chroma from '../index.js'; | ||
|
||
describe('Some tests for chroma.num()', () => { | ||
it('number output', () => { | ||
const color = chroma.hsl(0, 1, 0.5, 0.5); | ||
expect(color.num()).toBe(0xff0000); | ||
}); | ||
|
||
it('num color', () => { | ||
const colors = [chroma(0xff0000), chroma(0x000000), chroma(0xffffff), chroma(0x31ff98), chroma('red')]; | ||
|
||
expect(colors[0].hex()).toBe('#ff0000'); | ||
expect(colors[0].num()).toBe(0xff0000); | ||
|
||
expect(colors[1].hex()).toBe('#000000'); | ||
expect(colors[1].num()).toBe(0x000000); | ||
|
||
expect(colors[2].hex()).toBe('#ffffff'); | ||
expect(colors[2].num()).toBe(0xffffff); | ||
|
||
expect(colors[3].hex()).toBe('#31ff98'); | ||
expect(colors[3].num()).toBe(0x31ff98); | ||
|
||
expect(colors[4].num()).toBe(0xff0000); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import num2rgb from '../src/io/num/num2rgb.js'; | ||
|
||
describe('Testing num2rgb color conversions', () => { | ||
const testCases = { | ||
black: { in: 0x000000, out: [0, 0, 0, 1] }, | ||
white: { in: 0xffffff, out: [255, 255, 255, 1] }, | ||
red: { in: 0xff0000, out: [255, 0, 0, 1] }, | ||
green: { in: 0x00ff00, out: [0, 255, 0, 1] }, | ||
blue: { in: 0x0000ff, out: [0, 0, 255, 1] }, | ||
yellow: { in: 0xffff00, out: [255, 255, 0, 1] }, | ||
cyan: { in: 0x00ffff, out: [0, 255, 255, 1] }, | ||
magenta: { in: 0xff00ff, out: [255, 0, 255, 1] } | ||
}; | ||
|
||
Object.keys(testCases).forEach((key) => { | ||
const { in: input, out: expected } = testCases[key]; | ||
|
||
it(`should convert numeric HEX to RGB for ${key}`, () => { | ||
const result = num2rgb(input); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.