|
| 1 | +constpath=require('path'); |
| 2 | +const{ Commander}=require('algorithm-visualizer'); |
| 3 | +const{ rootDir}=require('../constants'); |
| 4 | +const{ signale}=require('../utils'); |
| 5 | +const{MAX_STEPS}=require('../constants'); |
| 6 | + |
| 7 | +module.exports=(category,algorithm,file,content)=>{ |
| 8 | +consterrors=[]; |
| 9 | +consterror=message=>errors.push(message); |
| 10 | +constwarns=[]; |
| 11 | +constwarn=message=>warns.push(message); |
| 12 | + |
| 13 | +try{ |
| 14 | +Commander.init(); |
| 15 | +require(path.resolve(rootDir,category,algorithm,file)); |
| 16 | +}catch(e){ |
| 17 | +error(e); |
| 18 | +} |
| 19 | +conststeps=Commander.commands.filter(command=>command.method==='delay').length; |
| 20 | +if(steps>MAX_STEPS){ |
| 21 | +warn('Too many steps.'); |
| 22 | +} |
| 23 | +if(!/\/\/importvisualizationlibraries{/.test(content)){ |
| 24 | +error('Missing the code folding for importing visualization libraries.'); |
| 25 | +} |
| 26 | +if(!/\/\/definetracervariables{/.test(content)){ |
| 27 | +error('Missing the code folding for defining tracer variables.'); |
| 28 | +} |
| 29 | +if(!/\/\/visualize{/.test(content)){ |
| 30 | +error('Missing the code folding for visualizing.'); |
| 31 | +} |
| 32 | + |
| 33 | +if(errors.length||warns.length){ |
| 34 | +signale.log(`${category}/${algorithm}/${file}`); |
| 35 | +warns.forEach(error=>signale.warn(error)); |
| 36 | +errors.forEach(error=>signale.error(error)); |
| 37 | +signale.log(); |
| 38 | +} |
| 39 | +returnerrors.length===0; |
| 40 | +}; |