@@ -1337,5 +1337,67 @@ suite('p5.Shader', function() {
13371337 assert . isNumber ( pixelColor [ 2 ] ) ;
13381338 } ) ;
13391339 } ) ;
1340+
1341+ suite ( 'noise()' , ( ) => {
1342+ for ( let i = 1 ; i <= 3 ; i ++ ) {
1343+ test ( `works with ${ i } D vectors` , ( ) => {
1344+ expect ( ( ) => {
1345+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1346+ const input = new Array ( i ) . fill ( 10 ) ;
1347+ const testShader = myp5 . baseFilterShader ( ) . modify ( ( ) => {
1348+ myp5 . getColor ( ( ) => {
1349+ return [ myp5 . noise ( input ) , 0 , 0 , 1 ] ;
1350+ } ) ;
1351+ } , { myp5, input } ) ;
1352+ myp5 . shader ( testShader ) ;
1353+ myp5 . plane ( 10 , 10 ) ;
1354+ } ) . not . toThrowError ( ) ;
1355+ } ) ;
1356+
1357+ test ( `works with ${ i } D positional arguments` , ( ) => {
1358+ expect ( ( ) => {
1359+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1360+ const input = new Array ( i ) . fill ( 10 ) ;
1361+ const testShader = myp5 . baseFilterShader ( ) . modify ( ( ) => {
1362+ myp5 . getColor ( ( ) => {
1363+ return [ myp5 . noise ( ...input ) , 0 , 0 , 1 ] ;
1364+ } ) ;
1365+ } , { myp5, input } ) ;
1366+ myp5 . shader ( testShader ) ;
1367+ myp5 . plane ( 10 , 10 ) ;
1368+ } ) . not . toThrowError ( ) ;
1369+ } ) ;
1370+ }
1371+
1372+ for ( const i of [ 0 , 4 ] ) {
1373+ test ( `Does not work in ${ i } D` , ( ) => {
1374+ expect ( ( ) => {
1375+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1376+ const input = new Array ( i ) . fill ( 10 ) ;
1377+ const testShader = myp5 . baseFilterShader ( ) . modify ( ( ) => {
1378+ myp5 . getColor ( ( ) => {
1379+ return [ myp5 . noise ( input ) , 0 , 0 , 1 ] ;
1380+ } ) ;
1381+ } , { myp5, input } ) ;
1382+ myp5 . shader ( testShader ) ;
1383+ myp5 . plane ( 10 , 10 ) ;
1384+ } ) . toThrowError ( ) ;
1385+ } ) ;
1386+
1387+ test ( `Does not work in ${ i } D with positional arguments` , ( ) => {
1388+ expect ( ( ) => {
1389+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1390+ const input = new Array ( i ) . fill ( 10 ) ;
1391+ const testShader = myp5 . baseFilterShader ( ) . modify ( ( ) => {
1392+ myp5 . getColor ( ( ) => {
1393+ return [ myp5 . noise ( ...input ) , 0 , 0 , 1 ] ;
1394+ } ) ;
1395+ } , { myp5, input } ) ;
1396+ myp5 . shader ( testShader ) ;
1397+ myp5 . plane ( 10 , 10 ) ;
1398+ } ) . toThrowError ( ) ;
1399+ } ) ;
1400+ }
1401+ } ) ;
13401402 } ) ;
13411403} ) ;
0 commit comments