-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: added unit tests for contour legend configuration class
- Loading branch information
1 parent
8811ab3
commit fed2968
Showing
3 changed files
with
611 additions
and
3 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
191 changes: 191 additions & 0 deletions
191
GsaGHTests/Helpers/GH/Legend/ContourLegendConfigurationTests.cs
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,191 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using GsaGH.Helpers.GH; | ||
|
||
using Xunit; | ||
|
||
namespace GsaGHTests.Helpers.GH.Legend { | ||
public class ContourLegendConfigurationTests { | ||
private readonly ContourLegendConfiguration legendConfiguration; | ||
|
||
public ContourLegendConfigurationTests() { | ||
legendConfiguration = new ContourLegendConfiguration(); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedShouldContainEmptyValues() { | ||
Assert.NotNull(legendConfiguration.Values); | ||
Assert.Empty(legendConfiguration.Values); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedShouldContainEmptyPositionYValues() { | ||
Assert.NotNull(legendConfiguration.ValuePositionsY); | ||
Assert.Empty(legendConfiguration.ValuePositionsY); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedIsVisibleShouldBeTrue() { | ||
Assert.True(legendConfiguration.IsVisible); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedScaleShouldBeSet() { | ||
double defaultScale = 1.0d; | ||
Assert.Equal(defaultScale, legendConfiguration.Scale); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedBitmapShouldBeSet() { | ||
Assert.NotNull(legendConfiguration.Bitmap); | ||
Assert.Equal(legendConfiguration.DefaultWidth, legendConfiguration.Bitmap.Width); | ||
Assert.Equal(legendConfiguration.DefaultHeight, legendConfiguration.Bitmap.Height); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialisedIsLegendDisplayableShouldReturnFalse() { | ||
Assert.False(legendConfiguration.IsLegendDisplayable()); | ||
} | ||
|
||
[Fact] | ||
public void SetTextValuesShouldThrowErrorWhenValuesAreNull() { | ||
Assert.Throws<ArgumentNullException>(() => legendConfiguration.SetTextValues(null)); | ||
} | ||
|
||
[Fact] | ||
public void SetTextValuesShouldSetValuesCorrectly() { | ||
var expectedValues = new List<string>() { | ||
"1", | ||
"2", | ||
}; | ||
legendConfiguration.SetTextValues(expectedValues); | ||
Assert.Equal(expectedValues.Count, legendConfiguration.Values.Count); | ||
Assert.Same(expectedValues, legendConfiguration.Values); | ||
} | ||
|
||
[Fact] | ||
public void SetTextValuesShouldSetEmptyList() { | ||
legendConfiguration.SetTextValues(new List<string>()); | ||
Assert.NotNull(legendConfiguration.Values); | ||
Assert.Empty(legendConfiguration.Values); | ||
} | ||
|
||
[Fact] | ||
public void SetValuePositionsYShouldThrowErrorWhenValuesAreNull() { | ||
Assert.Throws<ArgumentNullException>(() => legendConfiguration.SetValuePositionsY(null)); | ||
} | ||
|
||
[Fact] | ||
public void SetValuePositionsYShouldSetValuesCorrectly() { | ||
var expectedValues = new List<int>() { | ||
1, | ||
2, | ||
}; | ||
legendConfiguration.SetValuePositionsY(expectedValues); | ||
Assert.Equal(expectedValues.Count, legendConfiguration.ValuePositionsY.Count); | ||
Assert.Same(expectedValues, legendConfiguration.ValuePositionsY); | ||
} | ||
|
||
[Fact] | ||
public void SetValuePositionsYShouldSetEmptyList() { | ||
legendConfiguration.SetValuePositionsY(new List<int>()); | ||
Assert.NotNull(legendConfiguration.ValuePositionsY); | ||
Assert.Empty(legendConfiguration.ValuePositionsY); | ||
} | ||
|
||
[Fact] | ||
public void SetScaleShouldThrowErrorWhenScaleIsLessThan0() { | ||
Assert.Throws<ArgumentOutOfRangeException>(() => legendConfiguration.SetLegendScale(-1)); | ||
} | ||
|
||
[Fact] | ||
public void SetScaleShouldThrowErrorWhenScaleIsEqual0() { | ||
Assert.Throws<ArgumentOutOfRangeException>(() => legendConfiguration.SetLegendScale(0)); | ||
} | ||
|
||
[Fact] | ||
public void SetScaleShouldSetScaleCorrectly() { | ||
const double expectedScale = 1.5; | ||
legendConfiguration.SetLegendScale(expectedScale); | ||
Assert.Equal(expectedScale, legendConfiguration.Scale); | ||
} | ||
|
||
[Fact] | ||
public void SetScaleShouldResizeBitmapCorrectly() { | ||
const double expectedScale = 1.5; | ||
int expectedWidth = (int)(expectedScale * legendConfiguration.DefaultWidth); | ||
int expectedHeight = (int)(expectedScale * legendConfiguration.DefaultHeight); | ||
legendConfiguration.SetLegendScale(expectedScale); | ||
Assert.Equal(expectedHeight, legendConfiguration.Bitmap.Height); | ||
Assert.Equal(expectedWidth, legendConfiguration.Bitmap.Width); | ||
} | ||
|
||
[Fact] | ||
public void ToggleLegendVisibilityWorksCorrectly() { | ||
Assert.False(legendConfiguration.ToggleLegendVisibility()); | ||
Assert.True(legendConfiguration.ToggleLegendVisibility()); | ||
} | ||
|
||
[Fact] | ||
public void IsLegendDisplayableWillReturnTrueIfLegendIsVisibleAndHasValues() { | ||
Assert.False(legendConfiguration.IsLegendDisplayable()); | ||
legendConfiguration.SetTextValues(new List<string>() { | ||
"1", | ||
}); | ||
legendConfiguration.SetValuePositionsY(new List<int>() { | ||
1, | ||
}); | ||
Assert.True(legendConfiguration.IsLegendDisplayable()); | ||
} | ||
|
||
[Fact] | ||
public void IsLegendDisplayableWillReturnFalseIfLegendIsNotVisibleButHasValues() { | ||
Assert.False(legendConfiguration.IsLegendDisplayable()); | ||
legendConfiguration.ToggleLegendVisibility(); | ||
legendConfiguration.SetTextValues(new List<string>() { | ||
"1", | ||
}); | ||
legendConfiguration.SetValuePositionsY(new List<int>() { | ||
1, | ||
}); | ||
Assert.False(legendConfiguration.IsLegendDisplayable()); | ||
} | ||
|
||
[Fact] | ||
public void IsLegendDisplayableWillReturnFalseIfLegendIsVisibleButHasNotValues() { | ||
legendConfiguration.SetValuePositionsY(new List<int>() { | ||
1, | ||
}); | ||
Assert.False(legendConfiguration.IsLegendDisplayable()); | ||
} | ||
|
||
[Fact] | ||
public void SerialiseWillThrowErrorWhenObjectIsNotSet() { | ||
Assert.Throws<ArgumentNullException>(() => legendConfiguration.SerializeLegendState(null)); | ||
} | ||
|
||
[Fact] | ||
public void DeserialiseWillThrowErrorWhenObjectIsNotSet() { | ||
Assert.Throws<ArgumentNullException>(() => legendConfiguration.DeserializeLegendState(null)); | ||
} | ||
|
||
[Fact] | ||
public void SerializeAndDeserializeLegendStateWorksCorrectly() { | ||
var writer = new MockWriter(); | ||
var reader = new MockReader(); | ||
|
||
legendConfiguration.SetLegendScale(2.0); | ||
legendConfiguration.ToggleLegendVisibility(); | ||
legendConfiguration.SerializeLegendState(writer); | ||
|
||
reader.Data = writer.Data; | ||
var deserializedConfig = new ContourLegendConfiguration(); | ||
deserializedConfig.DeserializeLegendState(reader); | ||
|
||
Assert.Equal(legendConfiguration.Scale, deserializedConfig.Scale); | ||
Assert.Equal(legendConfiguration.IsVisible, deserializedConfig.IsVisible); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.