UI for Zipcoin Blue

compare.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
  2. var B = require('../').Buffer
  3. var test = require('tape')
  4. test('buffer.compare', function (t) {
  5. var b = new B(1).fill('a')
  6. var c = new B(1).fill('c')
  7. var d = new B(2).fill('aa')
  8. t.equal(b.compare(c), -1)
  9. t.equal(c.compare(d), 1)
  10. t.equal(d.compare(b), 1)
  11. t.equal(b.compare(d), -1)
  12. // static method
  13. t.equal(B.compare(b, c), -1)
  14. t.equal(B.compare(c, d), 1)
  15. t.equal(B.compare(d, b), 1)
  16. t.equal(B.compare(b, d), -1)
  17. t.end()
  18. })
  19. test('buffer.compare argument validation', function (t) {
  20. t.throws(function () {
  21. var b = new B(1)
  22. B.compare(b, 'abc')
  23. })
  24. t.throws(function () {
  25. var b = new B(1)
  26. B.compare('abc', b)
  27. })
  28. t.throws(function () {
  29. var b = new B(1)
  30. b.compare('abc')
  31. })
  32. t.end()
  33. })
  34. test('buffer.equals', function (t) {
  35. var b = new B(5).fill('abcdf')
  36. var c = new B(5).fill('abcdf')
  37. var d = new B(5).fill('abcde')
  38. var e = new B(6).fill('abcdef')
  39. t.ok(b.equals(c))
  40. t.ok(!c.equals(d))
  41. t.ok(!d.equals(e))
  42. t.end()
  43. })
  44. test('buffer.equals argument validation', function (t) {
  45. t.throws(function () {
  46. var b = new B(1)
  47. b.equals('abc')
  48. })
  49. t.end()
  50. })