1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | describe('Colors', function () { describe('Color Construction', function () { it('should have a color class', function () { expect(TestFlotr.Color).not.toBeUndefined(); }); it('should create a color', function () { var color = new TestFlotr.Color(0, 0, 0, 0); expect(color).toBeTruthy(); }); it('should have rgba attributes', function () { var color = new TestFlotr.Color(0, 0, 0, 0); expect(color.r).toEqual(0); expect(color.g).toEqual(0); expect(color.b).toEqual(0); expect(color.a).toEqual(1.0); }); }); describe('Color Manipulation', function () { var color; afterEach(function () { color = null; }); it('normalizes colors to upper bound', function () { color = new TestFlotr.Color(1000, 1000, 1000, 10); expect(color.r).toEqual(255); expect(color.g).toEqual(255); expect(color.b).toEqual(255); expect(color.a).toEqual(1.0); }); it('normalizes colors to lower bound', function () { color = new TestFlotr.Color(-1000, -1000, -1000, -10); expect(color.r).toEqual(0); expect(color.g).toEqual(0); expect(color.b).toEqual(0); expect(color.a).toEqual(0.0); }); it('scales colors', function () { color = new TestFlotr.Color(200, 200, 200, 1.0); color.scale(.5, .5, .5, .5); expect(color.r).toEqual(100); expect(color.g).toEqual(100); expect(color.b).toEqual(100); expect(color.a).toEqual(0.5); }); }); describe('Color Conversion', function () { var color; beforeEach(function () { color = new TestFlotr.Color(200, 200, 200, 1.0); }); afterEach(function () { color = null; }); it('should convert colors to strings, rgb', function () { expect(color.toString()).toEqual('rgb(200,200,200)'); }); it('should convert colors to strings, rgba', function () { color.a = 0.5; color.normalize(); expect(color.toString()).toEqual('rgba(200,200,200,0.5)'); }); it('should clone colors', function () { var color2 = color.clone(); expect(color.toString()).toEqual(color2.toString()); color.a = 0.5; color.normalize(); color2 = color.clone(); expect(color.toString()).toEqual(color2.toString()); }); }); }); |