clone.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. if (typeof Test === 'undefined') require('../tester');
  2. Test('clone', function () {
  3. function t(value) {
  4. Test.isTrue(value);
  5. }
  6. var Big = BigNumber.clone();
  7. var x = new Big(0);
  8. var y = new Big('1');
  9. t(x instanceof Big);
  10. t(y instanceof Big);
  11. t(!(x instanceof BigNumber));
  12. t(!(y instanceof BigNumber));
  13. t(BigNumber.isBigNumber(x));
  14. t(BigNumber.isBigNumber(y));
  15. t(Big.isBigNumber(x));
  16. t(Big.isBigNumber(y));
  17. var z = new BigNumber(x);
  18. t(z instanceof BigNumber);
  19. t(!(z instanceof Big));
  20. t(BigNumber.isBigNumber(z));
  21. t(Big.isBigNumber(z));
  22. t(x.eq(z));
  23. t(!x.eq(y));
  24. t(!z.eq(y));
  25. AnotherBig = Big.clone();
  26. xx = new AnotherBig(0);
  27. yy = new AnotherBig('1');
  28. t(xx instanceof AnotherBig);
  29. t(!(xx instanceof BigNumber));
  30. t(!(yy instanceof BigNumber));
  31. t(!(xx instanceof Big));
  32. t(!(yy instanceof Big));
  33. t(Big.isBigNumber(xx));
  34. t(Big.isBigNumber(yy));
  35. t(AnotherBig.isBigNumber(xx));
  36. t(AnotherBig.isBigNumber(yy));
  37. zz = new Big(z);
  38. t(zz instanceof Big);
  39. t(!(zz instanceof AnotherBig));
  40. t(!(zz instanceof BigNumber));
  41. t(zz.eq(x));
  42. t(zz.eq(xx));
  43. t(zz.eq(z));
  44. t(!zz.eq(y));
  45. t(!zz.eq(yy));
  46. });