Commit ae9d4a40 authored by Mike Bostock's avatar Mike Bostock
Browse files

Refactor format tests for minimal loading.

parent af25181d
This diff is collapsed.
......@@ -6,105 +6,105 @@ var suite = vows.describe("d3.formatPrefix");
suite.addBatch({
"formatPrefix": {
topic: load("format/formatPrefix"),
"determines the appropriate prefix for small numbers": function(d3) {
assert.equal(d3.formatPrefix(0).symbol, "");
assert.equal(d3.formatPrefix(1e-00).symbol, "");
assert.equal(d3.formatPrefix(1e-01).symbol, "");
assert.equal(d3.formatPrefix(1e-02).symbol, "");
assert.equal(d3.formatPrefix(1e-03).symbol, "m");
assert.equal(d3.formatPrefix(1e-04).symbol, "m");
assert.equal(d3.formatPrefix(1e-05).symbol, "m");
assert.equal(d3.formatPrefix(1e-06).symbol, "µ");
assert.equal(d3.formatPrefix(1e-07).symbol, "µ");
assert.equal(d3.formatPrefix(1e-08).symbol, "µ");
assert.equal(d3.formatPrefix(1e-09).symbol, "n");
assert.equal(d3.formatPrefix(1e-10).symbol, "n");
assert.equal(d3.formatPrefix(1e-11).symbol, "n");
assert.equal(d3.formatPrefix(1e-12).symbol, "p");
assert.equal(d3.formatPrefix(1e-13).symbol, "p");
assert.equal(d3.formatPrefix(1e-14).symbol, "p");
assert.equal(d3.formatPrefix(1e-15).symbol, "f");
assert.equal(d3.formatPrefix(1e-16).symbol, "f");
assert.equal(d3.formatPrefix(1e-17).symbol, "f");
assert.equal(d3.formatPrefix(1e-18).symbol, "a");
assert.equal(d3.formatPrefix(1e-19).symbol, "a");
assert.equal(d3.formatPrefix(1e-20).symbol, "a");
assert.equal(d3.formatPrefix(1e-21).symbol, "z");
assert.equal(d3.formatPrefix(1e-22).symbol, "z");
assert.equal(d3.formatPrefix(1e-23).symbol, "z");
assert.equal(d3.formatPrefix(1e-24).symbol, "y");
assert.equal(d3.formatPrefix(1e-25).symbol, "y");
assert.equal(d3.formatPrefix(1e-26).symbol, "y");
assert.equal(d3.formatPrefix(1e-27).symbol, "y");
topic: load("format/formatPrefix").expression("d3.formatPrefix"),
"determines the appropriate prefix for small numbers": function(prefix) {
assert.equal(prefix(0).symbol, "");
assert.equal(prefix(1e-00).symbol, "");
assert.equal(prefix(1e-01).symbol, "");
assert.equal(prefix(1e-02).symbol, "");
assert.equal(prefix(1e-03).symbol, "m");
assert.equal(prefix(1e-04).symbol, "m");
assert.equal(prefix(1e-05).symbol, "m");
assert.equal(prefix(1e-06).symbol, "µ");
assert.equal(prefix(1e-07).symbol, "µ");
assert.equal(prefix(1e-08).symbol, "µ");
assert.equal(prefix(1e-09).symbol, "n");
assert.equal(prefix(1e-10).symbol, "n");
assert.equal(prefix(1e-11).symbol, "n");
assert.equal(prefix(1e-12).symbol, "p");
assert.equal(prefix(1e-13).symbol, "p");
assert.equal(prefix(1e-14).symbol, "p");
assert.equal(prefix(1e-15).symbol, "f");
assert.equal(prefix(1e-16).symbol, "f");
assert.equal(prefix(1e-17).symbol, "f");
assert.equal(prefix(1e-18).symbol, "a");
assert.equal(prefix(1e-19).symbol, "a");
assert.equal(prefix(1e-20).symbol, "a");
assert.equal(prefix(1e-21).symbol, "z");
assert.equal(prefix(1e-22).symbol, "z");
assert.equal(prefix(1e-23).symbol, "z");
assert.equal(prefix(1e-24).symbol, "y");
assert.equal(prefix(1e-25).symbol, "y");
assert.equal(prefix(1e-26).symbol, "y");
assert.equal(prefix(1e-27).symbol, "y");
},
"determines the appropriate prefix for large numbers": function(d3) {
assert.equal(d3.formatPrefix(0).symbol, "");
assert.equal(d3.formatPrefix(1e00).symbol, "");
assert.equal(d3.formatPrefix(1e01).symbol, "");
assert.equal(d3.formatPrefix(1e02).symbol, "");
assert.equal(d3.formatPrefix(1e03).symbol, "k");
assert.equal(d3.formatPrefix(1e04).symbol, "k");
assert.equal(d3.formatPrefix(1e05).symbol, "k");
assert.equal(d3.formatPrefix(1e06).symbol, "M");
assert.equal(d3.formatPrefix(1e07).symbol, "M");
assert.equal(d3.formatPrefix(1e08).symbol, "M");
assert.equal(d3.formatPrefix(1e09).symbol, "G");
assert.equal(d3.formatPrefix(1e10).symbol, "G");
assert.equal(d3.formatPrefix(1e11).symbol, "G");
assert.equal(d3.formatPrefix(1e12).symbol, "T");
assert.equal(d3.formatPrefix(1e13).symbol, "T");
assert.equal(d3.formatPrefix(1e14).symbol, "T");
assert.equal(d3.formatPrefix(1e15).symbol, "P");
assert.equal(d3.formatPrefix(1e16).symbol, "P");
assert.equal(d3.formatPrefix(1e17).symbol, "P");
assert.equal(d3.formatPrefix(1e18).symbol, "E");
assert.equal(d3.formatPrefix(1e19).symbol, "E");
assert.equal(d3.formatPrefix(1e20).symbol, "E");
assert.equal(d3.formatPrefix(1e21).symbol, "Z");
assert.equal(d3.formatPrefix(1e22).symbol, "Z");
assert.equal(d3.formatPrefix(1e23).symbol, "Z");
assert.equal(d3.formatPrefix(1e24).symbol, "Y");
assert.equal(d3.formatPrefix(1e25).symbol, "Y");
assert.equal(d3.formatPrefix(1e26).symbol, "Y");
assert.equal(d3.formatPrefix(1e27).symbol, "Y");
"determines the appropriate prefix for large numbers": function(prefix) {
assert.equal(prefix(0).symbol, "");
assert.equal(prefix(1e00).symbol, "");
assert.equal(prefix(1e01).symbol, "");
assert.equal(prefix(1e02).symbol, "");
assert.equal(prefix(1e03).symbol, "k");
assert.equal(prefix(1e04).symbol, "k");
assert.equal(prefix(1e05).symbol, "k");
assert.equal(prefix(1e06).symbol, "M");
assert.equal(prefix(1e07).symbol, "M");
assert.equal(prefix(1e08).symbol, "M");
assert.equal(prefix(1e09).symbol, "G");
assert.equal(prefix(1e10).symbol, "G");
assert.equal(prefix(1e11).symbol, "G");
assert.equal(prefix(1e12).symbol, "T");
assert.equal(prefix(1e13).symbol, "T");
assert.equal(prefix(1e14).symbol, "T");
assert.equal(prefix(1e15).symbol, "P");
assert.equal(prefix(1e16).symbol, "P");
assert.equal(prefix(1e17).symbol, "P");
assert.equal(prefix(1e18).symbol, "E");
assert.equal(prefix(1e19).symbol, "E");
assert.equal(prefix(1e20).symbol, "E");
assert.equal(prefix(1e21).symbol, "Z");
assert.equal(prefix(1e22).symbol, "Z");
assert.equal(prefix(1e23).symbol, "Z");
assert.equal(prefix(1e24).symbol, "Y");
assert.equal(prefix(1e25).symbol, "Y");
assert.equal(prefix(1e26).symbol, "Y");
assert.equal(prefix(1e27).symbol, "Y");
},
"determines the appropriate prefix for negative numbers": function(d3) {
assert.equal(d3.formatPrefix(-0).symbol, "");
assert.equal(d3.formatPrefix(-1e-00).symbol, "");
assert.equal(d3.formatPrefix(-1e-03).symbol, "m");
assert.equal(d3.formatPrefix(-1e-06).symbol, "µ");
assert.equal(d3.formatPrefix(-1e-09).symbol, "n");
assert.equal(d3.formatPrefix(-1e-12).symbol, "p");
assert.equal(d3.formatPrefix(-1e-15).symbol, "f");
assert.equal(d3.formatPrefix(-1e-18).symbol, "a");
assert.equal(d3.formatPrefix(-1e-21).symbol, "z");
assert.equal(d3.formatPrefix(-1e-24).symbol, "y");
assert.equal(d3.formatPrefix(-1e-27).symbol, "y");
assert.equal(d3.formatPrefix(-1e00).symbol, "");
assert.equal(d3.formatPrefix(-1e03).symbol, "k");
assert.equal(d3.formatPrefix(-1e06).symbol, "M");
assert.equal(d3.formatPrefix(-1e09).symbol, "G");
assert.equal(d3.formatPrefix(-1e12).symbol, "T");
assert.equal(d3.formatPrefix(-1e15).symbol, "P");
assert.equal(d3.formatPrefix(-1e18).symbol, "E");
assert.equal(d3.formatPrefix(-1e21).symbol, "Z");
assert.equal(d3.formatPrefix(-1e24).symbol, "Y");
assert.equal(d3.formatPrefix(-1e27).symbol, "Y");
"determines the appropriate prefix for negative numbers": function(prefix) {
assert.equal(prefix(-0).symbol, "");
assert.equal(prefix(-1e-00).symbol, "");
assert.equal(prefix(-1e-03).symbol, "m");
assert.equal(prefix(-1e-06).symbol, "µ");
assert.equal(prefix(-1e-09).symbol, "n");
assert.equal(prefix(-1e-12).symbol, "p");
assert.equal(prefix(-1e-15).symbol, "f");
assert.equal(prefix(-1e-18).symbol, "a");
assert.equal(prefix(-1e-21).symbol, "z");
assert.equal(prefix(-1e-24).symbol, "y");
assert.equal(prefix(-1e-27).symbol, "y");
assert.equal(prefix(-1e00).symbol, "");
assert.equal(prefix(-1e03).symbol, "k");
assert.equal(prefix(-1e06).symbol, "M");
assert.equal(prefix(-1e09).symbol, "G");
assert.equal(prefix(-1e12).symbol, "T");
assert.equal(prefix(-1e15).symbol, "P");
assert.equal(prefix(-1e18).symbol, "E");
assert.equal(prefix(-1e21).symbol, "Z");
assert.equal(prefix(-1e24).symbol, "Y");
assert.equal(prefix(-1e27).symbol, "Y");
},
"considers the effect of rounding based on precision": function(d3) {
assert.equal(d3.formatPrefix(999.5000000, 4).symbol, "");
assert.equal(d3.formatPrefix(999.5000000, 3).symbol, "k");
assert.equal(d3.formatPrefix(995.0000000, 3).symbol, "");
assert.equal(d3.formatPrefix(995.0000000, 2).symbol, "k");
assert.equal(d3.formatPrefix(950.0000000, 2).symbol, "");
assert.equal(d3.formatPrefix(950.0000000, 1).symbol, "k");
assert.equal(d3.formatPrefix(0.000009995, 4).symbol, "µ");
assert.equal(d3.formatPrefix(0.000009995, 3).symbol, "m");
assert.equal(d3.formatPrefix(0.000009950, 3).symbol, "µ");
assert.equal(d3.formatPrefix(0.000009950, 2).symbol, "m");
assert.equal(d3.formatPrefix(0.000009500, 2).symbol, "µ");
assert.equal(d3.formatPrefix(0.000009500, 1).symbol, "m");
"considers the effect of rounding based on precision": function(prefix) {
assert.equal(prefix(999.5000000, 4).symbol, "");
assert.equal(prefix(999.5000000, 3).symbol, "k");
assert.equal(prefix(995.0000000, 3).symbol, "");
assert.equal(prefix(995.0000000, 2).symbol, "k");
assert.equal(prefix(950.0000000, 2).symbol, "");
assert.equal(prefix(950.0000000, 1).symbol, "k");
assert.equal(prefix(0.000009995, 4).symbol, "µ");
assert.equal(prefix(0.000009995, 3).symbol, "m");
assert.equal(prefix(0.000009950, 3).symbol, "µ");
assert.equal(prefix(0.000009950, 2).symbol, "m");
assert.equal(prefix(0.000009500, 2).symbol, "µ");
assert.equal(prefix(0.000009500, 1).symbol, "m");
}
}
});
......
......@@ -6,42 +6,42 @@ var suite = vows.describe("d3.requote");
suite.addBatch({
"requote": {
topic: load("format/requote"),
"quotes backslashes": function(d3) {
assert.equal(d3.requote("\\"), "\\\\");
topic: load("format/requote").expression("d3.requote"),
"quotes backslashes": function(requote) {
assert.equal(requote("\\"), "\\\\");
},
"quotes carets": function(d3) {
assert.equal(d3.requote("^"), "\\^");
"quotes carets": function(requote) {
assert.equal(requote("^"), "\\^");
},
"quotes dollar signs": function(d3) {
assert.equal(d3.requote("$"), "\\$");
"quotes dollar signs": function(requote) {
assert.equal(requote("$"), "\\$");
},
"quotes stars": function(d3) {
assert.equal(d3.requote("*"), "\\*");
"quotes stars": function(requote) {
assert.equal(requote("*"), "\\*");
},
"quotes plusses": function(d3) {
assert.equal(d3.requote("+"), "\\+");
"quotes plusses": function(requote) {
assert.equal(requote("+"), "\\+");
},
"quotes question marks": function(d3) {
assert.equal(d3.requote("?"), "\\?");
"quotes question marks": function(requote) {
assert.equal(requote("?"), "\\?");
},
"quotes periods": function(d3) {
assert.equal(d3.requote("."), "\\.");
"quotes periods": function(requote) {
assert.equal(requote("."), "\\.");
},
"quotes parentheses": function(d3) {
assert.equal(d3.requote("("), "\\(");
assert.equal(d3.requote(")"), "\\)");
"quotes parentheses": function(requote) {
assert.equal(requote("("), "\\(");
assert.equal(requote(")"), "\\)");
},
"quotes pipes": function(d3) {
assert.equal(d3.requote("|"), "\\|");
"quotes pipes": function(requote) {
assert.equal(requote("|"), "\\|");
},
"quotes curly braces": function(d3) {
assert.equal(d3.requote("{"), "\\{");
assert.equal(d3.requote("}"), "\\}");
"quotes curly braces": function(requote) {
assert.equal(requote("{"), "\\{");
assert.equal(requote("}"), "\\}");
},
"quotes square brackets": function(d3) {
assert.equal(d3.requote("["), "\\[");
assert.equal(d3.requote("]"), "\\]");
"quotes square brackets": function(requote) {
assert.equal(requote("["), "\\[");
assert.equal(requote("]"), "\\]");
}
}
});
......
......@@ -6,59 +6,59 @@ var suite = vows.describe("d3.round");
suite.addBatch({
"round": {
topic: load("format/round"),
"returns a number": function(d3) {
assert.isNumber(d3.round(42));
topic: load("format/round").expression("d3.round"),
"returns a number": function(round) {
assert.isNumber(round(42));
},
"returns zero for zero": function(d3) {
assert.equal(d3.round(0), 0);
"returns zero for zero": function(round) {
assert.equal(round(0), 0);
},
"ignores degenerate input": function(d3) {
assert.isNaN(d3.round(NaN));
assert.equal(d3.round(Infinity), Infinity);
assert.equal(d3.round(-Infinity), -Infinity);
"ignores degenerate input": function(round) {
assert.isNaN(round(NaN));
assert.equal(round(Infinity), Infinity);
assert.equal(round(-Infinity), -Infinity);
},
"returns integers by default": function(d3) {
assert.equal(d3.round(10.6), 11);
assert.equal(d3.round(10.4), 10);
assert.equal(d3.round(0.6), 1);
assert.equal(d3.round(0.4), 0);
assert.equal(d3.round(-0.6), -1);
assert.equal(d3.round(-0.4), 0);
assert.equal(d3.round(-10.6), -11);
assert.equal(d3.round(-10.4), -10);
"returns integers by default": function(round) {
assert.equal(round(10.6), 11);
assert.equal(round(10.4), 10);
assert.equal(round(0.6), 1);
assert.equal(round(0.4), 0);
assert.equal(round(-0.6), -1);
assert.equal(round(-0.4), 0);
assert.equal(round(-10.6), -11);
assert.equal(round(-10.4), -10);
},
"rounds to the specified decimal place": function(d3) {
assert.inDelta(d3.round(10.56, 1), 10.6, 1e-6);
assert.inDelta(d3.round(10.54, 1), 10.5, 1e-6);
assert.inDelta(d3.round(0.56, 1), 0.6, 1e-6);
assert.inDelta(d3.round(0.54, 1), 0.5, 1e-6);
assert.inDelta(d3.round(-0.56, 1), -0.6, 1e-6);
assert.inDelta(d3.round(-0.54, 1), -0.5, 1e-6);
assert.inDelta(d3.round(-10.56, 1), -10.6, 1e-6);
assert.inDelta(d3.round(-10.54, 1), -10.5, 1e-6);
assert.inDelta(d3.round(10.556, 2), 10.56, 1e-6);
assert.inDelta(d3.round(10.554, 2), 10.55, 1e-6);
assert.inDelta(d3.round(0.556, 2), 0.56, 1e-6);
assert.inDelta(d3.round(0.554, 2), 0.55, 1e-6);
assert.inDelta(d3.round(-0.556, 2), -0.56, 1e-6);
assert.inDelta(d3.round(-0.554, 2), -0.55, 1e-6);
assert.inDelta(d3.round(-10.556, 2), -10.56, 1e-6);
assert.inDelta(d3.round(-10.554, 2), -10.55, 1e-6);
"rounds to the specified decimal place": function(round) {
assert.inDelta(round(10.56, 1), 10.6, 1e-6);
assert.inDelta(round(10.54, 1), 10.5, 1e-6);
assert.inDelta(round(0.56, 1), 0.6, 1e-6);
assert.inDelta(round(0.54, 1), 0.5, 1e-6);
assert.inDelta(round(-0.56, 1), -0.6, 1e-6);
assert.inDelta(round(-0.54, 1), -0.5, 1e-6);
assert.inDelta(round(-10.56, 1), -10.6, 1e-6);
assert.inDelta(round(-10.54, 1), -10.5, 1e-6);
assert.inDelta(round(10.556, 2), 10.56, 1e-6);
assert.inDelta(round(10.554, 2), 10.55, 1e-6);
assert.inDelta(round(0.556, 2), 0.56, 1e-6);
assert.inDelta(round(0.554, 2), 0.55, 1e-6);
assert.inDelta(round(-0.556, 2), -0.56, 1e-6);
assert.inDelta(round(-0.554, 2), -0.55, 1e-6);
assert.inDelta(round(-10.556, 2), -10.56, 1e-6);
assert.inDelta(round(-10.554, 2), -10.55, 1e-6);
},
"rounds to the specified significant digits": function(d3) {
assert.equal(d3.round(123.45, -1), 120);
assert.equal(d3.round(345.67, -1), 350);
assert.equal(d3.round(-123.45, -1), -120);
assert.equal(d3.round(-345.67, -1), -350);
assert.equal(d3.round(123.45, -2), 100);
assert.equal(d3.round(456.78, -2), 500);
assert.equal(d3.round(-123.45, -2), -100);
assert.equal(d3.round(-456.78, -2), -500);
assert.equal(d3.round(123.45, -3), 0);
assert.equal(d3.round(567.89, -3), 1000);
assert.equal(d3.round(-123.45, -3), 0);
assert.equal(d3.round(-567.89, -3), -1000);
"rounds to the specified significant digits": function(round) {
assert.equal(round(123.45, -1), 120);
assert.equal(round(345.67, -1), 350);
assert.equal(round(-123.45, -1), -120);
assert.equal(round(-345.67, -1), -350);
assert.equal(round(123.45, -2), 100);
assert.equal(round(456.78, -2), 500);
assert.equal(round(-123.45, -2), -100);
assert.equal(round(-456.78, -2), -500);
assert.equal(round(123.45, -3), 0);
assert.equal(round(567.89, -3), 1000);
assert.equal(round(-123.45, -3), 0);
assert.equal(round(-567.89, -3), -1000);
}
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment