@@ -8,13 +8,18 @@ suite.addBatch({
88 "interpolate" : {
99 topic : load ( "interpolate/interpolate" ) . document ( ) ,
1010
11- "when a and b are numbers " : {
11+ "when b is a number " : {
1212 "interpolates numbers" : function ( d3 ) {
1313 assert . strictEqual ( d3 . interpolate ( 2 , 12 ) ( .4 ) , 6 ) ;
14+ } ,
15+ "coerces a to a number" : function ( d3 ) {
16+ assert . strictEqual ( d3 . interpolate ( "" , 1 ) ( .5 ) , .5 ) ;
17+ assert . strictEqual ( d3 . interpolate ( "2" , 12 ) ( .4 ) , 6 ) ;
18+ assert . strictEqual ( d3 . interpolate ( [ 2 ] , 12 ) ( .4 ) , 6 ) ;
1419 }
1520 } ,
1621
17- "when a and b are color strings " : {
22+ "when b is a color string " : {
1823 "interpolates RGB values and returns a hexadecimal string" : function ( d3 ) {
1924 assert . strictEqual ( d3 . interpolate ( "#ff0000" , "#008000" ) ( .4 ) , "#993300" ) ;
2025 } ,
@@ -26,10 +31,13 @@ suite.addBatch({
2631 } ,
2732 "interpolates decimal HSL colors in RGB" : function ( d3 ) {
2833 assert . strictEqual ( d3 . interpolate ( "hsl(0,100%,50%)" , "hsl(120,100%,25%)" ) ( .4 ) , "#993300" ) ;
34+ } ,
35+ "coerces a to a color" : function ( d3 ) {
36+ assert . strictEqual ( d3 . interpolate ( { toString : function ( ) { return "red" ; } } , "green" ) ( .4 ) , "#993300" ) ;
2937 }
3038 } ,
3139
32- "when a and b are color objects " : {
40+ "when b is a color object " : {
3341 "interpolates RGB values and returns a hexadecimal string" : function ( d3 ) {
3442 assert . strictEqual ( d3 . interpolate ( d3 . rgb ( 255 , 0 , 0 ) , d3 . rgb ( 0 , 128 , 0 ) ) ( .4 ) , "#993300" ) ;
3543 } ,
@@ -41,16 +49,19 @@ suite.addBatch({
4149 } ,
4250 "interpolates d3.hcl in RGB" : function ( d3 ) {
4351 assert . strictEqual ( d3 . interpolate ( d3 . hcl ( "red" ) , d3 . hcl ( "green" ) ) ( .4 ) , "#993300" ) ;
52+ } ,
53+ "coerces a to a color" : function ( d3 ) {
54+ assert . strictEqual ( d3 . interpolate ( { toString : function ( ) { return "red" ; } } , "green" ) ( .4 ) , "#993300" ) ;
4455 }
4556 } ,
4657
47- "when a and b are strings " : {
58+ "when b is a string " : {
4859 "interpolates matching numbers in both strings" : function ( d3 ) {
4960 assert . strictEqual ( d3 . interpolate ( " 10/20 30" , "50/10 100 " ) ( .4 ) , "26/16 58 " ) ;
5061 } ,
51- "if a and b are coercible to numbers, interpolates numbers rather than strings " : function ( d3 ) {
52- assert . strictEqual ( d3 . interpolate ( "1." , "2." ) ( .5 ) , 1.5 ) ;
53- assert . strictEqual ( d3 . interpolate ( "1e+3" , "1e+4" ) ( .5 ) , 5500 ) ;
62+ "if b is coercible to a number, still returns a string " : function ( d3 ) {
63+ assert . strictEqual ( d3 . interpolate ( "1." , "2." ) ( .5 ) , " 1.5" ) ;
64+ assert . strictEqual ( d3 . interpolate ( "1e+3" , "1e+4" ) ( .5 ) , " 5500" ) ;
5465 } ,
5566 "preserves non-numbers in string b" : function ( d3 ) {
5667 assert . strictEqual ( d3 . interpolate ( " 10/20 30" , "50/10 foo " ) ( .4 ) , "26/16 foo " ) ;
@@ -60,10 +71,13 @@ suite.addBatch({
6071 } ,
6172 "preserves equal-value numbers in both strings" : function ( d3 ) {
6273 assert . strictEqual ( d3 . interpolate ( " 10/20 100 20" , "50/10 100, 20 " ) ( .4 ) , "26/16 100, 20 " ) ;
74+ } ,
75+ "coerces a to a string" : function ( d3 ) {
76+ assert . strictEqual ( d3 . interpolate ( { toString : function ( ) { return "1." ; } } , "2." ) ( .5 ) , "1.5" ) ;
6377 }
6478 } ,
6579
66- "when a and b are arrays " : {
80+ "when b is an array " : {
6781 "interpolates each element in b" : function ( d3 ) {
6882 assert . strictEqual ( JSON . stringify ( d3 . interpolate ( [ 2 , 4 ] , [ 12 , 24 ] ) ( .4 ) ) , "[6,12]" ) ;
6983 } ,
@@ -77,7 +91,7 @@ suite.addBatch({
7791 }
7892 } ,
7993
80- "when a and b are objects " : {
94+ "when b is an object " : {
8195 "interpolates each property in b" : function ( d3 ) {
8296 assert . deepEqual ( d3 . interpolate ( { foo : 2 , bar : 4 } , { foo : 12 , bar : 24 } ) ( .4 ) , { foo : 6 , bar : 12 } ) ;
8397 } ,
@@ -93,16 +107,6 @@ suite.addBatch({
93107 }
94108 } ,
95109
96- "when a and b are different types" : {
97- "coerces both types to strings" : function ( d3 ) {
98- assert . strictEqual ( d3 . interpolate ( "2" , 12 ) ( .4 ) , 6 ) ;
99- assert . strictEqual ( d3 . interpolate ( "2px" , 12 ) ( .4 ) , 6 ) ;
100- assert . strictEqual ( d3 . interpolate ( [ 2 ] , 12 ) ( .4 ) , 6 ) ;
101- assert . strictEqual ( d3 . interpolate ( { valueOf : function ( ) { return 2 ; } } , 12 ) ( .4 ) , 6 ) ;
102- assert . strictEqual ( d3 . interpolate ( { toString : function ( ) { return 2 ; } } , 12 ) ( .4 ) , 6 ) ;
103- }
104- } ,
105-
106110 "may or may not interpolate between enumerable and non-enumerable properties" : function ( d3 ) {
107111 var a = Object . create ( { } , { foo : { value : 1 , enumerable : true } } ) ,
108112 b = Object . create ( { } , { foo : { value : 2 , enumerable : false } } ) ;
0 commit comments