Sha256: 11d2875fbe1c07e1343f0ec44511bf156c46729d85dbf9013070a32790de0e66

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

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

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

suite.addBatch({
  "median": {
    topic: load("arrays/median").expression("d3.median"),
    "returns the median value for numbers": function(median) {
      assert.equal(median([1]), 1);
      assert.equal(median([5, 1, 2, 3, 4]), 3);
      assert.equal(median([20, 3]), 11.5);
      assert.equal(median([3, 20]), 11.5);
    },
    "ignores null, undefined and NaN": function(median) {
      assert.equal(median([NaN, 1, 2, 3, 4, 5]), 3);
      assert.equal(median([1, 2, 3, 4, 5, NaN]), 3);
      assert.equal(median([10, null, 3, undefined, 5, NaN]), 5);
    },
    "can handle large numbers without overflowing": function(median) {
      assert.equal(median([Number.MAX_VALUE, Number.MAX_VALUE]), Number.MAX_VALUE);
      assert.equal(median([-Number.MAX_VALUE, -Number.MAX_VALUE]), -Number.MAX_VALUE);
    },
    "returns undefined for empty array": function(median) {
      assert.isUndefined(median([]));
      assert.isUndefined(median([null]));
      assert.isUndefined(median([undefined]));
      assert.isUndefined(median([NaN]));
      assert.isUndefined(median([NaN, NaN]));
    },
    "applies the optional accessor function": function(median) {
      assert.equal(median([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { return median(d); }), 4.5);
      assert.equal(median([1, 2, 3, 4, 5], function(d, i) { return i; }), 2);
    }
  }
});

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/median-test.js
stripmem-0.0.3 lib/stripmem/public/components/d3/test/arrays/median-test.js
stripmem-0.0.2 lib/stripmem/public/components/d3/test/arrays/median-test.js
stripmem-0.0.1 lib/stripmem/public/components/d3/test/arrays/median-test.js