3 var Set = require('../../primitive')
4 , toArray = require('es5-ext/array/to-array')
5 , iteratorSymbol = require('es6-symbol').iterator
9 compare = function (a, b) {
10 if (!a.value) return -1;
11 if (!b.value) return 1;
12 return a.value.localeCompare(b.value);
15 map = function (arr) {
16 return arr.sort().map(function (value) {
17 return { done: false, value: value };
21 module.exports = function (T) {
24 var arr = ['raz', 'dwa', 'trzy', 'cztery', 'pięć'], it, y, z
25 , set = new Set(arr), result = [];
28 a(it[iteratorSymbol](), it, "@@iterator");
32 a.not(y, z, "Recreate result");
34 result.push(it.next());
35 result.push(it.next());
36 result.push(it.next());
37 a.deep(result.sort(compare), map(arr));
38 a.deep(y = it.next(), { done: true, value: undefined }, "End");
39 a.not(y, it.next(), "Recreate result on dead");
41 Emited: function (a) {
42 var arr = ['raz', 'dwa', 'trzy', 'cztery', 'pięć'], it
43 , set = new Set(arr), result = [];
46 result.push(it.next());
47 result.push(it.next());
50 result.push(it.next());
53 result.push(it.next());
54 result.push(it.next());
55 a.deep(result.sort(compare), map(arr));
56 a.deep(it.next(), { done: true, value: undefined }, "End");
58 "Emited #2": function (a) {
59 var arr = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it
60 , set = new Set(arr), result = [];
63 result.push(it.next());
64 result.push(it.next());
67 result.push(it.next());
68 result.push(it.next());
71 result.push(it.next());
72 a.deep(result.sort(compare), map(arr));
73 a.deep(it.next(), { done: true, value: undefined }, "End");
75 "Emited: Clear #1": function (a) {
76 var arr = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it
77 , set = new Set(arr), result = [];
80 result.push(it.next());
81 result.push(it.next());
84 a.deep(result.sort(compare), map(arr));
85 a.deep(it.next(), { done: true, value: undefined }, "End");
87 "Emited: Clear #2": function (a) {
88 var arr = ['raz', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć'], it
89 , set = new Set(arr), result = [];
92 result.push(it.next());
93 result.push(it.next());
97 arr = ['raz', 'dwa', 'foo', 'bar'];
98 result.push(it.next());
99 result.push(it.next());
100 a.deep(result.sort(compare), map(arr));
101 a.deep(it.next(), { done: true, value: undefined }, "End");
103 Kinds: function (a) {
104 var set = new Set(['raz', 'dwa']);
106 a.deep(toArray(new T(set)).sort(), ['raz', 'dwa'].sort(), "Default");
107 a.deep(toArray(new T(set, 'key+value')).sort(),
108 [['raz', 'raz'], ['dwa', 'dwa']].sort(), "Key & Value");
109 a.deep(toArray(new T(set, 'value')).sort(), ['raz', 'dwa'].sort(),