1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 tvcm.require('tvcm.color');
9 tvcm.unittest.testSuite('tvcm.color_test', function() {
10 test('fromRGB', function() {
11 var c = tvcm.Color.fromString('rgb(1, 2, 3)');
15 assertEquals(undefined, c.a);
18 test('FromRGBA', function() {
19 var c = tvcm.Color.fromString('rgba(1, 2, 3, 0.5)');
23 assertEquals(0.5, c.a);
26 test('fromHex', function() {
27 var c = tvcm.Color.fromString('#010203');
31 assertEquals(undefined, c.a);
34 test('toStringRGB', function() {
35 var c = new tvcm.Color(1, 2, 3);
36 assertEquals('rgb(1,2,3)', c.toString());
39 test('toStringRGBA', function() {
40 var c = new tvcm.Color(1, 2, 3, 0.5);
41 assertEquals('rgba(1,2,3,0.5)', c.toString());
44 test('lerpRGB', function() {
45 var a = new tvcm.Color(0, 127, 191);
46 var b = new tvcm.Color(255, 255, 255);
47 var x = tvcm.Color.lerpRGB(a, b, 0.25);
48 assertEquals(63, x.r);
49 assertEquals(159, x.g);
50 assertEquals(207, x.b);
53 test('lerpRGBA', function() {
54 var a = new tvcm.Color(0, 127, 191, 0.5);
55 var b = new tvcm.Color(255, 255, 255, 1);
56 var x = tvcm.Color.lerpRGBA(a, b, 0.25);
57 assertEquals(63, x.r);
58 assertEquals(159, x.g);
59 assertEquals(207, x.b);
60 assertEquals(0.625, x.a);