Sha256: cb9ca9f396edef651e0bffb5066422edd3671df326a1ae841434298c8fbae092

Contents?: true

Size: 1.87 KB

Versions: 4

Compression:

Stored size: 1.87 KB

Contents

var vows = require("vows"),
    _ = require("../../"),
    load = require("../load"),
    assert = require("../assert");

var suite = vows.describe("d3.max");

suite.addBatch({
  "max": {
    topic: load("arrays/max").expression("d3.max"),
    "returns the greatest numeric value for numbers": function(max) {
      assert.equal(max([1]), 1);
      assert.equal(max([5, 1, 2, 3, 4]), 5);
      assert.equal(max([20, 3]), 20);
      assert.equal(max([3, 20]), 20);
    },
    "returns the greatest lexicographic value for strings": function(max) {
      assert.equal(max(["c", "a", "b"]), "c");
      assert.equal(max(["20", "3"]), "3");
      assert.equal(max(["3", "20"]), "3");
    },
    "ignores null, undefined and NaN": function(max) {
      var o = {valueOf: function() { return NaN; }};
      assert.equal(max([NaN, 1, 2, 3, 4, 5]), 5);
      assert.equal(max([o, 1, 2, 3, 4, 5]), 5);
      assert.equal(max([1, 2, 3, 4, 5, NaN]), 5);
      assert.equal(max([1, 2, 3, 4, 5, o]), 5);
      assert.equal(max([10, null, 3, undefined, 5, NaN]), 10);
      assert.equal(max([-1, null, -3, undefined, -5, NaN]), -1);
    },
    "compares heterogenous types as numbers": function(max) {
      assert.strictEqual(max([20, "3"]), 20);
      assert.strictEqual(max(["20", 3]), "20");
      assert.strictEqual(max([3, "20"]), "20");
      assert.strictEqual(max(["3", 20]), 20);
    },
    "returns undefined for empty array": function(max) {
      assert.isUndefined(max([]));
      assert.isUndefined(max([null]));
      assert.isUndefined(max([undefined]));
      assert.isUndefined(max([NaN]));
      assert.isUndefined(max([NaN, NaN]));
    },
    "applies the optional accessor function": function(max) {
      assert.equal(max([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { return _.min(d); }), 2);
      assert.equal(max([1, 2, 3, 4, 5], function(d, i) { return i; }), 4);
    }
  }
});

suite.export(module);

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
stripchart-0.0.3 lib/stripchart/public/components/d3/test/arrays/max-test.js
stripmem-0.0.3 lib/stripmem/public/components/d3/test/arrays/max-test.js
stripmem-0.0.2 lib/stripmem/public/components/d3/test/arrays/max-test.js
stripmem-0.0.1 lib/stripmem/public/components/d3/test/arrays/max-test.js