1
0

array.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. var iteratorSymbol = require('es6-symbol').iterator;
  3. module.exports = function (T) {
  4. return {
  5. Values: function (a) {
  6. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
  7. it = new T(x);
  8. a(it[iteratorSymbol](), it, "@@iterator");
  9. a.deep(it.next(), { done: false, value: 'raz' }, "#1");
  10. a.deep(it.next(), { done: false, value: 'dwa' }, "#2");
  11. x.splice(1, 0, 'elo');
  12. a.deep(it.next(), { done: false, value: 'dwa' }, "Insert");
  13. a.deep(it.next(), { done: false, value: 'trzy' }, "#3");
  14. a.deep(it.next(), { done: false, value: 'cztery' }, "#4");
  15. x.pop();
  16. a.deep(it.next(), { done: false, value: 'pięć' }, "#5");
  17. a.deep(it.next(), { done: true, value: undefined }, "End");
  18. },
  19. "Keys & Values": function (a) {
  20. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
  21. it = new T(x, 'key+value');
  22. a(it[iteratorSymbol](), it, "@@iterator");
  23. a.deep(it.next(), { done: false, value: [0, 'raz'] }, "#1");
  24. a.deep(it.next(), { done: false, value: [1, 'dwa'] }, "#2");
  25. x.splice(1, 0, 'elo');
  26. a.deep(it.next(), { done: false, value: [2, 'dwa'] }, "Insert");
  27. a.deep(it.next(), { done: false, value: [3, 'trzy'] }, "#3");
  28. a.deep(it.next(), { done: false, value: [4, 'cztery'] }, "#4");
  29. x.pop();
  30. a.deep(it.next(), { done: false, value: [5, 'pięć'] }, "#5");
  31. a.deep(it.next(), { done: true, value: undefined }, "End");
  32. },
  33. Keys: function (a) {
  34. var x = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it;
  35. it = new T(x, 'key');
  36. a(it[iteratorSymbol](), it, "@@iterator");
  37. a.deep(it.next(), { done: false, value: 0 }, "#1");
  38. a.deep(it.next(), { done: false, value: 1 }, "#2");
  39. x.splice(1, 0, 'elo');
  40. a.deep(it.next(), { done: false, value: 2 }, "Insert");
  41. a.deep(it.next(), { done: false, value: 3 }, "#3");
  42. a.deep(it.next(), { done: false, value: 4 }, "#4");
  43. x.pop();
  44. a.deep(it.next(), { done: false, value: 5 }, "#5");
  45. a.deep(it.next(), { done: true, value: undefined }, "End");
  46. },
  47. Sparse: function (a) {
  48. var x = new Array(6), it;
  49. x[2] = 'raz';
  50. x[4] = 'dwa';
  51. it = new T(x);
  52. a.deep(it.next(), { done: false, value: undefined }, "#1");
  53. a.deep(it.next(), { done: false, value: undefined }, "#2");
  54. a.deep(it.next(), { done: false, value: 'raz' }, "#3");
  55. a.deep(it.next(), { done: false, value: undefined }, "#4");
  56. a.deep(it.next(), { done: false, value: 'dwa' }, "#5");
  57. a.deep(it.next(), { done: false, value: undefined }, "#6");
  58. a.deep(it.next(), { done: true, value: undefined }, "End");
  59. }
  60. };
  61. };