Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.7 KiB

  1. var DLList = require('../lib/DLList')
  2. var assert = require('assert')
  3. var c = require('./context')({datastore: 'local'})
  4. var fakeQueues = function () {
  5. this._length = 0
  6. this.incr = () => this._length++
  7. this.decr = () => this._length--
  8. }
  9. describe('DLList', function () {
  10. it('Should be created and be empty', function () {
  11. var list = new DLList(new fakeQueues())
  12. c.mustEqual(list.getArray().length, 0)
  13. })
  14. it('Should be possible to append once', function () {
  15. var list = new DLList(new fakeQueues())
  16. list.push(5)
  17. var arr = list.getArray()
  18. c.mustEqual(arr.length, 1)
  19. c.mustEqual(list.length, 1)
  20. c.mustEqual(list._queues._length, 1)
  21. c.mustEqual(arr[0], 5)
  22. })
  23. it('Should be possible to append multiple times', function () {
  24. var list = new DLList(new fakeQueues())
  25. list.push(5)
  26. list.push(6)
  27. var arr = list.getArray()
  28. c.mustEqual(arr.length, 2)
  29. c.mustEqual(list.length, 2)
  30. c.mustEqual(list._queues._length, 2)
  31. c.mustEqual(arr[0], 5)
  32. c.mustEqual(arr[1], 6)
  33. list.push(10)
  34. arr = list.getArray()
  35. c.mustEqual(arr.length, 3)
  36. c.mustEqual(list.length, 3)
  37. c.mustEqual(arr[0], 5)
  38. c.mustEqual(arr[1], 6)
  39. c.mustEqual(arr[2], 10)
  40. })
  41. it('Should be possible to shift an empty list', function () {
  42. var list = new DLList(new fakeQueues())
  43. c.mustEqual(list.length, 0)
  44. assert(list.shift() === undefined)
  45. var arr = list.getArray()
  46. c.mustEqual(arr.length, 0)
  47. c.mustEqual(list.length, 0)
  48. assert(list.shift() === undefined)
  49. arr = list.getArray()
  50. c.mustEqual(arr.length, 0)
  51. c.mustEqual(list.length, 0)
  52. c.mustEqual(list._queues._length, 0)
  53. })
  54. it('Should be possible to append then shift once', function () {
  55. var list = new DLList(new fakeQueues())
  56. list.push(5)
  57. c.mustEqual(list.length, 1)
  58. c.mustEqual(list.shift(), 5)
  59. var arr = list.getArray()
  60. c.mustEqual(arr.length, 0)
  61. c.mustEqual(list.length, 0)
  62. c.mustEqual(list._queues._length, 0)
  63. })
  64. it('Should be possible to append then shift multiple times', function () {
  65. var list = new DLList(new fakeQueues())
  66. list.push(5)
  67. c.mustEqual(list.length, 1)
  68. c.mustEqual(list.shift(), 5)
  69. c.mustEqual(list.length, 0)
  70. list.push(6)
  71. c.mustEqual(list.length, 1)
  72. c.mustEqual(list.shift(), 6)
  73. c.mustEqual(list.length, 0)
  74. c.mustEqual(list._queues._length, 0)
  75. })
  76. it('Should pass a full test', function () {
  77. var list = new DLList(new fakeQueues())
  78. list.push(10)
  79. c.mustEqual(list.length, 1)
  80. list.push("11")
  81. c.mustEqual(list.length, 2)
  82. list.push(12)
  83. c.mustEqual(list.length, 3)
  84. c.mustEqual(list._queues._length, 3)
  85. c.mustEqual(list.shift(), 10)
  86. c.mustEqual(list.length, 2)
  87. c.mustEqual(list.shift(),"11")
  88. c.mustEqual(list.length, 1)
  89. list.push(true)
  90. c.mustEqual(list.length, 2)
  91. var arr = list.getArray()
  92. c.mustEqual(arr[0], 12)
  93. c.mustEqual(arr[1], true)
  94. c.mustEqual(arr.length, 2)
  95. c.mustEqual(list._queues._length, 2)
  96. })
  97. it('Should return the first value without shifting', function () {
  98. var list = new DLList(new fakeQueues())
  99. assert(list.first() === undefined)
  100. assert(list.first() === undefined)
  101. list.push(1)
  102. c.mustEqual(list.first(), 1)
  103. c.mustEqual(list.first(), 1)
  104. list.push(2)
  105. c.mustEqual(list.first(), 1)
  106. c.mustEqual(list.first(), 1)
  107. c.mustEqual(list.shift(), 1)
  108. c.mustEqual(list.first(), 2)
  109. c.mustEqual(list.first(), 2)
  110. c.mustEqual(list.shift(), 2)
  111. assert(list.first() === undefined)
  112. assert(list.first() === undefined)
  113. assert(list.first() === undefined)
  114. assert(list.shift() === undefined)
  115. assert(list.first() === undefined)
  116. })
  117. })