/* Re-renders every golden case with sim/engine.js and compares with test/vectors. Exit code 0 = engine unchanged. Use the same files to test the C port. */ var fs=require('fs'), path=require('path'); var E=require('../sim/engine.js'), R=require('./render.js'); var dir=path.join(__dirname,'vectors'), fail=0, n=0; var prim=JSON.parse(fs.readFileSync(path.join(dir,'primitives.json'),'utf8')); prim.mix.forEach(function(v){ n++; if(R.hex(E.mix(parseInt(v.a,16)>>>0,v.b))!==v.out){ fail++; console.log('mix',v.a,v.b,'differs'); } }); prim.rng.forEach(function(v){ n++; var r=new E.Rng(parseInt(v.seed,16)>>>0); for(var i=0;i<16;i++) if(R.hex(r.next())!==v.next[i]){ fail++; console.log('rng',v.seed,'step',i,'differs'); break; } }); prim.genomes.forEach(function(v){ n++; if(JSON.stringify(E.genome(parseInt(v.seed,16)>>>0))!==JSON.stringify(v.genome)){ fail++; console.log('genome',v.seed,'differs'); } }); fs.readdirSync(dir).filter(function(f){ return /^gen\d/.test(f); }).sort().forEach(function(f){ JSON.parse(fs.readFileSync(path.join(dir,f),'utf8')).cases.forEach(function(c){ n++; var got=R.renderCase({seed:parseInt(c.seed,16)>>>0,salts:c.salts,gen:c.gen,energy:c.energy,drift:c.drift,fillBars:c.fillBars,scale:c.scale,root:c.root},c.bars.length); if(got.checksum===c.checksum) return; fail++; for(var b=0;b