Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MUR Drupal
d3-library
Commits
f37405d1
Commit
f37405d1
authored
Mar 14, 2013
by
Mike Bostock
Browse files
Refactor array tests for minimal loading.
parent
0f2b61ae
Changes
21
Hide whitespace changes
Inline
Side-by-side
test/arrays/ascending-test.js
View file @
f37405d1
...
...
@@ -6,37 +6,37 @@ var suite = vows.describe("d3.ascending");
suite
.
addBatch
({
"
d3.ascending
"
:
{
topic
:
load
(
"
arrays/ascending
"
),
topic
:
load
(
"
arrays/ascending
"
)
.
expression
(
"
d3.ascending
"
)
,
"
numbers
"
:
{
"
returns a negative number if a < b
"
:
function
(
d3
)
{
assert
.
isTrue
(
d3
.
ascending
(
0
,
1
)
<
0
);
"
returns a negative number if a < b
"
:
function
(
ascending
)
{
assert
.
isTrue
(
ascending
(
0
,
1
)
<
0
);
},
"
returns a positive number if a > b
"
:
function
(
d3
)
{
assert
.
isTrue
(
d3
.
ascending
(
1
,
0
)
>
0
);
"
returns a positive number if a > b
"
:
function
(
ascending
)
{
assert
.
isTrue
(
ascending
(
1
,
0
)
>
0
);
},
"
returns zero if a == b
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ascending
(
0
,
0
),
0
);
"
returns zero if a == b
"
:
function
(
ascending
)
{
assert
.
equal
(
ascending
(
0
,
0
),
0
);
},
"
returns NaN if a or b is undefined
"
:
function
(
d3
)
{
assert
.
isNaN
(
d3
.
ascending
(
0
,
undefined
));
assert
.
isNaN
(
d3
.
ascending
(
undefined
,
0
));
assert
.
isNaN
(
d3
.
ascending
(
undefined
,
undefined
));
"
returns NaN if a or b is undefined
"
:
function
(
ascending
)
{
assert
.
isNaN
(
ascending
(
0
,
undefined
));
assert
.
isNaN
(
ascending
(
undefined
,
0
));
assert
.
isNaN
(
ascending
(
undefined
,
undefined
));
},
"
returns NaN if a or b is NaN
"
:
function
(
d3
)
{
assert
.
isNaN
(
d3
.
ascending
(
0
,
NaN
));
assert
.
isNaN
(
d3
.
ascending
(
NaN
,
0
));
assert
.
isNaN
(
d3
.
ascending
(
NaN
,
NaN
));
"
returns NaN if a or b is NaN
"
:
function
(
ascending
)
{
assert
.
isNaN
(
ascending
(
0
,
NaN
));
assert
.
isNaN
(
ascending
(
NaN
,
0
));
assert
.
isNaN
(
ascending
(
NaN
,
NaN
));
}
},
"
strings
"
:
{
"
returns a negative number if a < b
"
:
function
(
d3
)
{
assert
.
isTrue
(
d3
.
ascending
(
"
a
"
,
"
b
"
)
<
0
);
"
returns a negative number if a < b
"
:
function
(
ascending
)
{
assert
.
isTrue
(
ascending
(
"
a
"
,
"
b
"
)
<
0
);
},
"
returns a positive number if a > b
"
:
function
(
d3
)
{
assert
.
isTrue
(
d3
.
ascending
(
"
b
"
,
"
a
"
)
>
0
);
"
returns a positive number if a > b
"
:
function
(
ascending
)
{
assert
.
isTrue
(
ascending
(
"
b
"
,
"
a
"
)
>
0
);
},
"
returns zero if a == b
"
:
function
(
d3
)
{
assert
.
equal
(
d3
.
ascending
(
"
a
"
,
"
a
"
),
0
);
"
returns zero if a == b
"
:
function
(
ascending
)
{
assert
.
equal
(
ascending
(
"
a
"
,
"
a
"
),
0
);
}
}
}
...
...
test/arrays/bisect-test.js
View file @
f37405d1
...
...
@@ -8,47 +8,47 @@ var i30 = 1 << 30;
suite
.
addBatch
({
"
bisectLeft
"
:
{
topic
:
load
(
"
arrays/bisect
"
),
"
finds the index of an exact match
"
:
function
(
d3
)
{
topic
:
load
(
"
arrays/bisect
"
)
.
expression
(
"
d3.bisectLeft
"
)
,
"
finds the index of an exact match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1
),
0
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2
),
1
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
1
),
0
);
assert
.
equal
(
bisect
(
array
,
2
),
1
);
assert
.
equal
(
bisect
(
array
,
3
),
2
);
},
"
finds the index of the first match
"
:
function
(
d3
)
{
"
finds the index of the first match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1
),
0
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2
),
1
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
1
),
0
);
assert
.
equal
(
bisect
(
array
,
2
),
1
);
assert
.
equal
(
bisect
(
array
,
3
),
3
);
},
"
finds the insertion point of a non-exact match
"
:
function
(
d3
)
{
"
finds the insertion point of a non-exact match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Left
(
array
,
0.5
),
0
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1.5
),
1
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2.5
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3.5
),
3
);
assert
.
equal
(
bisect
(
array
,
0.5
),
0
);
assert
.
equal
(
bisect
(
array
,
1.5
),
1
);
assert
.
equal
(
bisect
(
array
,
2.5
),
2
);
assert
.
equal
(
bisect
(
array
,
3.5
),
3
);
},
"
observes the optional lower bound
"
:
function
(
d3
)
{
"
observes the optional lower bound
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
,
4
,
5
];
assert
.
equal
(
d3
.
bisect
Left
(
array
,
0
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
4
,
2
),
3
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
5
,
2
),
4
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
6
,
2
),
5
);
assert
.
equal
(
bisect
(
array
,
0
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
1
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
2
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
3
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
4
,
2
),
3
);
assert
.
equal
(
bisect
(
array
,
5
,
2
),
4
);
assert
.
equal
(
bisect
(
array
,
6
,
2
),
5
);
},
"
observes the optional bounds
"
:
function
(
d3
)
{
"
observes the optional bounds
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
,
4
,
5
];
assert
.
equal
(
d3
.
bisect
Left
(
array
,
0
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
4
,
2
,
3
),
3
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
5
,
2
,
3
),
3
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
6
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
0
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
1
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
2
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
3
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
4
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
5
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
6
,
2
,
3
),
3
);
},
"
large arrays
"
:
function
(
d3
)
{
"
large arrays
"
:
function
(
bisect
)
{
var
array
=
[],
i
=
i30
;
array
[
i
++
]
=
1
;
...
...
@@ -56,57 +56,57 @@ suite.addBatch({
array
[
i
++
]
=
3
;
array
[
i
++
]
=
4
;
array
[
i
++
]
=
5
;
assert
.
equal
(
d3
.
bisect
Left
(
array
,
0
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
1
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
2
,
i
-
5
,
i
),
i
-
4
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
3
,
i
-
5
,
i
),
i
-
3
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
4
,
i
-
5
,
i
),
i
-
2
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
5
,
i
-
5
,
i
),
i
-
1
);
assert
.
equal
(
d3
.
bisect
Left
(
array
,
6
,
i
-
5
,
i
),
i
-
0
);
assert
.
equal
(
bisect
(
array
,
0
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
bisect
(
array
,
1
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
bisect
(
array
,
2
,
i
-
5
,
i
),
i
-
4
);
assert
.
equal
(
bisect
(
array
,
3
,
i
-
5
,
i
),
i
-
3
);
assert
.
equal
(
bisect
(
array
,
4
,
i
-
5
,
i
),
i
-
2
);
assert
.
equal
(
bisect
(
array
,
5
,
i
-
5
,
i
),
i
-
1
);
assert
.
equal
(
bisect
(
array
,
6
,
i
-
5
,
i
),
i
-
0
);
}
},
"
bisectRight
"
:
{
topic
:
load
(
"
arrays/bisect
"
),
"
finds the index after an exact match
"
:
function
(
d3
)
{
topic
:
load
(
"
arrays/bisect
"
)
.
expression
(
"
d3.bisectRight
"
)
,
"
finds the index after an exact match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1
),
1
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
1
),
1
);
assert
.
equal
(
bisect
(
array
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
3
),
3
);
},
"
finds the index after the last match
"
:
function
(
d3
)
{
"
finds the index after the last match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1
),
1
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2
),
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3
),
4
);
assert
.
equal
(
bisect
(
array
,
1
),
1
);
assert
.
equal
(
bisect
(
array
,
2
),
3
);
assert
.
equal
(
bisect
(
array
,
3
),
4
);
},
"
finds the insertion point of a non-exact match
"
:
function
(
d3
)
{
"
finds the insertion point of a non-exact match
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
];
assert
.
equal
(
d3
.
bisect
Right
(
array
,
0.5
),
0
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1.5
),
1
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2.5
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3.5
),
3
);
assert
.
equal
(
bisect
(
array
,
0.5
),
0
);
assert
.
equal
(
bisect
(
array
,
1.5
),
1
);
assert
.
equal
(
bisect
(
array
,
2.5
),
2
);
assert
.
equal
(
bisect
(
array
,
3.5
),
3
);
},
"
observes the optional lower bound
"
:
function
(
d3
)
{
"
observes the optional lower bound
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
,
4
,
5
];
assert
.
equal
(
d3
.
bisect
Right
(
array
,
0
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2
,
2
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3
,
2
),
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
4
,
2
),
4
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
5
,
2
),
5
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
6
,
2
),
5
);
assert
.
equal
(
bisect
(
array
,
0
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
1
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
2
,
2
),
2
);
assert
.
equal
(
bisect
(
array
,
3
,
2
),
3
);
assert
.
equal
(
bisect
(
array
,
4
,
2
),
4
);
assert
.
equal
(
bisect
(
array
,
5
,
2
),
5
);
assert
.
equal
(
bisect
(
array
,
6
,
2
),
5
);
},
"
observes the optional bounds
"
:
function
(
d3
)
{
"
observes the optional bounds
"
:
function
(
bisect
)
{
var
array
=
[
1
,
2
,
3
,
4
,
5
];
assert
.
equal
(
d3
.
bisect
Right
(
array
,
0
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2
,
2
,
3
),
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3
,
2
,
3
),
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
4
,
2
,
3
),
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
5
,
2
,
3
),
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
6
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
0
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
1
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
2
,
2
,
3
),
2
);
assert
.
equal
(
bisect
(
array
,
3
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
4
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
5
,
2
,
3
),
3
);
assert
.
equal
(
bisect
(
array
,
6
,
2
,
3
),
3
);
},
"
large arrays
"
:
function
(
d3
)
{
"
large arrays
"
:
function
(
bisect
)
{
var
array
=
[],
i
=
i30
;
array
[
i
++
]
=
1
;
...
...
@@ -114,20 +114,20 @@ suite.addBatch({
array
[
i
++
]
=
3
;
array
[
i
++
]
=
4
;
array
[
i
++
]
=
5
;
assert
.
equal
(
d3
.
bisect
Right
(
array
,
0
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
1
,
i
-
5
,
i
),
i
-
4
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
2
,
i
-
5
,
i
),
i
-
3
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
3
,
i
-
5
,
i
),
i
-
2
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
4
,
i
-
5
,
i
),
i
-
1
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
5
,
i
-
5
,
i
),
i
-
0
);
assert
.
equal
(
d3
.
bisect
Right
(
array
,
6
,
i
-
5
,
i
),
i
-
0
);
assert
.
equal
(
bisect
(
array
,
0
,
i
-
5
,
i
),
i
-
5
);
assert
.
equal
(
bisect
(
array
,
1
,
i
-
5
,
i
),
i
-
4
);
assert
.
equal
(
bisect
(
array
,
2
,
i
-
5
,
i
),
i
-
3
);
assert
.
equal
(
bisect
(
array
,
3
,
i
-
5
,
i
),
i
-
2
);
assert
.
equal
(
bisect
(
array
,
4
,
i
-
5
,
i
),
i
-
1
);
assert
.
equal
(
bisect
(
array
,
5
,
i
-
5
,
i
),
i
-
0
);
assert
.
equal
(
bisect
(
array
,
6
,
i
-
5
,
i
),
i
-
0
);
}
},
"
bisector(key)
"
:
{
topic
:
load
(
"
arrays/bisect
"
),
topic
:
load
(
"
arrays/bisect
"
)
.
expression
(
"
d3.bisector
"
)
,
"
left
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
bisector
(
function
(
d
)
{
return
d
.
key
;
}).
left
;
topic
:
function
(
bisector
)
{
return
bisector
(
function
(
d
)
{
return
d
.
key
;
}).
left
;
},
"
finds the index of an exact match
"
:
function
(
bisect
)
{
var
array
=
[{
key
:
1
},
{
key
:
2
},
{
key
:
3
}];
...
...
@@ -186,8 +186,8 @@ suite.addBatch({
}
},
"
right
"
:
{
topic
:
function
(
d3
)
{
return
d3
.
bisector
(
function
(
d
)
{
return
d
.
key
;
}).
right
;
topic
:
function
(
bisector
)
{
return
bisector
(
function
(
d
)
{
return
d
.
key
;
}).
right
;
},
"
finds the index after an exact match
"
:
function
(
bisect
)
{
var
array
=
[{
key
:
1
},
{
key
:
2
},
{
key
:
3
}];
...
...
test/arrays/descending-test.js
View file @
f37405d1
...
...
@@ -6,37 +6,37 @@ var suite = vows.describe("d3.descending");
suite
.
addBatch
({
"
descending
"
:
{
topic
:
load
(
"
arrays/descending
"
),
topic
:
load
(
"
arrays/descending
"
)
.
expression
(
"
d3.descending
"
)
,
"
numbers
"
:
{
"
returns a negative number if a > b
"
:
function
(
d
3
)
{
assert
.
isTrue
(
d3
.
descending
(
1
,
0
)
<
0
);
"
returns a negative number if a > b
"
:
function
(
d
escending
)
{
assert
.
isTrue
(
descending
(
1
,
0
)
<
0
);
},
"
returns a positive number if a < b
"
:
function
(
d
3
)
{
assert
.
isTrue
(
d3
.
descending
(
0
,
1
)
>
0
);
"
returns a positive number if a < b
"
:
function
(
d
escending
)
{
assert
.
isTrue
(
descending
(
0
,
1
)
>
0
);
},
"
returns zero if a == b
"
:
function
(
d
3
)
{
assert
.
equal
(
d3
.
descending
(
0
,
0
),
0
);
"
returns zero if a == b
"
:
function
(
d
escending
)
{
assert
.
equal
(
descending
(
0
,
0
),
0
);
},
"
returns NaN if a or b is undefined
"
:
function
(
d
3
)
{
assert
.
isNaN
(
d3
.
descending
(
0
,
undefined
));
assert
.
isNaN
(
d3
.
descending
(
undefined
,
0
));
assert
.
isNaN
(
d3
.
descending
(
undefined
,
undefined
));
"
returns NaN if a or b is undefined
"
:
function
(
d
escending
)
{
assert
.
isNaN
(
descending
(
0
,
undefined
));
assert
.
isNaN
(
descending
(
undefined
,
0
));
assert
.
isNaN
(
descending
(
undefined
,
undefined
));
},
"
returns NaN if a or b is NaN
"
:
function
(
d
3
)
{
assert
.
isNaN
(
d3
.
descending
(
0
,
NaN
));
assert
.
isNaN
(
d3
.
descending
(
NaN
,
0
));
assert
.
isNaN
(
d3
.
descending
(
NaN
,
NaN
));
"
returns NaN if a or b is NaN
"
:
function
(
d
escending
)
{
assert
.
isNaN
(
descending
(
0
,
NaN
));
assert
.
isNaN
(
descending
(
NaN
,
0
));
assert
.
isNaN
(
descending
(
NaN
,
NaN
));
}
},
"
strings
"
:
{
"
returns a negative number if a > b
"
:
function
(
d
3
)
{
assert
.
isTrue
(
d3
.
descending
(
"
b
"
,
"
a
"
)
<
0
);
"
returns a negative number if a > b
"
:
function
(
d
escending
)
{
assert
.
isTrue
(
descending
(
"
b
"
,
"
a
"
)
<
0
);
},
"
returns a positive number if a < b
"
:
function
(
d
3
)
{
assert
.
isTrue
(
d3
.
descending
(
"
a
"
,
"
b
"
)
>
0
);
"
returns a positive number if a < b
"
:
function
(
d
escending
)
{
assert
.
isTrue
(
descending
(
"
a
"
,
"
b
"
)
>
0
);
},
"
returns zero if a == b
"
:
function
(
d
3
)
{
assert
.
equal
(
d3
.
descending
(
"
a
"
,
"
a
"
),
0
);
"
returns zero if a == b
"
:
function
(
d
escending
)
{
assert
.
equal
(
descending
(
"
a
"
,
"
a
"
),
0
);
}
}
}
...
...
test/arrays/entries-test.js
View file @
f37405d1
...
...
@@ -6,27 +6,27 @@ var suite = vows.describe("d3.entries");
suite
.
addBatch
({
"
entries
"
:
{
topic
:
load
(
"
arrays/entries
"
),
"
enumerates every entry
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
entries
({
a
:
1
,
b
:
2
}),
[
topic
:
load
(
"
arrays/entries
"
)
.
expression
(
"
d3.entries
"
)
,
"
enumerates every entry
"
:
function
(
entries
)
{
assert
.
deepEqual
(
entries
({
a
:
1
,
b
:
2
}),
[
{
key
:
"
a
"
,
value
:
1
},
{
key
:
"
b
"
,
value
:
2
}
]);
},
"
includes entries defined on prototypes
"
:
function
(
d3
)
{
"
includes entries defined on prototypes
"
:
function
(
entries
)
{
function
abc
()
{
this
.
a
=
1
;
this
.
b
=
2
;
}
abc
.
prototype
.
c
=
3
;
assert
.
deepEqual
(
d3
.
entries
(
new
abc
()),
[
assert
.
deepEqual
(
entries
(
new
abc
()),
[
{
key
:
"
a
"
,
value
:
1
},
{
key
:
"
b
"
,
value
:
2
},
{
key
:
"
c
"
,
value
:
3
}
]);
},
"
includes null or undefined values
"
:
function
(
d3
)
{
var
v
=
d3
.
entries
({
a
:
undefined
,
b
:
null
,
c
:
NaN
});
"
includes null or undefined values
"
:
function
(
entries
)
{
var
v
=
entries
({
a
:
undefined
,
b
:
null
,
c
:
NaN
});
assert
.
equal
(
v
.
length
,
3
);
assert
.
deepEqual
(
v
[
0
],
{
key
:
"
a
"
,
value
:
undefined
});
assert
.
deepEqual
(
v
[
1
],
{
key
:
"
b
"
,
value
:
null
});
...
...
test/arrays/extent-test.js
View file @
f37405d1
...
...
@@ -6,40 +6,40 @@ var suite = vows.describe("d3.extent");
suite
.
addBatch
({
"
extent
"
:
{
topic
:
load
(
"
arrays/extent
"
),
"
returns the numeric extent for numbers
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
extent
([
1
]),
[
1
,
1
]);
assert
.
deepEqual
(
d3
.
extent
([
5
,
1
,
2
,
3
,
4
]),
[
1
,
5
]);
assert
.
deepEqual
(
d3
.
extent
([
20
,
3
]),
[
3
,
20
]);
assert
.
deepEqual
(
d3
.
extent
([
3
,
20
]),
[
3
,
20
]);
topic
:
load
(
"
arrays/extent
"
)
.
expression
(
"
d3.extent
"
)
,
"
returns the numeric extent for numbers
"
:
function
(
extent
)
{
assert
.
deepEqual
(
extent
([
1
]),
[
1
,
1
]);
assert
.
deepEqual
(
extent
([
5
,
1
,
2
,
3
,
4
]),
[
1
,
5
]);
assert
.
deepEqual
(
extent
([
20
,
3
]),
[
3
,
20
]);
assert
.
deepEqual
(
extent
([
3
,
20
]),
[
3
,
20
]);
},
"
returns the lexicographic extent for strings
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
extent
([
"
c
"
,
"
a
"
,
"
b
"
]),
[
"
a
"
,
"
c
"
]);
assert
.
deepEqual
(
d3
.
extent
([
"
20
"
,
"
3
"
]),
[
"
20
"
,
"
3
"
]);
assert
.
deepEqual
(
d3
.
extent
([
"
3
"
,
"
20
"
]),
[
"
20
"
,
"
3
"
]);
"
returns the lexicographic extent for strings
"
:
function
(
extent
)
{
assert
.
deepEqual
(
extent
([
"
c
"
,
"
a
"
,
"
b
"
]),
[
"
a
"
,
"
c
"
]);
assert
.
deepEqual
(
extent
([
"
20
"
,
"
3
"
]),
[
"
20
"
,
"
3
"
]);
assert
.
deepEqual
(
extent
([
"
3
"
,
"
20
"
]),
[
"
20
"
,
"
3
"
]);
},
"
ignores null, undefined and NaN
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
extent
([
NaN
,
1
,
2
,
3
,
4
,
5
]),
[
1
,
5
]);
assert
.
deepEqual
(
d3
.
extent
([
1
,
2
,
3
,
4
,
5
,
NaN
]),
[
1
,
5
]);
assert
.
deepEqual
(
d3
.
extent
([
10
,
null
,
3
,
undefined
,
5
,
NaN
]),
[
3
,
10
]);
assert
.
deepEqual
(
d3
.
extent
([
-
1
,
null
,
-
3
,
undefined
,
-
5
,
NaN
]),
[
-
5
,
-
1
]);
"
ignores null, undefined and NaN
"
:
function
(
extent
)
{
assert
.
deepEqual
(
extent
([
NaN
,
1
,
2
,
3
,
4
,
5
]),
[
1
,
5
]);
assert
.
deepEqual
(
extent
([
1
,
2
,
3
,
4
,
5
,
NaN
]),
[
1
,
5
]);
assert
.
deepEqual
(
extent
([
10
,
null
,
3
,
undefined
,
5
,
NaN
]),
[
3
,
10
]);
assert
.
deepEqual
(
extent
([
-
1
,
null
,
-
3
,
undefined
,
-
5
,
NaN
]),
[
-
5
,
-
1
]);
},
"
compares heterogenous types as numbers
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
extent
([
20
,
"
3
"
]),
[
"
3
"
,
20
]);
assert
.
deepEqual
(
d3
.
extent
([
"
20
"
,
3
]),
[
3
,
"
20
"
]);
assert
.
deepEqual
(
d3
.
extent
([
3
,
"
20
"
]),
[
3
,
"
20
"
]);
assert
.
deepEqual
(
d3
.
extent
([
"
3
"
,
20
]),
[
"
3
"
,
20
]);
"
compares heterogenous types as numbers
"
:
function
(
extent
)
{
assert
.
deepEqual
(
extent
([
20
,
"
3
"
]),
[
"
3
"
,
20
]);
assert
.
deepEqual
(
extent
([
"
20
"
,
3
]),
[
3
,
"
20
"
]);
assert
.
deepEqual
(
extent
([
3
,
"
20
"
]),
[
3
,
"
20
"
]);
assert
.
deepEqual
(
extent
([
"
3
"
,
20
]),
[
"
3
"
,
20
]);
},
"
returns undefined for empty array
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
extent
([]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
d3
.
extent
([
null
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
d3
.
extent
([
undefined
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
d3
.
extent
([
NaN
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
d3
.
extent
([
NaN
,
NaN
]),
[
undefined
,
undefined
]);
"
returns undefined for empty array
"
:
function
(
extent
)
{
assert
.
deepEqual
(
extent
([]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
extent
([
null
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
extent
([
undefined
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
extent
([
NaN
]),
[
undefined
,
undefined
]);
assert
.
deepEqual
(
extent
([
NaN
,
NaN
]),
[
undefined
,
undefined
]);
},
"
applies the optional accessor function exactly once
"
:
function
(
d3
)
{
"
applies the optional accessor function exactly once
"
:
function
(
extent
)
{
var
i
=
10
;
assert
.
deepEqual
(
d3
.
extent
([
0
,
1
,
2
,
3
],
function
()
{
return
++
i
;
}),
[
11
,
14
]);
assert
.
deepEqual
(
extent
([
0
,
1
,
2
,
3
],
function
()
{
return
++
i
;
}),
[
11
,
14
]);
}
}
});
...
...
test/arrays/keys-test.js
View file @
f37405d1
...
...
@@ -6,20 +6,20 @@ var suite = vows.describe("d3.keys");
suite
.
addBatch
({
"
keys
"
:
{
topic
:
load
(
"
arrays/keys
"
),
"
enumerates every defined key
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
keys
({
a
:
1
,
b
:
1
}),
[
"
a
"
,
"
b
"
]);
topic
:
load
(
"
arrays/keys
"
)
.
expression
(
"
d3.keys
"
)
,
"
enumerates every defined key
"
:
function
(
keys
)
{
assert
.
deepEqual
(
keys
({
a
:
1
,
b
:
1
}),
[
"
a
"
,
"
b
"
]);
},
"
includes keys defined on prototypes
"
:
function
(
d3
)
{
"
includes keys defined on prototypes
"
:
function
(
keys
)
{
function
abc
()
{
this
.
a
=
1
;
this
.
b
=
2
;
}
abc
.
prototype
.
c
=
3
;
assert
.
deepEqual
(
d3
.
keys
(
new
abc
()),
[
"
a
"
,
"
b
"
,
"
c
"
]);
assert
.
deepEqual
(
keys
(
new
abc
()),
[
"
a
"
,
"
b
"
,
"
c
"
]);
},
"
includes keys with null or undefined values
"
:
function
(
d3
)
{
assert
.
deepEqual
(
d3
.
keys
({
a
:
undefined
,
b
:
null
,
c
:
NaN
}),
[
"
a
"
,
"
b
"
,
"
c
"
]);
"
includes keys with null or undefined values
"
:
function
(
keys
)
{
assert
.
deepEqual
(
keys
({
a
:
undefined
,
b
:
null
,
c
:
NaN
}),
[
"
a
"
,
"
b
"
,
"
c
"
]);
}
}
});
...
...
test/arrays/map-test.js
View file @
f37405d1
...
...
@@ -6,202 +6,202 @@ var suite = vows.describe("d3.map");
suite
.
addBatch
({
"
map
"
:
{
topic
:
load
(
"
arrays/map
"
),
topic
:
load
(
"
arrays/map
"
)
.
expression
(
"
d3.map
"
)
,
"
constructor
"
:
{
"
map() returns an empty map
"
:
function
(
d3
)
{
var
m
ap
=
d3
.
map
();
assert
.
deepEqual
(
m
ap
.
keys
(),
[]);
},
"
map(null) returns an empty map
"
:
function
(
d3
)
{
var
m
ap
=
d3
.
map
(
null
);
assert
.
deepEqual
(
m
ap
.
keys
(),
[]);
},
"
map(object) copies enumerable keys
"
:
function
(
d3
)
{
var
m
ap
=
d3
.
map
({
foo
:
42
});
assert
.
isTrue
(
m
ap
.
has
(
"
foo
"
));
assert
.
equal
(
m
ap
.
get
(
"
foo
"
),
42
);
var
m
ap
=
d3
.
map
(
Object
.
create
(
null
,
{
foo
:
{
value
:
42
,
enumerable
:
true
}}));
assert
.
isTrue
(
m
ap
.
has
(
"
foo
"
));
assert
.
equal
(
m
ap
.
get
(
"
foo
"
),
42
);
},
"
map(object) copies inherited keys
"
:
function
(
d3
)
{
"
map() returns an empty map
"
:
function
(
map
)
{
var
m
=
map
();
assert
.
deepEqual
(
m
.
keys
(),
[]);
},
"
map(null) returns an empty map
"
:
function
(
map
)
{
var
m
=
map
(
null
);
assert
.
deepEqual
(
m
.
keys
(),
[]);
},
"
map(object) copies enumerable keys
"
:
function
(
map
)
{
var
m
=
map
({
foo
:
42
});
assert
.
isTrue
(
m
.
has
(
"
foo
"
));
assert
.
equal
(
m
.
get
(
"
foo
"
),
42
);
var
m
=
map
(
Object
.
create
(
null
,
{
foo
:
{
value
:
42
,
enumerable
:
true
}}));
assert
.
isTrue
(
m
.
has
(
"
foo
"
));
assert
.
equal
(
m
.
get
(
"
foo
"
),
42
);
},
"
map(object) copies inherited keys
"
:
function
(
map
)
{
function
Foo
()
{}
Foo
.
prototype
.
foo
=
42
;
var
m
ap
=
d3
.
map
(
Object
.
create
({
foo
:
42
}));
assert
.
isTrue
(
m
ap
.
has
(
"
foo
"
));
assert
.
equal
(
m
ap
.
get
(
"
foo
"
),
42
);
var
m
ap
=
d3
.
map
(
new
Foo
());
assert
.
isTrue
(
m
ap
.
has
(
"
foo
"
));
assert
.
equal
(
m
ap
.
get
(
"
foo
"
),
42
);
},
"
map(object) does not copy non-enumerable keys
"
:
function
(
d3
)
{
var
m
ap
=
d3
.
map
({
__proto__
:
42
});
// because __proto__ isn't enumerable
assert
.
isFalse
(
m
ap
.
has
(
"
__proto__
"
));
assert
.
isUndefined
(
m
ap
.
get
(
"
__proto__
"
));
var
m
ap
=
d3
.
map
(
Object
.
create
(
null
,
{
foo
:
{
value
:
42
,
enumerable
:
false
}}));
assert
.
isFalse
(
m
ap
.
has
(
"
foo
"
));
assert
.
isUndefined
(
m
ap
.
get
(
"
foo
"
));
var
m
=
map
(
Object
.
create
({
foo
:
42
}));
assert
.
isTrue
(
m
.
has
(
"
foo
"
));
assert
.
equal
(
m
.
get
(
"
foo
"
),
42
);
var
m
=
map
(
new
Foo
());
assert
.
isTrue
(
m
.
has
(
"
foo
"
));
assert
.
equal
(
m
.
get
(
"
foo
"
),
42
);
},
"
map(object) does not copy non-enumerable keys
"
:
function
(
map
)
{
var
m
=
map
({
__proto__
:
42
});
// because __proto__ isn't enumerable
assert
.
isFalse
(
m
.
has
(
"
__proto__
"
));
assert
.
isUndefined
(
m
.
get
(
"
__proto__
"
));
var
m
=
map
(
Object
.
create
(
null
,
{
foo
:
{
value
:
42
,
enumerable
:
false
}}));
assert
.
isFalse
(
m
.
has
(
"
foo
"
));
assert
.
isUndefined
(
m
.
get
(
"
foo
"
));
}
},
"
forEach
"
:
{