bert_test.js 778 B

1234567891011121314151617181920212223
  1. var bert = require('../priv/protocols/bert.js');
  2. var utf8 = require('../priv/utf8.js');
  3. var fs = require('fs');
  4. utf8_dec = utf8.dec;
  5. utf8_toByteArray = utf8.enc;
  6. print = function (x) { return "["+Array.apply([], x ).join(",")+"]"; }
  7. pass = true;
  8. counter = 0;
  9. fs.readFileSync('bert.data').toString().split('\n').forEach(function (data) {
  10. if (data == "") return;
  11. pass = pass && (data==print(bert.enc(bert.dec(new Uint8Array(JSON.parse(data)).buffer))));
  12. if (pass) { console.log("OK: "+counter); }
  13. counter+=1;
  14. if (!pass) {
  15. console.log(data);
  16. console.log(print(bert.enc(bert.dec(new Uint8Array(JSON.parse(data)).buffer))));
  17. console.log(bert.dec(new Uint8Array(JSON.parse(data)).buffer));
  18. console.log("ERROR: "+data);
  19. }
  20. });