a zip code crypto-currency system good for red ONLY

index.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. var aFrom = require('es5-ext/array/from')
  3. , getIterator = require('es6-iterator/get')
  4. , toArray = require('es5-ext/array/to-array');
  5. module.exports = function (T, a) {
  6. var arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]
  7. , map = new T(arr), x = 'other', y = 'other2'
  8. , i = 0, result = [];
  9. a(map instanceof T, true, "Map");
  10. a(map.size, 3, "Size");
  11. a(map.get('raz'), 'one', "Get: contained");
  12. a(map.get(x), undefined, "Get: not contained");
  13. a(map.has('raz'), true, "Has: true");
  14. a(map.has(x), false, "Has: false");
  15. a(map.set(x, y), map, "Add: return");
  16. a(map.has(x), true, "Add");
  17. a(map.size, 4, "Add: Size");
  18. map.set('dwa', x);
  19. a(map.get('dwa'), x, "Overwrite: get");
  20. a(map.size, 4, "Overwrite: size");
  21. a(map.delete('else'), false, "Delete: false");
  22. arr.push([x, y]);
  23. arr[1][1] = x;
  24. map.forEach(function () {
  25. result.push(aFrom(arguments));
  26. a(this, y, "ForEach: Context: #" + i);
  27. }, y);
  28. a.deep(result.sort(function (a, b) {
  29. return String([a[1], a[0]]).localeCompare([b[1], b[0]]);
  30. }), arr.sort().map(function (val) { return [val[1], val[0], map]; }),
  31. "ForEach: Arguments");
  32. a.deep(toArray(map.entries()).sort(), [['dwa', x], ['trzy', 'three'],
  33. [x, y], ['raz', 'one']].sort(), "Entries");
  34. a.deep(toArray(map.keys()).sort(), ['dwa', 'trzy', x, 'raz'].sort(),
  35. "Keys");
  36. a.deep(toArray(map.values()).sort(), [x, 'three', y, 'one'].sort(),
  37. "Values");
  38. a.deep(toArray(getIterator(map)).sort(), [['dwa', x], ['trzy', 'three'],
  39. [x, y], ['raz', 'one']].sort(),
  40. "Iterator");
  41. map.clear();
  42. a(map.size, 0, "Clear: size");
  43. a(map.has('trzy'), false, "Clear: has");
  44. a.deep(toArray(map.values()), [], "Clear: Values");
  45. a.h1("Empty initialization");
  46. map = new T();
  47. map.set('foo', 'bar');
  48. a(map.size, 1);
  49. a(map.get('foo'), 'bar');
  50. };