Skip to content

Instantly share code, notes, and snippets.

@greatseth
Created December 21, 2012 20:12
Show Gist options
  • Save greatseth/4355449 to your computer and use it in GitHub Desktop.
Save greatseth/4355449 to your computer and use it in GitHub Desktop.
define([
'shape-map/shape-map',
'underscore'
], function(module, _) {
var map;
beforeEach(function() {
map = new module.ShapeMap();
});
describe('module.ShapeMap', function() {
describe('getPolygonColor', function() {
var breakpoints = [0, 5, 10, 15, 49999];
var colors = ['#C0E1F2', '#77C1DB', '#1174B7', '#0C47AD', '#cccccc'];
var categoryNames = ['<5% ', '5-10%', '10-15%', '>15%', 'No data'];
describe('when the number of colors and breakpoints do not match', function() {
it('throws an error', function() {
var breaks = _.clone(breakpoints);
breaks.push(50000);
expect(function() {
map.getPolygonColor(breaks, colors, 0)
}).toThrow('number of breakpoints does not match colors');
});
});
describe('when a given value matches a breakpoint', function() {
it('returns the color at the same index as the breakpoint', function() {
expect(map.getPolygonColor(breakpoints, colors, 0)).toEqual(colors[0]);
expect(map.getPolygonColor(breakpoints, colors, 5)).toEqual(colors[1]);
expect(map.getPolygonColor(breakpoints, colors, 10)).toEqual(colors[2]);
expect(map.getPolygonColor(breakpoints, colors, 15)).toEqual(colors[3]);
expect(map.getPolygonColor(breakpoints, colors, 49999)).toEqual(colors[4]);
expect(map.getPolygonColor(breakpoints, colors, 50000)).toEqual(colors[4]);
});
});
describe('when a given value is between two breakpoints', function() {
it('returns the color at the same index as the next lowest breakpoint', function() {
expect(map.getPolygonColor(breakpoints, colors, 2)).toEqual(colors[0]);
expect(map.getPolygonColor(breakpoints, colors, 7.4)).toEqual(colors[1]);
expect(map.getPolygonColor(breakpoints, colors, 11.99)).toEqual(colors[2]);
expect(map.getPolygonColor(breakpoints, colors, 15000)).toEqual(colors[3]);
expect(map.getPolygonColor(breakpoints, colors, 500000)).toEqual(colors[4]);
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment