-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gradient builder performance adjustments (#79)
* Gradient builder performance adjustments, unit tests fixes * Fix unit test name * Update Xamarin.Forms dependency where HSL bug is fixed
- Loading branch information
1 parent
74d5420
commit 0914aae
Showing
11 changed files
with
191 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Xamarin.Forms; | ||
using Xunit; | ||
|
||
namespace MagicGradients.Tests | ||
{ | ||
public class GradientBuilderTestCases : TheoryData<GradientBuilderTestCase> | ||
{ | ||
public GradientBuilderTestCases() | ||
{ | ||
Add(new LinearTestCase()); | ||
Add(new RadialTestCase()); | ||
} | ||
} | ||
|
||
public abstract class GradientBuilderTestCase | ||
{ | ||
public abstract void AddGradient(GradientBuilder builder); | ||
} | ||
|
||
public class LinearTestCase : GradientBuilderTestCase | ||
{ | ||
public override void AddGradient(GradientBuilder builder) | ||
{ | ||
builder.AddLinearGradient(45); | ||
} | ||
} | ||
|
||
public class RadialTestCase : GradientBuilderTestCase | ||
{ | ||
public override void AddGradient(GradientBuilder builder) | ||
{ | ||
builder.AddRadialGradient( | ||
new Point(0.5, 0.5), | ||
RadialGradientShape.Circle, | ||
RadialGradientSize.ClosestSide); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using Xamarin.Forms; | ||
using Xunit; | ||
|
||
namespace MagicGradients.Tests | ||
{ | ||
public class GradientBuilderTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(GradientBuilderTestCases))] | ||
public void AddGradient_AndStops_SingleGradientWithStops(GradientBuilderTestCase testCase) | ||
{ | ||
// Arrange | ||
var builder = new GradientBuilder(); | ||
|
||
// Act | ||
testCase.AddGradient(builder); | ||
builder.AddStop(Color.White); | ||
builder.AddStop(Color.Black); | ||
|
||
var gradients = builder.Build(); | ||
|
||
// Assert | ||
using (new AssertionScope()) | ||
{ | ||
gradients.Should().HaveCount(1); | ||
gradients[0].Stops.Should().HaveCount(2); | ||
} | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(GradientBuilderTestCases))] | ||
public void AddStops_AndGradient_AndStops_TwoGradientsWithStops(GradientBuilderTestCase testCase) | ||
{ | ||
// Arrange | ||
var builder = new GradientBuilder(); | ||
|
||
// Act | ||
builder.AddStop(Color.Red); | ||
testCase.AddGradient(builder); | ||
builder.AddStop(Color.White); | ||
builder.AddStop(Color.Black); | ||
|
||
var gradients = builder.Build(); | ||
|
||
// Assert | ||
using (new AssertionScope()) | ||
{ | ||
gradients.Should().HaveCount(2); | ||
gradients[0].Stops.Should().HaveCount(1); | ||
gradients[1].Stops.Should().HaveCount(2); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void AddOnlyStops_DefaultGradientWithStops() | ||
{ | ||
// Arrange | ||
var builder = new GradientBuilder(); | ||
|
||
// Act | ||
builder.AddStop(Color.White); | ||
builder.AddStop(Color.Black); | ||
|
||
var gradients = builder.Build(); | ||
|
||
// Assert | ||
using (new AssertionScope()) | ||
{ | ||
gradients.Should().HaveCount(1); | ||
gradients[0].Should().BeOfType<LinearGradient>(); | ||
gradients[0].Stops.Should().HaveCount(2); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters