diff --git a/README.md b/README.md
index 115eece8..5a20024a 100644
--- a/README.md
+++ b/README.md
@@ -45,10 +45,6 @@ In a vanilla environment, a `d3_array` global is exported. [Try d3-array in your
* [Statistics](#statistics)
* [Search](#search)
* [Transformations](#transformations)
-* [Objects](#objects)
-* [Maps](#maps)
-* [Sets](#sets)
-* [Nests](#nests)
* [Histograms](#histograms)
* [Histogram Thresholds](#histogram-thresholds)
@@ -278,248 +274,6 @@ Returns an array of arrays, where the *i*th array contains the *i*th element fro
d3_array.zip([1, 2], [3, 4]); // returns [[1, 3], [2, 4]]
```
-### Objects
-
-A common data type in JavaScript is the *associative array*, or more simply the *object*, which has a set of named properties. The standard mechanism for iterating over the keys (or property names) in an associative array is the [for…in loop](https://developer.mozilla.org/en/JavaScript/Reference/Statements/for...in). However, note that the iteration order is undefined. D3 provides several methods for converting associative arrays to standard arrays with numeric indexes.
-
-A word of caution: it is tempting to use plain objects as maps, but this causes [unexpected behavior](http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/) when built-in property names are used as keys, such as `object["__proto__"] = 42` and `"hasOwnProperty" in object`. If you cannot guarantee that map keys and set values will be safe, use [maps](#maps) and [sets](#sets) (or their ES6 equivalents) instead of plain objects.
-
-# d3_array.keys(object)
-
-Returns an array containing the property names of the specified object (an associative array). The order of the returned array is undefined.
-
-# d3_array.values(object)
-
-Returns an array containing the property values of the specified object (an associative array). The order of the returned array is undefined.
-
-# d3_array.entries(object)
-
-Returns an array containing the property keys and values of the specified object (an associative array). Each entry is an object with a key and value attribute, such as `{key: "foo", value: 42}`. The order of the returned array is undefined.
-
-```js
-d3_array.entries({foo: 42, bar: true}); // [{key: "foo", value: 42}, {key: "bar", value: true}]
-```
-
-### Maps
-
-Like [ES6 Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), but with a few differences:
-
-* Keys are coerced to strings.
-* [map.each](#map_each), not [map.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach). (Also, no *thisArg*.)
-* [map.remove](#map_remove), not [map.delete](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).
-* [map.entries](#map_entries) returns an array of {key, value} objects, not an iterator of [key, value].
-* [map.size](#map_size) is a method, not a [property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size); also, there’s [map.empty](#map_empty).
-
-# d3_array.map([object[, key]])
-
-Constructs a new map. If *object* is specified, copies all enumerable properties from the specified object into this map. The specified object may also be an array or another map. An optional *key* function may be specified to compute the key for each value in the array. For example:
-
-```js
-var map = d3_array.map([{name: "foo"}, {name: "bar"}], function(d) { return d.name; });
-map.get("foo"); // {"name": "foo"}
-map.get("bar"); // {"name": "bar"}
-map.get("baz"); // undefined
-```
-
-See also [nests](#nests).
-
-# map.has(key)
-
-Returns true if and only if this map has an entry for the specified *key* string. Note: the value may be `null` or `undefined`.
-
-# map.get(key)
-
-Returns the value for the specified *key* string. If the map does not have an entry for the specified *key*, returns `undefined`.
-
-# map.set(key, value)
-
-Sets the *value* for the specified *key* string. If the map previously had an entry for the same *key* string, the old entry is replaced with the new value. Returns the map, allowing chaining. For example:
-
-```js
-var map = d3_array.map()
- .set("foo", 1)
- .set("bar", 2)
- .set("baz", 3);
-
-map.get("foo"); // 1
-```
-
-# map.remove(key)
-
-If the map has an entry for the specified *key* string, removes the entry and returns true. Otherwise, this method does nothing and returns false.
-
-# map.clear()
-
-Removes all entries from this map.
-
-# map.keys()
-
-Returns an array of string keys for every entry in this map. The order of the returned keys is arbitrary.
-
-# map.values()
-
-Returns an array of values for every entry in this map. The order of the returned values is arbitrary.
-
-# map.entries()
-
-Returns an array of key-value objects for each entry in this map. The order of the returned entries is arbitrary. Each entry’s key is a string, but the value has arbitrary type.
-
-# map.each(function)
-
-Calls the specified *function* for each entry in this map, passing the entry’s value and key as arguments, followed by the map itself. Returns undefined. The iteration order is arbitrary.
-
-# map.empty()
-
-Returns true if and only if this map has zero entries.
-
-# map.size()
-
-Returns the number of entries in this map.
-
-### Sets
-
-Like [ES6 Sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set), but with a few differences:
-
-* Values are coerced to strings.
-* [set.each](#set_each), not [set.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach). (Also, no *thisArg*.)
-* [set.remove](#set_remove), not [set.delete](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete).
-* [set.size](#set_size) is a method, not a [property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size); also, there’s [set.empty](#set_empty).
-
-# d3_array.set([array[, accessor]])
-
-Constructs a new set. If *array* is specified, adds the given *array* of string values to the returned set. The specified array may also be another set. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before constructing the set.
-
-# set.has(value)
-
-Returns true if and only if this set has an entry for the specified *value* string.
-
-# set.add(value)
-
-Adds the specified *value* string to this set. Returns the set, allowing chaining. For example:
-
-```js
-var set = d3_array.set()
- .add("foo")
- .add("bar")
- .add("baz");
-
-set.has("foo"); // true
-```
-
-# set.remove(value)
-
-If the set contains the specified *value* string, removes it and returns true. Otherwise, this method does nothing and returns false.
-
-# set.clear()
-
-Removes all values from this set.
-
-# set.values()
-
-Returns an array of the string values in this set. The order of the returned values is arbitrary. Can be used as a convenient way of computing the unique values for a set of strings. For example:
-
-```js
-d3_array.set(["foo", "bar", "foo", "baz"]).values(); // "foo", "bar", "baz"
-```
-
-# set.each(function)
-
-Calls the specified *function* for each value in this set, passing the value as the first two arguments (for symmetry with [*map*.each](#map_each)), followed by the set itself. Returns undefined. The iteration order is arbitrary.
-
-# set.empty()
-
-Returns true if and only if this set has zero values.
-
-# set.size()
-
-Returns the number of values in this set.
-
-### Nests
-
-Nesting allows elements in an array to be grouped into a hierarchical tree structure; think of it like the GROUP BY operator in SQL, except you can have multiple levels of grouping, and the resulting output is a tree rather than a flat table. The levels in the tree are specified by key functions. The leaf nodes of the tree can be sorted by value, while the internal nodes can be sorted by key. An optional rollup function will collapse the elements in each leaf node using a summary function. The nest operator (the object returned by [nest](#nest)) is reusable, and does not retain any references to the data that is nested.
-
-For example, consider the following tabular data structure of Barley yields, from various sites in Minnesota during 1931-2:
-
-```js
-var yields = [
- {yield: 27.00, variety: "Manchuria", year: 1931, site: "University Farm"},
- {yield: 48.87, variety: "Manchuria", year: 1931, site: "Waseca"},
- {yield: 27.43, variety: "Manchuria", year: 1931, site: "Morris"},
- ...
-];
-```
-
-To facilitate visualization, it may be useful to nest the elements first by year, and then by variety, as follows:
-
-```js
-var entries = d3_array.nest()
- .key(function(d) { return d.year; })
- .key(function(d) { return d.variety; })
- .entries(yields);
-```
-
-This returns a nested array. Each element of the outer array is a key-values pair, listing the values for each distinct key:
-
-```js
-[{key: "1931", values: [
- {key: "Manchuria", values: [
- {yield: 27.00, variety: "Manchuria", year: 1931, site: "University Farm"},
- {yield: 48.87, variety: "Manchuria", year: 1931, site: "Waseca"},
- {yield: 27.43, variety: "Manchuria", year: 1931, site: "Morris"}, ...]},
- {key: "Glabron", values: [
- {yield: 43.07, variety: "Glabron", year: 1931, site: "University Farm"},
- {yield: 55.20, variety: "Glabron", year: 1931, site: "Waseca"}, ...]}, ...]},
- {key: "1932", values: ...}]
-```
-
-The nested form allows easy iteration and generation of hierarchical structures in SVG or HTML.
-
-For a longer introduction to nesting, see:
-
-* Phoebe Bright’s [D3 Nest Tutorial and examples](http://bl.ocks.org/phoebebright/raw/3176159/)
-* Shan Carter’s [Mister Nester](http://bl.ocks.org/shancarter/raw/4748131/)
-
-# d3_array.nest()
-
-Creates a new nest operator. The set of keys is initially empty. If the [map](#nest_map) or [entries](#nest_entries) operator is invoked before any key functions are registered, the nest operator simply returns the input array.
-
-# nest.key(function)
-
-Registers a new key *function*. The key function will be invoked for each element in the input array, and must return a string identifier that is used to assign the element to its group. Most often, the function is implemented as a simple accessor, such as the year and variety accessors in the example above. The function is _not_ passed the input array index. Each time a key is registered, it is pushed onto the end of an internal keys array, and the resulting map or entries will have an additional hierarchy level. There is not currently a facility to remove or query the registered keys. The most-recently registered key is referred to as the current key in subsequent methods.
-
-# nest.sortKeys(comparator)
-
-Sorts key values for the current key using the specified *comparator*, such as [descending](#descending). If no comparator is specified for the current key, the order in which keys will be returned is undefined. Note that this only affects the result of the entries operator; the order of keys returned by the map operator is always undefined, regardless of comparator.
-
-```js
-var entries = d3_array.nest()
- .key(function(d) { return d.year; })
- .sortKeys(ascending)
- .entries(yields);
-```
-
-# nest.sortValues(comparator)
-
-Sorts leaf elements using the specified *comparator*, such as [descending](#descending). This is roughly equivalent to sorting the input array before applying the nest operator; however it is typically more efficient as the size of each group is smaller. If no value comparator is specified, elements will be returned in the order they appeared in the input array. This applies to both the map and entries operators.
-
-# nest.rollup(function)
-
-Specifies a rollup *function* to be applied on each group of leaf elements. The return value of the rollup function will replace the array of leaf values in either the associative array returned by the map operator, or the values attribute of each entry returned by the entries operator.
-
-# nest.map(array)
-
-Applies the nest operator to the specified *array*, returning a nested [map](#map). Each entry in the returned map corresponds to a distinct key value returned by the first key function. The entry value depends on the number of registered key functions: if there is an additional key, the value is another map; otherwise, the value is the array of elements filtered from the input *array* that have the given key value.
-
-# nest.object(array)
-
-Applies the nest operator to the specified *array*, returning a nested object. Each entry in the returned associative array corresponds to a distinct key value returned by the first key function. The entry value depends on the number of registered key functions: if there is an additional key, the value is another associative array; otherwise, the value is the array of elements filtered from the input *array* that have the given key value.
-
-Note: this method is unsafe if any of the keys conflict with built-in JavaScript properties, such as `__proto__`. If you cannot guarantee that the keys will be safe, you should use [nest.map](#nest_map) instead.
-
-# nest.entries(array)
-
-Applies the nest operator to the specified *array*, returning an array of key-values entries. Conceptually, this is similar to applying [entries](#entries) to the associative array returned by [map](#nest_map), but it applies to every level of the hierarchy rather than just the first (outermost) level. Each entry in the returned array corresponds to a distinct key value returned by the first key function. The entry value depends on the number of registered key functions: if there is an additional key, the value is another nested array of entries; otherwise, the value is the array of elements filtered from the input *array* that have the given key value.
-
### Histograms
[](http://bl.ocks.org/mbostock/3048450)
diff --git a/index.js b/index.js
index fd4b0bf8..321fd0f6 100644
--- a/index.js
+++ b/index.js
@@ -3,30 +3,24 @@ export {default as ascending} from "./src/ascending";
export {default as bisector} from "./src/bisector";
export {default as descending} from "./src/descending";
export {default as deviation} from "./src/deviation";
-export {default as entries} from "./src/entries";
export {default as extent} from "./src/extent";
export {default as histogram} from "./src/histogram";
export {default as thresholdFreedmanDiaconis} from "./src/threshold/freedmanDiaconis";
export {default as thresholdScott} from "./src/threshold/scott";
export {default as thresholdSturges} from "./src/threshold/sturges";
-export {default as keys} from "./src/keys";
-export {default as map} from "./src/map";
export {default as max} from "./src/max";
export {default as mean} from "./src/mean";
export {default as median} from "./src/median";
export {default as merge} from "./src/merge";
export {default as min} from "./src/min";
-export {default as nest} from "./src/nest";
export {default as pairs} from "./src/pairs";
export {default as permute} from "./src/permute";
export {default as quantile} from "./src/quantile";
export {default as range} from "./src/range";
export {default as scan} from "./src/scan";
-export {default as set} from "./src/set";
export {default as shuffle} from "./src/shuffle";
export {default as sum} from "./src/sum";
export {default as ticks, tickStep} from "./src/ticks";
export {default as transpose} from "./src/transpose";
-export {default as values} from "./src/values";
export {default as variance} from "./src/variance";
export {default as zip} from "./src/zip";
diff --git a/package.json b/package.json
index 7d2d475f..2950c21e 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,9 @@
{
"name": "d3-array",
- "version": "0.6.2",
+ "version": "0.7.0",
"description": "Array manipulation, ordering, searching, summarizing, etc.",
"keywords": [
"d3",
- "nest",
"histogram",
"bisect",
"shuffle",
diff --git a/src/entries.js b/src/entries.js
deleted file mode 100644
index 154d93c9..00000000
--- a/src/entries.js
+++ /dev/null
@@ -1,5 +0,0 @@
-export default function(map) {
- var entries = [];
- for (var key in map) entries.push({key: key, value: map[key]});
- return entries;
-};
diff --git a/src/keys.js b/src/keys.js
deleted file mode 100644
index 4cc5b2ce..00000000
--- a/src/keys.js
+++ /dev/null
@@ -1,5 +0,0 @@
-export default function(map) {
- var keys = [];
- for (var key in map) keys.push(key);
- return keys;
-};
diff --git a/src/map.js b/src/map.js
deleted file mode 100644
index 542d8626..00000000
--- a/src/map.js
+++ /dev/null
@@ -1,74 +0,0 @@
-export var prefix = "$";
-
-function Map() {}
-
-Map.prototype = map.prototype = {
- has: function(key) {
- return (prefix + key) in this;
- },
- get: function(key) {
- return this[prefix + key];
- },
- set: function(key, value) {
- this[prefix + key] = value;
- return this;
- },
- remove: function(key) {
- var property = prefix + key;
- return property in this && delete this[property];
- },
- clear: function() {
- for (var property in this) if (property[0] === prefix) delete this[property];
- },
- keys: function() {
- var keys = [];
- for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
- return keys;
- },
- values: function() {
- var values = [];
- for (var property in this) if (property[0] === prefix) values.push(this[property]);
- return values;
- },
- entries: function() {
- var entries = [];
- for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
- return entries;
- },
- size: function() {
- var size = 0;
- for (var property in this) if (property[0] === prefix) ++size;
- return size;
- },
- empty: function() {
- for (var property in this) if (property[0] === prefix) return false;
- return true;
- },
- each: function(f) {
- for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
- }
-};
-
-function map(object, f) {
- var map = new Map;
-
- // Copy constructor.
- if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
-
- // Index array by numeric index or specified key function.
- else if (Array.isArray(object)) {
- var i = -1,
- n = object.length,
- o;
-
- if (arguments.length === 1) while (++i < n) map.set(i, object[i]);
- else while (++i < n) map.set(f(o = object[i], i, object), o);
- }
-
- // Convert object to map.
- else if (object) for (var key in object) map.set(key, object[key]);
-
- return map;
-}
-
-export default map;
diff --git a/src/nest.js b/src/nest.js
deleted file mode 100644
index 840e7a8d..00000000
--- a/src/nest.js
+++ /dev/null
@@ -1,80 +0,0 @@
-import map from "./map";
-
-export default function() {
- var keys = [],
- sortKeys = [],
- sortValues,
- rollup,
- nest;
-
- function apply(array, depth, createResult, setResult) {
- if (depth >= keys.length) return rollup
- ? rollup(array) : (sortValues
- ? array.sort(sortValues)
- : array);
-
- var i = -1,
- n = array.length,
- key = keys[depth++],
- keyValue,
- value,
- valuesByKey = map(),
- values,
- result = createResult();
-
- while (++i < n) {
- if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
- values.push(value);
- } else {
- valuesByKey.set(keyValue, [value]);
- }
- }
-
- valuesByKey.each(function(values, key) {
- setResult(result, key, apply(values, depth, createResult, setResult));
- });
-
- return result;
- }
-
- function entries(map, depth) {
- if (depth >= keys.length) return map;
-
- var array = [],
- sortKey = sortKeys[depth++];
-
- map.each(function(value, key) {
- array.push({key: key, values: entries(value, depth)});
- });
-
- return sortKey
- ? array.sort(function(a, b) { return sortKey(a.key, b.key); })
- : array;
- }
-
- return nest = {
- object: function(array) { return apply(array, 0, createObject, setObject); },
- map: function(array) { return apply(array, 0, createMap, setMap); },
- entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
- key: function(d) { keys.push(d); return nest; },
- sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
- sortValues: function(order) { sortValues = order; return nest; },
- rollup: function(f) { rollup = f; return nest; }
- };
-};
-
-function createObject() {
- return {};
-}
-
-function setObject(object, key, value) {
- object[key] = value;
-}
-
-function createMap() {
- return map();
-}
-
-function setMap(map, key, value) {
- map.set(key, value);
-}
diff --git a/src/set.js b/src/set.js
deleted file mode 100644
index 3521c88e..00000000
--- a/src/set.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import {default as map, prefix} from "./map";
-
-function Set() {}
-
-var proto = map.prototype;
-
-Set.prototype = set.prototype = {
- has: proto.has,
- add: function(value) {
- value += "";
- this[prefix + value] = value;
- return this;
- },
- remove: proto.remove,
- clear: proto.clear,
- values: proto.keys,
- size: proto.size,
- empty: proto.empty,
- each: proto.each
-};
-
-function set(object, f) {
- var set = new Set;
-
- // Copy constructor.
- if (object instanceof Set) object.each(function(value) { set.add(value); });
-
- // Otherwise, assume it’s an array.
- else if (object) {
- var i = -1, n = object.length, o;
- if (arguments.length === 1) while (++i < n) set.add(object[i]);
- else while (++i < n) set.add(f(o = object[i], i, object));
- }
-
- return set;
-}
-
-export default set;
diff --git a/src/values.js b/src/values.js
deleted file mode 100644
index 14bac97e..00000000
--- a/src/values.js
+++ /dev/null
@@ -1,5 +0,0 @@
-export default function(map) {
- var values = [];
- for (var key in map) values.push(map[key]);
- return values;
-};
diff --git a/test/entries-test.js b/test/entries-test.js
deleted file mode 100644
index f724b453..00000000
--- a/test/entries-test.js
+++ /dev/null
@@ -1,35 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-require("./isNaN");
-
-tape("entries(object) enumerates every entry", function(test) {
- test.deepEqual(arrays.entries({a: 1, b: 2}).sort(ascendingKey), [{key: "a", value: 1}, {key: "b", value: 2}]);
- test.end();
-});
-
-tape("entries(object) includes entries defined on prototypes", function(test) {
- function abc() {
- this.a = 1;
- this.b = 2;
- }
- abc.prototype.c = 3;
- test.deepEqual(arrays.entries(new abc).sort(ascendingKey), [{key: "a", value: 1}, {key: "b", value: 2}, {key: "c", value: 3}]);
- test.end();
-});
-
-tape("entries(object) includes null, undefined and NaN values", function(test) {
- var v = arrays.entries({a: null, b: undefined, c: NaN}).sort(ascendingKey);
- test.equal(v.length, 3);
- test.equal(v[0].key, "a");
- test.equal(v[0].value, null);
- test.equal(v[1].key, "b");
- test.equal(v[1].value, undefined);
- test.equal(v[2].key, "c");
- test.isNaN(v[2].value);
- test.end();
-});
-
-function ascendingKey(a, b) {
- return arrays.ascending(a.key, b.key);
-}
diff --git a/test/keys-test.js b/test/keys-test.js
deleted file mode 100644
index 9803b5c6..00000000
--- a/test/keys-test.js
+++ /dev/null
@@ -1,24 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-require("./isNaN");
-
-tape("keys(object) enumerates every entry", function(test) {
- test.deepEqual(arrays.keys({a: 1, b: 2}).sort(arrays.ascending), ["a", "b"]);
- test.end();
-});
-
-tape("keys(object) includes keys defined on prototypes", function(test) {
- function abc() {
- this.a = 1;
- this.b = 2;
- }
- abc.prototype.c = 3;
- test.deepEqual(arrays.keys(new abc).sort(arrays.ascending), ["a", "b", "c"]);
- test.end();
-});
-
-tape("keys(object) includes null, undefined and NaN values", function(test) {
- test.deepEqual(arrays.keys({a: null, b: undefined, c: NaN}).sort(arrays.ascending), ["a", "b", "c"]);
- test.end();
-});
diff --git a/test/map-test.js b/test/map-test.js
deleted file mode 100644
index 849a95fc..00000000
--- a/test/map-test.js
+++ /dev/null
@@ -1,352 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-tape("map() returns an empty map", function(test) {
- var m = arrays.map();
- test.equal(m instanceof arrays.map, true);
- test.deepEqual(m.keys(), []);
- test.end();
-});
-
-tape("map(null) returns an empty map", function(test) {
- var m = arrays.map(null);
- test.deepEqual(m.keys(), []);
- test.end();
-});
-
-tape("map(object) copies enumerable keys", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.has("foo"), true);
- test.equal(m.get("foo"), 42);
- var m = arrays.map(Object.create(null, {foo: {value: 42, enumerable: true}}));
- test.equal(m.has("foo"), true);
- test.equal(m.get("foo"), 42);
- test.end();
-});
-
-tape("map(object) copies inherited keys", function(test) {
- function Foo() {}
- Foo.prototype.foo = 42;
- var m = arrays.map(Object.create({foo: 42}));
- test.equal(m.has("foo"), true);
- test.equal(m.get("foo"), 42);
- var m = arrays.map(new Foo());
- test.equal(m.has("foo"), true);
- test.equal(m.get("foo"), 42);
- test.end();
-});
-
-tape("map(object) does not copy non-enumerable keys", function(test) {
- var m = arrays.map({__proto__: 42}); // because __proto__ isn't enumerable
- test.equal(m.has("__proto__"), false);
- test.equal(m.get("__proto__"), undefined);
- var m = arrays.map(Object.create(null, {foo: {value: 42, enumerable: false}}));
- test.equal(m.has("foo"), false);
- test.equal(m.get("foo"), undefined);
- test.end();
-});
-
-tape("map(map) copies the given map", function(test) {
- var a = arrays.map({foo: 42}),
- b = arrays.map(a);
- test.equal(b.has("foo"), true);
- test.equal(b.get("foo"), 42);
- a.set("bar", true);
- test.equal(b.has("bar"), false);
- test.end();
-});
-
-tape("map(array) creates a map by index", function(test) {
- test.deepEqual(arrays.map(["foo", "bar"]).entries(), [{key: "0", value: "foo"}, {key: "1", value: "bar"}]);
- test.end();
-});
-
-tape("map(array) indexes missing elements in sparse arrays", function(test) {
- test.deepEqual(arrays.map(["foo", , "bar"]).entries(), [{key: "0", value: "foo"}, {key: "1", value: undefined}, {key: "2", value: "bar"}]);
- test.end();
-});
-
-tape("map(array, f) creates a map by accessor", function(test) {
- test.deepEqual(arrays.map([{field: "foo"}, {field: "bar"}], function(d) { return d.field; }).entries(), [{key: "foo", value: {field: "foo"}}, {key: "bar", value: {field: "bar"}}]);
- test.deepEqual(arrays.map([{field: "foo"}, {field: "bar"}], function(d, i) { return i; }).entries(), [{key: "0", value: {field: "foo"}}, {key: "1", value: {field: "bar"}}]);
- test.deepEqual(arrays.map([{field: "foo"}, {field: "bar"}], function(d, i, array) { return array[i].field; }).entries(), [{key: "foo", value: {field: "foo"}}, {key: "bar", value: {field: "bar"}}]);
- test.end();
-});
-
-tape("map.size() returns the number of distinct keys", function(test) {
- var m = arrays.map();
- test.equal(m.size(), 0);
- m.set("foo", 1);
- test.equal(m.size(), 1);
- m.set("foo", 2);
- test.equal(m.size(), 1);
- m.set("bar", 2);
- test.equal(m.size(), 2);
- m.remove("foo");
- test.equal(m.size(), 1);
- m.remove("foo");
- test.equal(m.size(), 1);
- m.remove("bar");
- test.equal(m.size(), 0);
- test.end();
-});
-
-tape("map.clear() removes all entries", function(test) {
- var m = arrays.map().set("foo", 1).set("bar", 2).set("foo", 3);
- test.equal(m.size(), 2);
- m.clear();
- test.equal(m.size(), 0);
- test.deepEqual(m.entries(), []);
- test.end();
-});
-
-tape("map.empty() returns true only if the map is empty", function(test) {
- var m = arrays.map();
- test.equal(m.empty(), true);
- m.set("foo", 1);
- test.equal(m.empty(), false);
- m.set("foo", 2);
- test.equal(m.empty(), false);
- m.set("bar", 2);
- test.equal(m.empty(), false);
- m.remove("foo");
- test.equal(m.empty(), false);
- m.remove("foo");
- test.equal(m.empty(), false);
- m.remove("bar");
- test.equal(m.empty(), true);
- test.end();
-});
-
-tape("map.each(callback) passes value, key and the map", function(test) {
- var m = arrays.map({foo: 1, bar: "42"}),
- c = [];
- m.each(function(v, k, m) { c.push([k, v, m]); });
- c.sort(function(a, b) { return a[0].localeCompare(b[0]); });
- test.deepEqual(c, [["bar", "42", m], ["foo", 1, m]]);
- test.end();
-});
-
-tape("map.each(callback) uses the global context", function(test) {
- var m = arrays.map({foo: 1, bar: "42"}),
- c = [];
- m.each(function() { c.push(this); });
- test.strictEqual(c[0], global);
- test.strictEqual(c[1], global);
- test.equal(c.length, 2);
- test.end();
-});
-
-tape("map.each(callback) iterates in arbitrary order", function(test) {
- var m1 = arrays.map({foo: 1, bar: "42"}),
- m2 = arrays.map({bar: "42", foo: 1}),
- c1 = [],
- c2 = [];
- m1.each(function(v, k) { c1.push([k, v]); });
- m2.each(function(v, k) { c2.push([k, v]); });
- c1.sort(function(a, b) { return a[0].localeCompare(b[0]); });
- c2.sort(function(a, b) { return a[0].localeCompare(b[0]); });
- test.deepEqual(c1, c2);
- test.end();
-});
-
-tape("map.keys() returns an array of string keys", function(test) {
- var m = arrays.map({foo: 1, bar: "42"});
- test.deepEqual(m.keys().sort(), ["bar", "foo"]);
- test.end();
-});
-
-tape("map.keys() properly unescapes zero-prefixed keys", function(test) {
- var m = arrays.map().set("__proto__", 42).set("$weird", 42);
- test.deepEqual(m.keys().sort(), ["$weird", "__proto__"]);
- test.end();
-});
-
-tape("map.values() returns an array of arbitrary values", function(test) {
- var m = arrays.map({foo: 1, bar: "42"});
- test.deepEqual(m.values().sort(), [1, "42"]);
- test.end();
-});
-
-tape("map.entries() returns an array of key-value objects", function(test) {
- var m = arrays.map({foo: 1, bar: "42"});
- test.deepEqual(m.entries().sort(ascendingByKey), [{key: "bar", value: "42"}, {key: "foo", value: 1}]);
- test.end();
-});
-
-tape("map.entries() empty maps have an empty entries array", function(test) {
- var m = arrays.map();
- test.deepEqual(m.entries(), []);
- m.set("foo", "bar");
- test.deepEqual(m.entries(), [{key: "foo", value: "bar"}]);
- m.remove("foo");
- test.deepEqual(m.entries(), []);
- test.end();
-});
-
-tape("map.entries() entries are returned in arbitrary order", function(test) {
- var m = arrays.map({foo: 1, bar: "42"});
- test.deepEqual(m.entries().sort(ascendingByKey), [{key: "bar", value: "42"}, {key: "foo", value: 1}]);
- var m = arrays.map({bar: "42", foo: 1});
- test.deepEqual(m.entries().sort(ascendingByKey), [{key: "bar", value: "42"}, {key: "foo", value: 1}]);
- test.end();
-});
-
-tape("map.entries() observes changes via set and remove", function(test) {
- var m = arrays.map({foo: 1, bar: "42"});
- test.deepEqual(m.entries().sort(ascendingByKey), [{key: "bar", value: "42"}, {key: "foo", value: 1}]);
- m.remove("foo");
- test.deepEqual(m.entries(), [{key: "bar", value: "42"}]);
- m.set("bar", "bar");
- test.deepEqual(m.entries(), [{key: "bar", value: "bar"}]);
- m.set("foo", "foo");
- test.deepEqual(m.entries().sort(ascendingByKey), [{key: "bar", value: "bar"}, {key: "foo", value: "foo"}]);
- m.remove("bar");
- test.deepEqual(m.entries(), [{key: "foo", value: "foo"}]);
- m.remove("foo");
- test.deepEqual(m.entries(), []);
- m.remove("foo");
- test.deepEqual(m.entries(), []);
- test.end();
-});
-
-tape("map.has(key) empty maps do not have object built-ins", function(test) {
- var m = arrays.map();
- test.equal(m.has("__proto__"), false);
- test.equal(m.has("hasOwnProperty"), false);
- test.end();
-});
-
-tape("map.has(key) can has keys using built-in names", function(test) {
- var m = arrays.map().set("__proto__", 42);
- test.equal(m.has("__proto__"), true);
- test.end();
-});
-
-tape("map.has(key) can has keys with null or undefined properties", function(test) {
- var m = arrays.map().set("", "").set("null", null).set("undefined", undefined);
- test.equal(m.has(""), true);
- test.equal(m.has("null"), true);
- test.equal(m.has("undefined"), true);
- test.end();
-});
-
-tape("map.has(key) coerces keys to strings", function(test) {
- var m = arrays.map({"42": "foo", "null": 1, "undefined": 2});
- test.equal(m.has(42), true);
- test.equal(m.has(null), true);
- test.equal(m.has(undefined), true);
- test.end();
-});
-
-tape("map.has(key) returns the latest value", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.has("foo"), true);
- m.set("foo", 43);
- test.equal(m.has("foo"), true);
- m.remove("foo");
- test.equal(m.has("foo"), false);
- m.set("foo", "bar");
- test.equal(m.has("foo"), true);
- test.end();
-});
-
-tape("map.has(key) returns undefined for missing keys", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.has("bar"), false);
- test.end();
-});
-
-tape("map.get(key) empty maps do not have object built-ins", function(test) {
- var m = arrays.map();
- test.equal(m.get("__proto__"), undefined);
- test.equal(m.get("hasOwnProperty"), undefined);
- test.end()
-});
-
-tape("map.get(key) can get keys using built-in names", function(test) {
- var m = arrays.map();
- m.set("__proto__", 42);
- test.equal(m.get("__proto__"), 42);
- test.end()
-});
-
-tape("map.get(key) coerces keys to strings", function(test) {
- var m = arrays.map({"42": 1, "null": 2, "undefined": 3});
- test.equal(m.get(42), 1);
- test.equal(m.get(null), 2);
- test.equal(m.get(undefined), 3);
- test.end()
-});
-
-tape("map.get(key) returns the latest value", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.get("foo"), 42);
- m.set("foo", 43);
- test.equal(m.get("foo"), 43);
- m.remove("foo");
- test.equal(m.get("foo"), undefined);
- m.set("foo", "bar");
- test.equal(m.get("foo"), "bar");
- test.end()
-});
-
-tape("map.get(key) returns undefined for missing keys", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.get("bar"), undefined);
- test.end()
-});
-
-tape("map.set(key, value) returns the map", function(test) {
- var m = arrays.map();
- test.equal(m.set("foo", 42), m);
- test.end();
-});
-
-tape("map.set(key, value) can set keys using built-in names", function(test) {
- var m = arrays.map();
- m.set("__proto__", 42);
- test.equal(m.get("__proto__"), 42);
- test.end();
-});
-
-tape("map.set(key, value) can set keys using zero-prefixed names", function(test) {
- var m = arrays.map();
- m.set("$weird", 42);
- test.equal(m.get("$weird"), 42);
- test.end();
-});
-
-tape("map.set(key, value) coerces keys to strings", function(test) {
- var m = arrays.map();
- m.set(42, 1);
- test.equal(m.get(42), 1);
- m.set(null, 2);
- test.equal(m.get(null), 2);
- m.set(undefined, 3);
- test.equal(m.get(undefined), 3);
- test.deepEqual(m.keys().sort(), ["42", "null", "undefined"]);
- test.end();
-});
-
-tape("map.set(key, value) can replace values", function(test) {
- var m = arrays.map({foo: 42});
- test.equal(m.get("foo"), 42);
- m.set("foo", 43);
- test.equal(m.get("foo"), 43);
- m.set("foo", "bar");
- test.equal(m.get("foo"), "bar");
- test.end();
-});
-
-tape("map.set(key, value) can set null, undefined or empty string values", function(test) {
- var m = arrays.map().set("", "").set("null", null).set("undefined", undefined);
- test.equal(m.get(""), "");
- test.equal(m.get("null"), null);
- test.equal(m.get("undefined"), undefined);
- test.end();
-});
-
-function ascendingByKey(a, b) {
- return a.key.localeCompare(b.key);
-}
diff --git a/test/nest-test.js b/test/nest-test.js
deleted file mode 100644
index dae6ee3a..00000000
--- a/test/nest-test.js
+++ /dev/null
@@ -1,164 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-tape("nest.entries(array) returns the array of input values, in input order", function(test) {
- var nest = arrays.nest();
- test.deepEqual(nest.entries([1, 2, 3]), [1, 2, 3]);
- test.deepEqual(nest.entries([1, 3, 2]), [1, 3, 2]);
- test.deepEqual(nest.entries([3, 1, 2]), [3, 1, 2]);
- test.end();
-});
-
-tape("nest.sortValues(order).entries(array) returns input values in sorted order", function(test) {
- var nestAscending = arrays.nest().sortValues(function(a, b) { return a.foo - b.foo; }),
- nestDescending = arrays.nest().sortValues(function(a, b) { return b.foo - a.foo; }),
- a = {foo: 1},
- b = {foo: 2},
- c = {foo: 3};
- test.deepEqual(nestAscending.entries([a, b, c]), [a, b, c]);
- test.deepEqual(nestAscending.entries([a, c, b]), [a, b, c]);
- test.deepEqual(nestAscending.entries([c, a, b]), [a, b, c]);
- test.deepEqual(nestDescending.entries([a, b, c]), [c, b, a]);
- test.deepEqual(nestDescending.entries([a, c, b]), [c, b, a]);
- test.deepEqual(nestDescending.entries([c, a, b]), [c, b, a]);
- test.end();
-});
-
-tape("nest.key(key).entries(array) returns entries for each distinct key, with values in input order", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.ascending),
- a = {foo: 1},
- b = {foo: 1},
- c = {foo: 2};
- test.deepEqual(nest.entries([c, a, b, c]), [{key: "1", values: [a, b]}, {key: "2", values: [c, c]}]);
- test.deepEqual(nest.entries([c, b, a, c]), [{key: "1", values: [b, a]}, {key: "2", values: [c, c]}]);
- test.end();
-});
-
-tape("nest.key(key) coerces key values to strings", function(test) {
- var nest = arrays.nest().key(function(d) { return d.number ? 1 : "1"; }).sortKeys(arrays.ascending),
- a = {number: true},
- b = {number: false};
- test.deepEqual(nest.entries([a, b]), [{key: "1", values: [a, b]}]);
- test.end();
-});
-
-tape("nest.key(key1).key(key2).entries(array) returns entries for each distinct key set, with values in input order", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.ascending).key(function(d) { return d.bar; }).sortKeys(arrays.ascending),
- a = {foo: 1, bar: "a"},
- b = {foo: 1, bar: "a"},
- c = {foo: 2, bar: "a"},
- d = {foo: 1, bar: "b"},
- e = {foo: 1, bar: "b"},
- f = {foo: 2, bar: "b"};
- test.deepEqual(nest.entries([a, b, c, d, e, f]), [{key: "1", values: [{key: "a", values: [a, b]}, {key: "b", values: [d, e]}]}, {key: "2", values: [{key: "a", values: [c]}, {key: "b", values: [f]}]}]);
- test.deepEqual(nest.entries([f, e, d, c, b, a]), [{key: "1", values: [{key: "a", values: [b, a]}, {key: "b", values: [e, d]}]}, {key: "2", values: [{key: "a", values: [c]}, {key: "b", values: [f]}]}]);
- test.end();
-});
-
-tape("nest.key(key).sortKeys(order).entries(array) sorts entries by key using the specified order function", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.descending),
- a = {foo: 1},
- b = {foo: 1},
- c = {foo: 2};
- test.deepEqual(nest.entries([c, a, b, c]), [{key: "2", values: [c, c]}, {key: "1", values: [a, b]}]);
- test.deepEqual(nest.entries([c, b, a, c]), [{key: "2", values: [c, c]}, {key: "1", values: [b, a]}]);
- test.end();
-});
-
-tape("nest.key(key1).sortKeys(order1).key(key2).sortKeys(order2).entries(array) sorts entries by key using the specified order functions", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.descending).key(function(d) { return d.bar; }).sortKeys(arrays.descending),
- a = {foo: 1, bar: "a"},
- b = {foo: 1, bar: "a"},
- c = {foo: 2, bar: "a"},
- d = {foo: 1, bar: "b"},
- e = {foo: 1, bar: "b"},
- f = {foo: 2, bar: "b"};
- test.deepEqual(nest.entries([a, b, c, d, e, f]), [{key: "2", values: [{key: "b", values: [f]}, {key: "a", values: [c]}]}, {key: "1", values: [{key: "b", values: [d, e]}, {key: "a", values: [a, b]}]}]);
- test.deepEqual(nest.entries([f, e, d, c, b, a]), [{key: "2", values: [{key: "b", values: [f]}, {key: "a", values: [c]}]}, {key: "1", values: [{key: "b", values: [e, d]}, {key: "a", values: [b, a]}]}]);
- test.end();
-});
-
-tape("nest.rollup(rollup).entries(array) aggregates values using the specified rollup function", function(test) {
- test.equal(arrays.nest().rollup(function(values) { return values.length; }).entries([1, 2, 3, 4, 5]), 5);
- test.equal(arrays.nest().rollup(arrays.sum).entries([1, 2, 3, 4, 5]), 1 + 2 + 3 + 4 + 5);
- test.equal(arrays.nest().rollup(arrays.max).entries([1, 2, 3, 4, 5]), 5);
- test.deepEqual(arrays.nest().rollup(arrays.extent).entries([1, 2, 3, 4, 5]), [1, 5]);
- test.end();
-});
-
-tape("nest.rollup(rollup) uses the global this context", function(test) {
- var that;
- arrays.nest().rollup(function() { that = this; }).entries([1, 2, 3, 4, 5]);
- test.equal(that, global);
- test.end();
-});
-
-tape("nest.key(key).rollup(rollup).entries(array) aggregates values per key using the specified rollup function", function(test) {
- var a = {foo: 1},
- b = {foo: 1},
- c = {foo: 2};
- test.deepEqual(arrays.nest().key(function(d) { return d.foo; }).rollup(function(values) { return values.length; }).entries([a, b, c]), [{key: "1", values: 2}, {key: "2", values: 1}]);
- test.end();
-});
-
-tape("nest.map(array) returns the array of input values, in input order", function(test) {
- var nest = arrays.nest();
- test.deepEqual(nest.map([1, 2, 3]), [1, 2, 3]);
- test.deepEqual(nest.map([1, 3, 2]), [1, 3, 2]);
- test.deepEqual(nest.map([3, 1, 2]), [3, 1, 2]);
- test.end();
-});
-
-tape("nest.sortValues(order).map(array) returns input values in sorted order", function(test) {
- var nestAscending = arrays.nest().sortValues(function(a, b) { return a.foo - b.foo; }),
- nestDescending = arrays.nest().sortValues(function(a, b) { return b.foo - a.foo; }),
- a = {foo: 1},
- b = {foo: 2},
- c = {foo: 3};
- test.deepEqual(nestAscending.map([a, b, c]), [a, b, c]);
- test.deepEqual(nestAscending.map([a, c, b]), [a, b, c]);
- test.deepEqual(nestAscending.map([c, a, b]), [a, b, c]);
- test.deepEqual(nestDescending.map([a, b, c]), [c, b, a]);
- test.deepEqual(nestDescending.map([a, c, b]), [c, b, a]);
- test.deepEqual(nestDescending.map([c, a, b]), [c, b, a]);
- test.end();
-});
-
-tape("nest.key(key).map(array) returns entries for each distinct key, with values in input order", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.ascending),
- a = {foo: 1},
- b = {foo: 1},
- c = {foo: 2};
- test.deepEqual(nest.map([c, a, b, c]), arrays.map({1: [a, b], 2: [c, c]}));
- test.deepEqual(nest.map([c, b, a, c]), arrays.map({1: [b, a], 2: [c, c]}));
- test.end();
-});
-
-tape("nest.key(key1).key(key2).map(array) returns entries for each distinct key set, with values in input order", function(test) {
- var nest = arrays.nest().key(function(d) { return d.foo; }).sortKeys(arrays.ascending).key(function(d) { return d.bar; }).sortKeys(arrays.ascending),
- a = {foo: 1, bar: "a"},
- b = {foo: 1, bar: "a"},
- c = {foo: 2, bar: "a"},
- d = {foo: 1, bar: "b"},
- e = {foo: 1, bar: "b"},
- f = {foo: 2, bar: "b"};
- test.deepEqual(nest.map([a, b, c, d, e, f]), arrays.map({1: arrays.map({a: [a, b], b: [d, e]}), 2: arrays.map({a: [c], b: [f]})}));
- test.deepEqual(nest.map([f, e, d, c, b, a]), arrays.map({1: arrays.map({a: [b, a], b: [e, d]}), 2: arrays.map({a: [c], b: [f]})}));
- test.end();
-});
-
-tape("nest.rollup(rollup).map(array) aggregates values using the specified rollup function", function(test) {
- test.equal(arrays.nest().rollup(function(values) { return values.length; }).map([1, 2, 3, 4, 5]), 5);
- test.equal(arrays.nest().rollup(arrays.sum).map([1, 2, 3, 4, 5]), 1 + 2 + 3 + 4 + 5);
- test.equal(arrays.nest().rollup(arrays.max).map([1, 2, 3, 4, 5]), 5);
- test.deepEqual(arrays.nest().rollup(arrays.extent).map([1, 2, 3, 4, 5]), [1, 5]);
- test.end();
-});
-
-tape("nest.key(key).rollup(rollup).map(array) aggregates values per key using the specified rollup function", function(test) {
- var a = {foo: 1},
- b = {foo: 1},
- c = {foo: 2};
- test.deepEqual(arrays.nest().key(function(d) { return d.foo; }).rollup(function(values) { return values.length; }).map([a, b, c]), arrays.map({1: 2, 2: 1}));
- test.end();
-});
diff --git a/test/set-test.js b/test/set-test.js
deleted file mode 100644
index b8c891dc..00000000
--- a/test/set-test.js
+++ /dev/null
@@ -1,254 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-tape("set() returns an empty set", function(test) {
- var s = arrays.set();
- test.equal(s instanceof arrays.set, true);
- test.deepEqual(s.values(), []);
- test.end();
-});
-
-tape("set(null) returns an empty set", function(test) {
- var s = arrays.set(null);
- test.deepEqual(s.values(), []);
- test.end();
-});
-
-tape("set(array) adds array entries", function(test) {
- var s = arrays.set(["foo"]);
- test.equal(s.has("foo"), true);
- var s = arrays.set(["foo", "bar"]);
- test.equal(s.has("foo"), true);
- test.equal(s.has("bar"), true);
- test.end();
-});
-
-tape("set(array, f) observes the specified accessor function", function(test) {
- var name = function(d) { return d.name; };
- var s = arrays.set([{name: "foo"}], name);
- test.equal(s.has("foo"), true);
- var s = arrays.set([{name: "foo"}, {name: "bar"}], name);
- test.equal(s.has("foo"), true);
- test.equal(s.has("bar"), true);
- test.end();
-});
-
-tape("set(set) copies the given set", function(test) {
- var a = arrays.set(["foo"]),
- b = arrays.set(a);
- test.equal(b.has("foo"), true);
- test.equal(b.has("foo"), true);
- a.add("bar");
- test.equal(b.has("bar"), false);
- test.end();
-});
-
-tape("set.size() returns the number of distinct values", function(test) {
- var s = arrays.set();
- test.equal(s.size(), 0);
- s.add("foo");
- test.equal(s.size(), 1);
- s.add("foo");
- test.equal(s.size(), 1);
- s.add("bar");
- test.equal(s.size(), 2);
- s.remove("foo");
- test.equal(s.size(), 1);
- s.remove("foo");
- test.equal(s.size(), 1);
- s.remove("bar");
- test.equal(s.size(), 0);
- test.end();
-});
-
-tape("set.clear() removes all values", function(test) {
- var s = arrays.set().add("foo").add("bar").add("foo");
- test.equal(s.size(), 2);
- s.clear();
- test.equal(s.size(), 0);
- test.deepEqual(s.values(), []);
- test.end();
-});
-
-tape("set.empty() returns true only if the set is empty", function(test) {
- var s = arrays.set();
- test.equal(s.empty(), true);
- s.add("foo");
- test.equal(s.empty(), false);
- s.add("foo");
- test.equal(s.empty(), false);
- s.add("bar");
- test.equal(s.empty(), false);
- s.remove("foo");
- test.equal(s.empty(), false);
- s.remove("foo");
- test.equal(s.empty(), false);
- s.remove("bar");
- test.equal(s.empty(), true);
- test.end();
-});
-
-tape("set.each(callback) passes value, value and the set", function(test) {
- var s = arrays.set(["foo", "bar"]),
- c = [];
- s.each(function(v0, v1, s) { c.push([v0, v1, s]); });
- c.sort();
- test.deepEqual(c, [["bar", "bar", s], ["foo", "foo", s]]);
- test.end();
-});
-
-tape("set.each(callback) uses the global context", function(test) {
- var s = arrays.set(["foo", "bar"]),
- c = [];
- s.each(function() { c.push(this); });
- test.strictEqual(c[0], global);
- test.strictEqual(c[1], global);
- test.equal(c.length, 2);
- test.end();
-});
-
-tape("set.each(callback) iterates in arbitrary order", function(test) {
- var s1 = arrays.set(["foo", "bar"]),
- s2 = arrays.set(["bar", "foo"]),
- c1 = [],
- c2 = [];
- s1.each(function(v) { c1.push(v); });
- s2.each(function(v) { c2.push(v); });
- c1.sort();
- c2.sort();
- test.deepEqual(c1, c2);
- test.end();
-});
-
-tape("set.values() returns an array of string values", function(test) {
- var s = arrays.set(["foo", "bar"]);
- test.deepEqual(s.values().sort(), ["bar", "foo"]);
- test.end();
-});
-
-tape("set.values() empty sets have an empty values array", function(test) {
- var s = arrays.set();
- test.deepEqual(s.values(), []);
- s.add("foo");
- test.deepEqual(s.values(), ["foo"]);
- s.remove("foo");
- test.deepEqual(s.values(), []);
- test.end();
-});
-
-tape("set.values() values are returned in arbitrary order", function(test) {
- var s = arrays.set(["foo", "bar"]);
- test.deepEqual(s.values().sort(arrays.ascending), ["bar", "foo"]);
- var s = arrays.set(["bar", "foo"]);
- test.deepEqual(s.values().sort(arrays.ascending), ["bar", "foo"]);
- test.end();
-});
-
-tape("set.values() properly unescapes prefixed keys", function(test) {
- var s = arrays.set(["__proto__", "$weird"]);
- test.deepEqual(s.values().sort(arrays.ascending), ["$weird", "__proto__"]);
- test.end();
-});
-
-tape("set.values() observes changes via add and remove", function(test) {
- var s = arrays.set(["foo", "bar"]);
- test.deepEqual(s.values().sort(arrays.ascending), ["bar", "foo"]);
- s.remove("foo");
- test.deepEqual(s.values(), ["bar"]);
- s.add("bar");
- test.deepEqual(s.values(), ["bar"]);
- s.add("foo");
- test.deepEqual(s.values().sort(arrays.ascending), ["bar", "foo"]);
- s.remove("bar");
- test.deepEqual(s.values(), ["foo"]);
- s.remove("foo");
- test.deepEqual(s.values(), []);
- s.remove("foo");
- test.deepEqual(s.values(), []);
- test.end();
-});
-
-tape("set.has(value) empty sets do not have object built-ins", function(test) {
- var s = arrays.set();
- test.equal(s.has("__proto__"), false);
- test.equal(s.has("hasOwnProperty"), false);
- test.end();
-});
-
-tape("set.has(value) coerces values to strings", function(test) {
- var s = arrays.set(["42", "null", "undefined"]);
- test.equal(s.has(42), true);
- test.equal(s.has(null), true);
- test.equal(s.has(undefined), true);
- test.end();
-});
-
-tape("set.has(value) observes changes via add and remove", function(test) {
- var s = arrays.set(["foo"]);
- test.equal(s.has("foo"), true);
- s.add("foo");
- test.equal(s.has("foo"), true);
- s.remove("foo");
- test.equal(s.has("foo"), false);
- s.add("foo");
- test.equal(s.has("foo"), true);
- test.end();
-});
-
-tape("set.has(value) returns undefined for missing values", function(test) {
- var s = arrays.set(["foo"]);
- test.equal(s.has("bar"), false);
- test.end();
-});
-
-tape("set.add(value) returns the set", function(test) {
- var s = arrays.set();
- test.equal(s.add("foo"), s);
- test.equal(s.add(2), s);
- test.deepEqual(s.values().sort(), ["2", "foo"]);
- test.end();
-});
-
-tape("set.add(value) can add values using built-in names", function(test) {
- var s = arrays.set().add("__proto__");
- test.equal(s.has("__proto__"), true);
- test.end();
-});
-
-tape("set.add(value) can add values using zero-prefixed names", function(test) {
- var s = arrays.set().add("$weird");
- test.equal(s.has("$weird"), true);
- test.end();
-});
-
-tape("set.add(value) coerces values to strings", function(test) {
- var s = arrays.set();
- s.add(42);
- test.equal(s.has(42), true);
- s.add(null);
- test.equal(s.has(null), true);
- s.add(undefined);
- test.equal(s.has(undefined), true);
- test.deepEqual(s.values().sort(), ["42", "null", "undefined"]);
- test.end();
-});
-
-tape("set.add(value) can add null, undefined or empty string values", function(test) {
- var s = arrays.set().add("").add("null").add("undefined");
- test.equal(s.has(""), true);
- test.equal(s.has("null"), true);
- test.equal(s.has("undefined"), true);
- test.end();
-});
-
-tape("set.remove(value) returns true if the value was removed", function(test) {
- var s = arrays.set(["foo"]);
- test.equal(s.remove("foo"), true);
- test.end();
-});
-
-tape("set.remove(value) returns false if the value is not an element", function(test) {
- var s = arrays.set();
- test.equal(s.remove("foo"), false);
- test.end();
-});
diff --git a/test/values-test.js b/test/values-test.js
deleted file mode 100644
index 729eb4ff..00000000
--- a/test/values-test.js
+++ /dev/null
@@ -1,44 +0,0 @@
-var tape = require("tape"),
- arrays = require("../");
-
-require("./isNaN");
-
-tape("values(object) enumerates every value", function(test) {
- test.deepEqual(arrays.values({a: 1, b: 2}).sort(arrays.ascending), [1, 2]);
- test.end();
-});
-
-tape("values(object) includes values defined on prototypes", function(test) {
- function abc() {
- this.a = 1;
- this.b = 2;
- }
- abc.prototype.c = 3;
- test.deepEqual(arrays.values(new abc).sort(arrays.ascending), [1, 2, 3]);
- test.end();
-});
-
-tape("values(object) includes null, undefined and NaN values", function(test) {
- var v = arrays.values({a: null, b: undefined, c: NaN}).map(box).sort(order).map(unbox);
- test.equal(v.length, 3);
- test.equal(v[0], null);
- test.equal(v[1], undefined);
- test.isNaN(v[2]);
- test.end();
-});
-
-function box(value) {
- return {value: value};
-}
-
-function unbox(box) {
- return box.value;
-}
-
-function order(a, b) {
- a = a.value;
- b = b.value;
- return arrays.ascending(a, b)
- || isNaN(a) - isNaN(b)
- || (b === b) - (a === a);
-}