Skip to content

Commit eb17bd0

Browse files
author
Lauren McCarthy
authored
Merge pull request #1463 from kadamwhite/add-color-tostring-mutation-unit-tests
Add unit tests for p5.Color.toString()
2 parents 0492e9e + 5e9d185 commit eb17bd0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/unit/color/p5.Color.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,28 @@ suite('p5.Color', function() {
780780
assert.deepEqual(c.levels, [100, 100, 100, 70]);
781781
});
782782
});
783+
784+
suite.only('p5.Color.prototype.toString', function() {
785+
var colorStr;
786+
787+
setup(function() {
788+
myp5.colorMode(myp5.RGB, 255, 255, 255, 255);
789+
c = myp5.color(128, 0, 128, 128);
790+
colorStr = c.toString();
791+
});
792+
793+
test('should generate (r,g,b,a) color string with 0-1 normalized alpha', function() {
794+
// Will not exactly equal 0.5 due to math: test "0.5" substr of
795+
// 'rgba(128,0,128,0.5...' instead of checking the entire string
796+
assert.equal(colorStr.substr(15, 3), '0.5');
797+
});
798+
799+
test('should consistently generate the same output', function() {
800+
assert.equal(colorStr, '' + c);
801+
});
802+
803+
test('should not mutate color levels', function() {
804+
assert.equal(c.levels, [128, 0, 128, 128]);
805+
});
806+
});
783807
});

0 commit comments

Comments
 (0)