UNPKG

@bigfishtv/cockpit

Version:

57 lines (51 loc) 1.27 kB
import { interpolateGradient } from './colorUtils.js' describe('interpolateGradient', () => { it('should return midpoint gray with range of 3', () => { const gradientMapMarkers = [ { position: 0, alpha: 1, color: [0, 0, 0], }, { position: 1, alpha: 1, color: [255, 255, 255], }, ] const expected = [0, 0, 0, 255, 128, 128, 128, 255, 255, 255, 255, 255] expect(interpolateGradient(gradientMapMarkers, 3)).toEqual(expected) }) it('should resolve colors if markers are not on end points', () => { const gradientMapMarkers = [ { position: 0, alpha: 1, color: [0, 0, 0], }, { position: 0.5, alpha: 1, color: [255, 255, 255], }, ] const expected = [0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255] expect(interpolateGradient(gradientMapMarkers, 3)).toEqual(expected) }) it('should return array with lenth of 4x the range provided', () => { const gradientMapMarkers = [ { position: 0, alpha: 1, color: [0, 0, 0], }, { position: 1, alpha: 1, color: [255, 255, 255], }, ] expect(interpolateGradient(gradientMapMarkers, 12).length).toEqual(4 * 12) expect(interpolateGradient(gradientMapMarkers, 255).length).toEqual(4 * 255) }) })