Standardizing color ranges (see #129)

This commit is contained in:
Tim Schaub
2013-01-17 14:19:50 -07:00
parent b36eab1dfa
commit 10672ad303
6 changed files with 84 additions and 8 deletions

View File

@@ -72,6 +72,7 @@
<!-- include spec files here... -->
<script type="text/javascript" src="spec/ol/array.test.js"></script>
<script type="text/javascript" src="spec/ol/collection.test.js"></script>
<script type="text/javascript" src="spec/ol/color.test.js"></script>
<script type="text/javascript" src="spec/ol/extent.test.js"></script>
<script type="text/javascript" src="spec/ol/map.test.js"></script>
<script type="text/javascript" src="spec/ol/object.test.js"></script>

View File

@@ -0,0 +1,73 @@
describe('ol.Color', function() {
describe('constructor', function() {
it('limits r to 0-255', function() {
var c;
// legit r
c = new ol.Color(10.5, 11, 12, 0.5);
expect(c.r).toBe(10.5);
// under r
c = new ol.Color(-10, 11, 12, 0.5);
expect(c.r).toBe(0);
// over r
c = new ol.Color(300, 11, 12, 0.5);
expect(c.r).toBe(255);
});
it('limits g to 0-255', function() {
var c;
// legit g
c = new ol.Color(10, 11.5, 12, 0.5);
expect(c.g).toBe(11.5);
// under g
c = new ol.Color(10, -11, 12, 0.5);
expect(c.g).toBe(0);
// over g
c = new ol.Color(10, 275, 12, 0.5);
expect(c.g).toBe(255);
});
it('limits b to 0-255', function() {
var c;
// legit b
c = new ol.Color(10, 11, 12.5, 0.5);
expect(c.b).toBe(12.5);
// under b
c = new ol.Color(10, 11, -12, 0.5);
expect(c.b).toBe(0);
// over b
c = new ol.Color(10, 11, 500, 0.5);
expect(c.b).toBe(255);
});
it('limits 1 to 0-1', function() {
var c;
// legit a
c = new ol.Color(10, 11, 12, 0.5);
expect(c.a).toBe(0.5);
// under a
c = new ol.Color(10, 11, 12, -0.5);
expect(c.a).toBe(0);
// over a
c = new ol.Color(10, 11, 12, 2.5);
expect(c.a).toBe(1);
});
});
});
goog.require('ol.array');