demo.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Created by Tony on 2017/3/16.
  3. */
  4. var test = require('tape');
  5. test('basic arithmetic', function (t) {
  6. t.equal(2 + 3, 5);
  7. t.equal(7 * 8 + 9, 65);
  8. t.equal(/^-?\d+$/.test("10"), true);
  9. //t.equal(isNaN(10.1), true);
  10. t.equal(Math.round(10.4999), 10);
  11. t.end();
  12. });
  13. test('', function(t){
  14. var dt = new Date();
  15. p_fillZero = function(val){
  16. var rst = val;
  17. if (val < 10) {
  18. rst = '0' + val;
  19. }
  20. return rst;
  21. };
  22. console.log(dt.getFullYear() + '-' + p_fillZero(dt.getMonth()) + '-' + p_fillZero(dt.getDate()) + 'T' +
  23. p_fillZero(dt.getHours()) + ':' + p_fillZero(dt.getMinutes()) + ':' + p_fillZero(dt.getSeconds()) + 'Z');
  24. t.pass('just pass');
  25. t.end();
  26. })
  27. test('default sorting...', function(t){
  28. var arrSimple=new Array(1,8,7,6,10,11);
  29. arrSimple.sort(function(i1, i2){
  30. rst = 0;
  31. if (i1 > i2) {rst = 1} else
  32. if (i1 < i2) rst = -1;
  33. return rst;
  34. });
  35. console.log(arrSimple);
  36. t.pass('just pass');
  37. t.end();
  38. })