public void BlendColor_ReturnsRatioBlendedColor() { // prereq IsValidColor_ExtensionReturnsAnswer(); // arrange Color left = new Color(0.1f, 0.7f, 0.4f, 0.5f); Color right = new Color(0.6f, 0.2f, 0.4f, 0.9f); float ratio = 0.1f, invRatio = 1 - ratio; Color expectedNoAlpha = new Color( left.r * ratio + right.r * invRatio, left.g * ratio + right.g * invRatio, left.b * ratio + right.b * invRatio, left.a); Color expectedYesAlpha = expectedNoAlpha; expectedYesAlpha.a = ratio * left.a + invRatio * right.a; // act Color blendNoAlpha = Palette.BlendColors(left, right, ratio); Color blendYesAlpha = Palette.BlendColors(left, right, ratio, true); // assert Assert.IsTrue(blendNoAlpha.IsValidColor(), TestHelper.ShowVariable("blend w/o alpha is valid: ", false)); Assert.AreEqual(expectedNoAlpha, blendNoAlpha, "no alpha: " + TestHelper.ShowVariables(expectedNoAlpha, blendNoAlpha)); Assert.IsTrue(blendYesAlpha.IsValidColor(), TestHelper.ShowVariable("blend w/ alpha is valid: ", false)); Assert.AreEqual(expectedYesAlpha, blendYesAlpha, "yes alpha: " + TestHelper.ShowVariables(expectedYesAlpha, blendYesAlpha)); }
public void AverageColors_ReturnsAveragedColors() { // prereq BlendColor_ReturnsRatioBlendedColor(); // arrange Color left = Color.green; Color right = Color.cyan; // act Color average = Palette.AverageColors(left, right); Color expected = Palette.BlendColors(left, right, 0.5f); // assert Assert.AreEqual(expected, average, TestHelper.LabelAs("left, right")); }
public void BlendColor_ReturnsDropBlendedColor() { // arrange Color left = Color.red; Color right = Palette.PastelYellow; int leftDrops = 5, rightDrops = 2; int totalDrops = leftDrops + rightDrops; // act Color blend = Palette.BlendColors(left, right, 5, 2); float r = left.r * (float)leftDrops / totalDrops + right.r * (float)rightDrops / totalDrops; float g = left.g * (float)leftDrops / totalDrops + right.g * (float)rightDrops / totalDrops; float b = left.b * (float)leftDrops / totalDrops + right.b * (float)rightDrops / totalDrops; // assert Assert.IsTrue(PMath.Approx(r, blend.r), "r: " + TestHelper.ShowVariables(r, blend.r)); Assert.IsTrue(PMath.Approx(g, blend.g), "g: " + TestHelper.ShowVariables(g, blend.g)); Assert.IsTrue(PMath.Approx(b, blend.b), "b: " + TestHelper.ShowVariables(b, blend.b)); }