fixed #504 and updated tests

This commit is contained in:
Charlie Kindel
2020-06-09 14:51:02 -06:00
parent bfcbd3cb0d
commit d5dd29dbda
4 changed files with 371 additions and 80 deletions

View File

@@ -27,9 +27,37 @@ namespace Terminal.Gui {
int testVal = 5;
dim = Dim.Sized (testVal);
Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
testVal = -1;
dim = Dim.Sized (testVal);
Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
}
// TODO: Other Dim.Sized tests (e.g. Equal?)
[Fact]
public void Sized_Equals ()
{
int n1 = 0;
int n2 = 0;
var dim1 = Dim.Sized (n1);
var dim2 = Dim.Sized (n2);
Assert.Equal (dim1, dim2);
n1 = n2 = 1;
dim1 = Dim.Sized (n1);
dim2 = Dim.Sized (n2);
Assert.Equal (dim1, dim2);
n1 = n2 = -1;
dim1 = Dim.Sized (n1);
dim2 = Dim.Sized (n2);
Assert.Equal (dim1, dim2);
n1 = 0;
n2 = 1;
dim1 = Dim.Sized (n1);
dim2 = Dim.Sized (n2);
Assert.NotEqual (dim1, dim2);
}
[Fact]
public void Width_SetsValue ()
@@ -47,7 +75,46 @@ namespace Terminal.Gui {
Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
}
// TODO: Other Dim.Width tests (e.g. Equal?)
[Fact]
public void Width_Equals ()
{
var testRect1 = Rect.Empty;
var view1 = new View (testRect1);
var testRect2 = Rect.Empty;
var view2 = new View (testRect2);
var dim1 = Dim.Width (view1);
var dim2 = Dim.Width (view1);
// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
Assert.NotEqual (dim1, dim2);
dim2 = Dim.Width (view2);
Assert.NotEqual (dim1, dim2);
testRect1 = new Rect (0, 1, 2, 3);
view1 = new View (testRect1);
testRect2 = new Rect (0, 1, 2, 3);
dim1 = Dim.Width (view1);
dim2 = Dim.Width (view1);
// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
Assert.NotEqual (dim1, dim2);
testRect1 = new Rect (0, -1, -2, -3);
view1 = new View (testRect1);
testRect2 = new Rect (0, -1, -2, -3);
dim1 = Dim.Width (view1);
dim2 = Dim.Width (view1);
// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
Assert.NotEqual (dim1, dim2);
testRect1 = new Rect (0, -1, -2, -3);
view1 = new View (testRect1);
testRect2 = Rect.Empty;
view2 = new View (testRect2);
dim1 = Dim.Width (view1);
dim2 = Dim.Width (view2);
Assert.NotEqual (dim1, dim2);
}
[Fact]
public void Height_SetsValue ()
@@ -72,7 +139,7 @@ namespace Terminal.Gui {
{
var testMargin = 0;
var dim = Dim.Fill ();
Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString());
Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
testMargin = 0;
dim = Dim.Fill (testMargin);
@@ -85,7 +152,7 @@ namespace Terminal.Gui {
[Fact]
public void Fill_Equal()
public void Fill_Equal ()
{
var margin1 = 0;
var margin2 = 0;
@@ -99,19 +166,54 @@ namespace Terminal.Gui {
{
float f = 0;
var dim = Dim.Percent (f);
Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
f = 0.5F;
dim = Dim.Percent (f);
Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
f = 100;
dim = Dim.Percent (f);
Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
}
// TODO: Other Dim.Percent tests (e.g. Equal?)
[Fact]
public void Percent_Equals ()
{
float n1 = 0;
float n2 = 0;
var dim1 = Dim.Percent (n1);
var dim2 = Dim.Percent (n2);
Assert.Equal (dim1, dim2);
n1 = n2 = 1;
dim1 = Dim.Percent (n1);
dim2 = Dim.Percent (n2);
Assert.Equal (dim1, dim2);
n1 = n2 = 0.5f;
dim1 = Dim.Percent (n1);
dim2 = Dim.Percent (n2);
Assert.Equal (dim1, dim2);
n1 = n2 = 100f;
dim1 = Dim.Percent (n1);
dim2 = Dim.Percent (n2);
Assert.Equal (dim1, dim2);
n1 = 0;
n2 = 1;
dim1 = Dim.Percent (n1);
dim2 = Dim.Percent (n2);
Assert.NotEqual (dim1, dim2);
n1 = 0.5f;
n2 = 1.5f;
dim1 = Dim.Percent (n1);
dim2 = Dim.Percent (n2);
Assert.NotEqual (dim1, dim2);
}
[Fact]
public void Percent_ThrowsOnIvalid()
public void Percent_ThrowsOnIvalid ()
{
var dim = Dim.Percent (0);
Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));