| 1 |
- {"id": "api_test", "name": "API 综合测试", "icon": "🧪", "command": "apitest", "mode": "inline", "description": "测试所有 IJS API 和 JS 库", "inputs": [], "jsCode": "function calculate(inputs, IJS) {\n var errors=[];var pass=0;\n function ok(v,exp){return(''+v).indexOf(exp)>=0;}\n function check(l,fn){try{fn();pass++;IJS.Symja.print('✅ '+l);}catch(e){errors.push(l+':'+e.message);IJS.Symja.print('❌ '+l+' — '+e.message);}}\n IJS.Symja.print('=== IJS.Symja ===');\n check('eval',function(){var r=IJS.Symja.eval('2+2');if(!ok(r,'4'))throw Error('act='+r);});\n check('eval var',function(){IJS.Symja.eval('tv=42');var r=IJS.Symja.eval('tv*2');if(!ok(r,'84'))throw Error('act='+r);});\n check('print',function(){IJS.Symja.print('ok');});\n check('diff',function(){var r=IJS.Symja.differentiate('x^3','x');if(!ok(r,'3*x^2'))throw Error('act='+r);});\n check('int',function(){var r=IJS.Symja.integrate('x^2','x');if(!ok(r,'x^3/3'))throw Error('act='+r);});\n check('solve',function(){var r=IJS.Symja.solve('x^2-4==0','x');if(!ok(r,'2'))throw Error('act='+r);});\n check('simplify',function(){var r=IJS.Symja.simplify('Sin[x]^2+Cos[x]^2');if(!ok(r,'1'))throw Error('act='+r);});\n check('expand',function(){var r=IJS.Symja.expand('(x+1)^2');if(!ok(r,'2*x'))throw Error('act='+r);});\n check('factor',function(){var r=IJS.Symja.factor('x^2-4');if(!r)throw Error('null');});\n check('apart',function(){var r=IJS.Symja.apart('(x+1)/(x^2-1)','x');if(!r)throw Error('null');});\n check('together',function(){var r=IJS.Symja.together('(1/x)+(1/y)');if(!r)throw Error('null');});\n check('trigSimplify',function(){var r=IJS.Symja.trigSimplify('Sin[x]^2+Cos[x]^2');if(!r)throw Error('null');});\n check('sum',function(){var r=IJS.Symja.sum('i^2','i','1','3');if(!ok(r,'14'))throw Error('act='+r);});\n check('product',function(){var r=IJS.Symja.product('i','i','1','4');if(!ok(r,'24'))throw Error('act='+r);});\n check('gcd',function(){var r=IJS.Symja.gcd('12','18');if(!ok(r,'6'))throw Error('act='+r);});\n check('lcm',function(){var r=IJS.Symja.lcm('12','18');if(!ok(r,'36'))throw Error('act='+r);});\n check('factorInteger',function(){var r=IJS.Symja.factorInteger('12');if(!r)throw Error('null');});\n check('isPrime',function(){var r=IJS.Symja.isPrime('17');if(!ok(r,'True'))throw Error('act='+r);});\n check('fibonacci',function(){var r=IJS.Symja.fibonacci(10);if(!ok(r,'55'))throw Error('act='+r);});\n check('binomial',function(){var r=IJS.Symja.binomial('5','2');if(!ok(r,'10'))throw Error('act='+r);});\n check('numeric',function(){var r=IJS.Symja.numeric('Pi',5);if(!ok(r,'3.141'))throw Error('act='+r);});\n check('toTeX',function(){var r=IJS.Symja.toTeX('x^2');if(!r)throw Error('null');});\n check('mat.det',function(){var r=IJS.Symja.matrix.det('{{1,2},{3,4}}');if(!ok(r,'-2'))throw Error('act='+r);});\n check('mat.inv',function(){var r=IJS.Symja.matrix.inverse('{{1,0},{0,2}}');if(!r)throw Error('null');});\n check('mat.tr',function(){var r=IJS.Symja.matrix.transpose('{{1,2},{3,4}}');if(!r)throw Error('null');});\n check('mat.eig',function(){var r=IJS.Symja.matrix.eigenvalues('{{1,0},{0,2}}');if(!r)throw Error('null');});\n check('mat.rank',function(){var r=IJS.Symja.matrix.rank('{{1,0},{0,1}}');if(!ok(r,'2'))throw Error('act='+r);});\n var wv=(typeof _!=='undefined');\n if(wv){\n IJS.Symja.print('=== lodash ===');\n check('_chunk',function(){var r=_.chunk([1,2,3,4],2);if(r.length!==2)throw Error('len='+r.length);});\n check('_shuffle',function(){var r=_.shuffle([1,2,3,4,5]);if(r.length!==5)throw Error('len='+r.length);});\n check('_range',function(){var r=_.range(1,5);if(r.length!==4)throw Error('len='+r.length);});\n check('_max',function(){var r=_.max([3,1,4,1,5,9]);if(r!==9)throw Error('act='+r);});\n check('_sum',function(){var r=_.sum([1,2,3]);if(r!==6)throw Error('act='+r);});\n IJS.Symja.print('=== seedrandom ===');\n check('seedrandom',function(){if(typeof Math.seedrandom!=='function')throw Error('not fn');});\n check('seeded',function(){Math.seedrandom('t');var r1=Math.random();Math.seedrandom('t');var r2=Math.random();if(r1!==r2)throw Error('not det');});\n IJS.Symja.print('=== IJS.canvas ===');check('canv.create',function(){var ctx=IJS.canvas.create(200,200);if(!ctx)throw Error('no ctx');});check('canv.getCtx',function(){var ctx=IJS.canvas.getContext();if(!ctx)throw Error('no ctx');});check('canv.getSize',function(){var s=IJS.canvas.getSize();if(!s.width||!s.height)throw Error('bad size');});check('canv.fill',function(){IJS.canvas.fill('#FFF');});check('canv.clear',function(){IJS.canvas.clear();});IJS.Symja.print('=== IJS.audio ===');check('audio.beep',function(){IJS.audio.beep(440,0.05);});check('audio.playNote',function(){IJS.audio.playNote('C',4,0.05);});check('audio.ctx',function(){var c=IJS.audio._getCtx();if(!c)throw Error('no AudioContext');});IJS.Symja.print('=== IJS.input ===');check('input.touch',function(){IJS.input.onTouchEnd(function(){});});IJS.Symja.print('=== Matter.js ===');check('Matter',function(){if(typeof Matter==='undefined')throw Error('no Matter');});check('Matter.Engine',function(){var e=Matter.Engine.create();if(!e)throw Error('no engine');Matter.Engine.clear(e);});check('Matter.Bodies',function(){var b=Matter.Bodies.circle(100,100,20);if(!b)throw Error('no body');});IJS.ui.close();IJS.Symja.print('=== IJS.io ===');\n check('io.w',function(){var r=IJS.io.write('t.json','{\"h\":42}');if(!r)throw Error('fail');});\n check('io.r',function(){var r=IJS.io.read('t.json');if(!r.includes('h'))throw Error(r);});\n check('io.ls',function(){var r=IJS.io.list();if(!r.includes('t.json'))throw Error(JSON.stringify(r));});\n check('io.rm',function(){IJS.io.delete('t.json');var r=IJS.io.read('t.json');if(r&&r.length>1)throw Error('still');});\n }else{\n IJS.Symja.print('=== Rhino: lodash/seedrandom/io N/A ===');\n }\n var total=26+(wv?9:0);\n IJS.Symja.print('');IJS.Symja.print('=== '+pass+'/'+total+' ===');\n if(errors.length===0)IJS.Symja.print('🎉 ALL PASS');\n else errors.forEach(function(e){IJS.Symja.print(' '+e);});\n return 'Null';\n}"}
|