a zip code crypto-currency system good for red ONLY

primitive-iterator.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use strict';
  2. var iteratorSymbol = require('es6-symbol').iterator
  3. , toArray = require('es5-ext/array/to-array')
  4. , Map = require('../../primitive')
  5. , compare, mapToResults;
  6. compare = function (a, b) {
  7. if (!a.value) return -1;
  8. if (!b.value) return 1;
  9. return a.value[0].localeCompare(b.value[0]);
  10. };
  11. mapToResults = function (arr) {
  12. return arr.sort().map(function (value) {
  13. return { done: false, value: value };
  14. });
  15. };
  16. module.exports = function (T) {
  17. return {
  18. "": function (a) {
  19. var arr, it, y, z, map, result = [];
  20. arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
  21. ['cztery', 'four'], ['pięć', 'five']];
  22. map = new Map(arr);
  23. it = new T(map);
  24. a(it[iteratorSymbol](), it, "@@iterator");
  25. y = it.next();
  26. result.push(y);
  27. z = it.next();
  28. a.not(y, z, "Recreate result");
  29. result.push(z);
  30. result.push(it.next());
  31. result.push(it.next());
  32. result.push(it.next());
  33. a.deep(result.sort(compare), mapToResults(arr));
  34. a.deep(y = it.next(), { done: true, value: undefined }, "End");
  35. a.not(y, it.next(), "Recreate result on dead");
  36. },
  37. Emited: function (a) {
  38. var arr, it, map, result = [];
  39. arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
  40. ['cztery', 'four'], ['pięć', 'five']];
  41. map = new Map(arr);
  42. it = new T(map);
  43. result.push(it.next());
  44. result.push(it.next());
  45. map.set('sześć', 'six');
  46. arr.push(['sześć', 'six']);
  47. result.push(it.next());
  48. map.delete('pięć');
  49. arr.splice(4, 1);
  50. result.push(it.next());
  51. result.push(it.next());
  52. a.deep(result.sort(compare), mapToResults(arr));
  53. a.deep(it.next(), { done: true, value: undefined }, "End");
  54. },
  55. "Emited #2": function (a) {
  56. var arr, it, map, result = [];
  57. arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
  58. ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
  59. map = new Map(arr);
  60. it = new T(map);
  61. result.push(it.next());
  62. result.push(it.next());
  63. map.set('siedem', 'seven');
  64. map.delete('siedem');
  65. result.push(it.next());
  66. result.push(it.next());
  67. map.delete('pięć');
  68. arr.splice(4, 1);
  69. result.push(it.next());
  70. a.deep(result.sort(compare), mapToResults(arr));
  71. a.deep(it.next(), { done: true, value: undefined }, "End");
  72. },
  73. "Emited: Clear #1": function (a) {
  74. var arr, it, map, result = [];
  75. arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
  76. ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
  77. map = new Map(arr);
  78. it = new T(map);
  79. result.push(it.next());
  80. result.push(it.next());
  81. arr = [['raz', 'one'], ['dwa', 'two']];
  82. map.clear();
  83. a.deep(result.sort(compare), mapToResults(arr));
  84. a.deep(it.next(), { done: true, value: undefined }, "End");
  85. },
  86. "Emited: Clear #2": function (a) {
  87. var arr, it, map, result = [];
  88. arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
  89. ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
  90. map = new Map(arr);
  91. it = new T(map);
  92. result.push(it.next());
  93. result.push(it.next());
  94. map.clear();
  95. map.set('foo', 'bru');
  96. map.set('bar', 'far');
  97. arr = [['raz', 'one'], ['dwa', 'two'], ['foo', 'bru'], ['bar', 'far']];
  98. result.push(it.next());
  99. result.push(it.next());
  100. a.deep(result.sort(compare), mapToResults(arr));
  101. a.deep(it.next(), { done: true, value: undefined }, "End");
  102. },
  103. Kinds: function (a) {
  104. var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr);
  105. a.deep(toArray(new T(map)).sort(), arr.sort(), "Default");
  106. a.deep(toArray(new T(map, 'key+value')).sort(), arr.sort(),
  107. "Key + Value");
  108. a.deep(toArray(new T(map, 'value')).sort(), ['one', 'two'].sort(),
  109. "Value");
  110. a.deep(toArray(new T(map, 'key')).sort(), ['raz', 'dwa'].sort(),
  111. "Key");
  112. }
  113. };
  114. };