11import blobs , { BlobOptions } from ".." ;
22
3+ const genMinimalOptions = ( ) : BlobOptions => ( {
4+ size : 1000 * Math . random ( ) ,
5+ complexity : 1 - Math . random ( ) ,
6+ contrast : 1 - Math . random ( ) ,
7+ color : "#fff" ,
8+ } ) ;
9+
310describe ( "blobs" , ( ) => {
411 it ( "should return a different result when seed is not provided" , ( ) => {
5- const options : BlobOptions = { size : 100 , complexity : 1 , contrast : 1 , color : "red" } ;
12+ const options = genMinimalOptions ( ) ;
613
714 const a = blobs ( options ) ;
815 const b = blobs ( options ) ;
@@ -11,12 +18,48 @@ describe("blobs", () => {
1118 } ) ;
1219
1320 it ( "should return the same result when the seed is provided" , ( ) => {
14- const options : BlobOptions = { size : 200 , complexity : 0.5 , contrast : 0.5 , color : "blue" } ;
15- options . seed = "abcde" ;
21+ const options = genMinimalOptions ( ) ;
1622
23+ options . seed = "abcde" ;
1724 const a = blobs ( options ) ;
1825 const b = blobs ( options ) ;
1926
2027 expect ( a ) . toEqual ( b ) ;
2128 } ) ;
29+
30+ it ( "should require a size be provided" , ( ) => {
31+ const options = genMinimalOptions ( ) ;
32+
33+ delete options . size ;
34+ expect ( ( ) => blobs ( options ) ) . toThrow ( "size" ) ;
35+ } ) ;
36+
37+ it ( "should reject out of range complexity values" , ( ) => {
38+ const options = genMinimalOptions ( ) ;
39+
40+ options . complexity = 1234 ;
41+ expect ( ( ) => blobs ( options ) ) . toThrow ( "complexity" ) ;
42+
43+ options . complexity = 0 ;
44+ expect ( ( ) => blobs ( options ) ) . toThrow ( "complexity" ) ;
45+ } ) ;
46+
47+ it ( "should reject out of range contrast values" , ( ) => {
48+ const options = genMinimalOptions ( ) ;
49+
50+ options . contrast = 999 ;
51+ expect ( ( ) => blobs ( options ) ) . toThrow ( "contrast" ) ;
52+
53+ options . contrast = - 1 ;
54+ expect ( ( ) => blobs ( options ) ) . toThrow ( "contrast" ) ;
55+ } ) ;
56+
57+ it ( "should reject options without stroke or color" , ( ) => {
58+ const options = genMinimalOptions ( ) ;
59+
60+ delete options . stroke ;
61+ delete options . color ;
62+ expect ( ( ) => blobs ( options ) ) . toThrow ( "stroke" ) ;
63+ expect ( ( ) => blobs ( options ) ) . toThrow ( "color" ) ;
64+ } ) ;
2265} ) ;
0 commit comments