-
Notifications
You must be signed in to change notification settings - Fork 834
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
1 parent
58c384a
commit 46965bd
Showing
5 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
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,31 @@ | ||
import { colorPalette} from './color_palette'; | ||
|
||
describe('colorPalette', () => { | ||
it('should generate the expected palette', () => { | ||
const actualPalette = colorPalette('#FFFF6D', '#1EA593'); | ||
expect(actualPalette).toEqual([ | ||
'#FFFF6D', | ||
'#E6F571', | ||
'#CDEB75', | ||
'#B4E17A', | ||
'#9BD77E', | ||
'#82CD82', | ||
'#69C386', | ||
'#50B98B', | ||
'#37AF8F', | ||
'#1EA593', | ||
]); | ||
}); | ||
|
||
it('should generate a palette with the specified spread', () => { | ||
const actualPalette = colorPalette('#FFFF6D', '#1EA593', 6); | ||
expect(actualPalette).toEqual([ | ||
'#FFFF6D', | ||
'#D2ED75', | ||
'#A5DB7C', | ||
'#78C984', | ||
'#4BB78B', | ||
'#1EA593', | ||
]); | ||
}); | ||
}); |
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,20 @@ | ||
import { hexToRgb } from './hex_to_rgb'; | ||
|
||
describe('hexToRgb ', () => { | ||
|
||
it('should handle 3 digit codes without a hash prefix', () => { | ||
expect(hexToRgb('0a8')).toEqual([0, 170, 136]); | ||
}); | ||
|
||
it('should handle 3 digit codes with a hash prefix', () => { | ||
expect(hexToRgb('#0a8')).toEqual([0, 170, 136]); | ||
}); | ||
|
||
it('should handle 6 digit codes without a hash prefix', () => { | ||
expect(hexToRgb('00aa88')).toEqual([0, 170, 136]); | ||
}); | ||
|
||
it('should handle 6 digit codes with a hash prefix', () => { | ||
expect(hexToRgb('#00aa88')).toEqual([0, 170, 136]); | ||
}); | ||
}); |
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,19 @@ | ||
import { rgbToHex } from './rgb_to_hex'; | ||
|
||
describe('rgbToHex ', () => { | ||
it('should handle rgb() without whitespace', () => { | ||
expect(rgbToHex('rgb(12,34,56)')).toEqual('#0c2238'); | ||
}); | ||
|
||
it('should handle rgb() with whitespace', () => { | ||
expect(rgbToHex('rgb ( 12 , 34 , 56 )')).toEqual('#0c2238'); | ||
}); | ||
|
||
it('should handle rgba() without whitespace', () => { | ||
expect(rgbToHex('rgba(12,34,56,0.4)')).toEqual('#0c2238'); | ||
}); | ||
|
||
it('should handle rgba() with whitespace', () => { | ||
expect(rgbToHex('rgba ( 12 , 34 , 56 , 0.4 )')).toEqual('#0c2238'); | ||
}); | ||
}); |
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,77 @@ | ||
import moment from 'moment'; | ||
import { Random } from './random'; | ||
|
||
describe('Random', () => { | ||
it('should generate booleans', () => { | ||
const trueRandom = new Random(() => 0.51); | ||
const falseRandom = new Random(() => 0.5); | ||
|
||
expect(trueRandom.boolean()).toEqual(true); | ||
expect(falseRandom.boolean()).toEqual(false); | ||
}); | ||
|
||
it('should generate numbers', () => { | ||
const random = new Random(() => 0.42); | ||
|
||
expect(random.number()).toEqual(7.550311166421726e+307); | ||
expect(random.number({ min: 5 })).toEqual(7.550311166421726e+307); | ||
expect(random.number({ max: 10 })).toEqual(4.2); | ||
expect(random.number({ min: 5, max: 10 })).toEqual(7.1); | ||
expect(random.number({ min: -10, max: 10 })).toBeCloseTo(-1.60); | ||
}); | ||
|
||
it('should generate integers', () => { | ||
const random = new Random(() => 0.42); | ||
|
||
expect(random.integer({ min: 0, max: 10 })).toEqual(4); | ||
expect(random.integer({ min: -10, max: 10 })).toEqual(-2); | ||
}); | ||
|
||
it('should select an array value', () => { | ||
const random = new Random(() => 0.42); | ||
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
|
||
expect(random.oneOf(values)).toEqual(5); | ||
}); | ||
|
||
it('should select the specified array value', () => { | ||
const random = new Random(() => 0.42); | ||
const values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
|
||
expect(random.oneToOne(values, 4)).toEqual(5); | ||
}); | ||
|
||
it('should select a set of random size', () => { | ||
const random = new Random(() => 0.42); | ||
const input = [12, 34, 56, 78, 90, 3434, 12313212, 3, 0]; | ||
|
||
expect(random.setOf(input)).toEqual([78, 90, 56, 3434]); | ||
}); | ||
|
||
it('should select a set of random size, with a size constraint', () => { | ||
const random = new Random(() => 0.42); | ||
const input = [12, 34, 56, 78, 90, 3434, 12313212, 3, 0]; | ||
|
||
expect(random.setOf(input, { max: 5 })).toEqual([78, 90]); | ||
}); | ||
|
||
it('should generate a date', () => { | ||
const random = new Random(() => 0.42); | ||
|
||
// The default max value is now, so we must specify a max in order to keep | ||
// the test deterministic. | ||
const actual = random.date({ max: new Date(Date.parse('2018-12-25T12:23:34.123')) }); | ||
|
||
expect(actual).toEqual(new Date(Date.parse('1990-07-29T00:24:17.932Z'))); | ||
}); | ||
|
||
it('should generate a moment', () => { | ||
const random = new Random(() => 0.42); | ||
|
||
// The default max value is now, so we must specify a max in order to keep | ||
// the test deterministic. | ||
const actual = random.moment({ max: moment('2018-12-25T12:23:34.123') }); | ||
|
||
expect(actual.toISOString()).toEqual('1990-07-29T00:24:17.932Z'); | ||
}); | ||
}); |
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