toolkit/javascript/d3/test/core/max-test.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     1 require("../env");
       
     2 require("../../d3");
       
     3 
       
     4 var vows = require("vows"),
       
     5     assert = require("assert");
       
     6 
       
     7 var suite = vows.describe("d3.max");
       
     8 
       
     9 suite.addBatch({
       
    10   "max": {
       
    11     topic: function() {
       
    12       return d3.max;
       
    13     },
       
    14     "returns the greatest numeric value for numbers": function(max) {
       
    15       assert.equal(max([1]), 1);
       
    16       assert.equal(max([5, 1, 2, 3, 4]), 5);
       
    17       assert.equal(max([20, 3]), 20);
       
    18       assert.equal(max([3, 20]), 20);
       
    19     },
       
    20     "returns the greatest lexicographic value for strings": function(max) {
       
    21       assert.equal(max(["c", "a", "b"]), "c");
       
    22       assert.equal(max(["20", "3"]), "3");
       
    23       assert.equal(max(["3", "20"]), "3");
       
    24     },
       
    25     "ignores null, undefined and NaN": function(max) {
       
    26       assert.equal(max([NaN, 1, 2, 3, 4, 5]), 5);
       
    27       assert.equal(max([1, 2, 3, 4, 5, NaN]), 5);
       
    28       assert.equal(max([10, null, 3, undefined, 5, NaN]), 10);
       
    29       assert.equal(max([-1, null, -3, undefined, -5, NaN]), -1);
       
    30     },
       
    31     "compares heterogenous types as numbers": function(max) {
       
    32       assert.strictEqual(max([20, "3"]), 20);
       
    33       assert.strictEqual(max(["20", 3]), "20");
       
    34       assert.strictEqual(max([3, "20"]), "20");
       
    35       assert.strictEqual(max(["3", 20]), 20);
       
    36     },
       
    37     "returns undefined for empty array": function(max) {
       
    38       assert.isUndefined(max([]));
       
    39       assert.isUndefined(max([null]));
       
    40       assert.isUndefined(max([undefined]));
       
    41       assert.isUndefined(max([NaN]));
       
    42       assert.isUndefined(max([NaN, NaN]));
       
    43     },
       
    44     "applies the optional accessor function": function(max) {
       
    45       assert.equal(d3.max([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { return d3.min(d); }), 2);
       
    46       assert.equal(d3.max([1, 2, 3, 4, 5], function(d, i) { return i; }), 4);
       
    47     }
       
    48   }
       
    49 });
       
    50 
       
    51 suite.export(module);