Skip to content

Commit

Permalink
fixed color tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codescapade committed Sep 18, 2024
1 parent e843bf5 commit fba48a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/jume/graphics/Color.hx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Color {
* @param blue The blue channel value (0 - 1).
* @param alpha The alpha channel value (0 - 1).
*/
public function new(red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0) {
public function new(red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0) {
set(red, green, blue, alpha);
}

Expand Down
71 changes: 13 additions & 58 deletions tests/unit/jume/graphics/ColorTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ class ColorTests extends Test {
Assert.equals(0, color.blue);
Assert.equals(1, color.alpha);

final color2 = new Color({
red: 0.3,
green: 0.4,
blue: 0.5,
alpha: 0.6
});
final color2 = new Color(0.3, 0.4, 0.5, 0.6);

Assert.equals(0.3, color2.red);
Assert.equals(0.4, color2.green);
Expand All @@ -26,20 +21,15 @@ class ColorTests extends Test {
}

function testFromBytes() {
final color = Color.fromBytes({ red: 100, green: 150, blue: 255 });
final color = Color.fromBytes(100, 150, 255);

Assert.floatEquals(0.39215, color.red);
Assert.floatEquals(0.58823, color.green);
Assert.floatEquals(1, color.blue);
Assert.floatEquals(1, color.alpha);

final color2 = new Color();
final color3 = Color.fromBytes({
red: 100,
green: 150,
blue: 255,
alpha: 100
}, color2);
final color3 = Color.fromBytes(100, 150, 255, 100, color2);

Assert.equals(color2, color3);
Assert.floatEquals(0.39215, color2.red);
Expand Down Expand Up @@ -71,19 +61,9 @@ class ColorTests extends Test {
}

function testInterpolate() {
final color1 = new Color({
red: 0,
green: 0,
blue: 0,
alpha: 0
});

final color2 = new Color({
red: 1,
green: 1,
blue: 1,
alpha: 1
});
final color1 = new Color(0, 0, 0, 0);

final color2 = new Color(1, 1, 1, 1);

final result = Color.interpolate(color1, color2, 0);

Expand Down Expand Up @@ -115,26 +95,16 @@ class ColorTests extends Test {
}

function testSet() {
final color = new Color({
red: 0.2,
green: 0.3,
blue: 0.4,
alpha: 0.5
});

color.set({
red: 0.5,
green: 0.2,
blue: 0.8,
alpha: 0.9
});
final color = new Color(0.2, 0.3, 0.4, 0.5);

color.set(0.5, 0.2, 0.8, 0.9);

Assert.floatEquals(0.5, color.red);
Assert.floatEquals(0.2, color.green);
Assert.floatEquals(0.8, color.blue);
Assert.floatEquals(0.9, color.alpha);

color.set({});
color.set(0, 0, 0);

Assert.floatEquals(0, color.red);
Assert.floatEquals(0, color.green);
Expand All @@ -145,12 +115,7 @@ class ColorTests extends Test {
function testClone() {
final out = new Color();

final source = new Color({
red: 0.5,
green: 0.2,
blue: 0.8,
alpha: 0.9
});
final source = new Color(0.5, 0.2, 0.8, 0.9);
final color = source.clone(out);

Assert.equals(out, color);
Expand All @@ -161,12 +126,7 @@ class ColorTests extends Test {
}

function testCopyfrom() {
final source = new Color({
red: 0.5,
green: 0.2,
blue: 0.8,
alpha: 0.9
});
final source = new Color(0.5, 0.2, 0.8, 0.9);
final color = new Color();
color.copyFrom(source);

Expand All @@ -177,12 +137,7 @@ class ColorTests extends Test {
}

function testToString() {
final color = new Color({
red: 0.2,
green: 0.5,
blue: 0.55,
alpha: 1
});
final color = new Color(0.2, 0.5, 0.55, 1);
final stringColor = color.toString();

Assert.equals('{ r: 0.2, g: 0.5, b: 0.55, a: 1 }', stringColor);
Expand Down

0 comments on commit fba48a5

Please sign in to comment.