Skip to content

Commit

Permalink
Fix generated equals method
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
sean-mcl committed Jul 7, 2020
1 parent 5c0fc87 commit 42b14c8
Show file tree
Hide file tree
Showing 850 changed files with 14,957 additions and 14,870 deletions.
4 changes: 2 additions & 2 deletions Plotly.Blazor.Generator/Templates/Class/Class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace {{Namespace}}
{{#Properties}}
{{^IsList}}
(
{{PropertyName}} == other.{{PropertyName}} &&
{{PropertyName}} != null && other.{{PropertyName}} != null &&
{{PropertyName}} == other.{{PropertyName}} ||
{{PropertyName}} != null &&
{{PropertyName}}.Equals(other.{{PropertyName}})
){{#HasMore}} && {{/HasMore}}{{^HasMore}};{{/HasMore}}
{{/IsList}}
Expand Down
77 changes: 77 additions & 0 deletions Plotly.Blazor.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.Text.Json;
using NUnit.Framework;
using Plotly.Blazor.Traces;
using Plotly.Blazor.Traces.ScatterLib;
using Plotly.Blazor.Traces.ScatterLib.ErrorXLib;

namespace Plotly.Blazor.Tests
{
public class GeneratorTests
{
/// <summary>
/// Defines the test method EqualsMethodTest.
/// </summary>
[Test]
public void EqualsMethodTest()
{
var referenceScatter = new Scatter
{
ClipOnAxis = true,
DX = new decimal(1.23),
Fill = FillEnum.ToNext,
HoverTemplateArray = new List<string> {"123", "456"},
CustomDataSrc = "123",
ErrorX = new ErrorX
{
CopyYStyle = true,
Array = new List<object>(),
Type = TypeEnum.Constant
}
};

var equalScatter = new Scatter
{
ClipOnAxis = true,
DX = new decimal(1.23),
Fill = FillEnum.ToNext,
HoverTemplateArray = new List<string> {"123", "456"},
CustomDataSrc = "123",
ErrorX = new ErrorX
{
CopyYStyle = true,
Array = new List<object>(),
Type = TypeEnum.Constant
}
};

var notEqualScatter = new Scatter
{
ClipOnAxis = null,
DX = new decimal(1.23),
Fill = FillEnum.ToNext,
HoverTemplateArray = new List<string> {"123", "456"},
CustomDataSrc = "123",
ErrorX = new ErrorX
{
CopyYStyle = true,
Array = new List<object>(),
Type = TypeEnum.Constant
}
};

Assert.IsFalse(referenceScatter.Equals(null));

Assert.IsTrue(referenceScatter.Equals(equalScatter));
Assert.IsTrue(equalScatter.Equals(referenceScatter));
Assert.IsTrue(referenceScatter == equalScatter);
Assert.IsFalse(referenceScatter != equalScatter);

Assert.IsFalse(referenceScatter.Equals(notEqualScatter));
Assert.IsFalse(notEqualScatter.Equals(referenceScatter));
Assert.IsFalse(referenceScatter == notEqualScatter);
Assert.IsTrue(referenceScatter != notEqualScatter);
}

}
}
20 changes: 10 additions & 10 deletions Plotly.Blazor/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ public bool Equals([AllowNull] Animation other)

return
(
Mode == other.Mode &&
Mode != null && other.Mode != null &&
Mode == other.Mode ||
Mode != null &&
Mode.Equals(other.Mode)
) &&
(
Direction == other.Direction &&
Direction != null && other.Direction != null &&
Direction == other.Direction ||
Direction != null &&
Direction.Equals(other.Direction)
) &&
(
FromCurrent == other.FromCurrent &&
FromCurrent != null && other.FromCurrent != null &&
FromCurrent == other.FromCurrent ||
FromCurrent != null &&
FromCurrent.Equals(other.FromCurrent)
) &&
(
Frame == other.Frame &&
Frame != null && other.Frame != null &&
Frame == other.Frame ||
Frame != null &&
Frame.Equals(other.Frame)
) &&
(
Transition == other.Transition &&
Transition != null && other.Transition != null &&
Transition == other.Transition ||
Transition != null &&
Transition.Equals(other.Transition)
);
}
Expand Down
8 changes: 4 additions & 4 deletions Plotly.Blazor/AnimationLib/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public bool Equals([AllowNull] Frame other)

return
(
Duration == other.Duration &&
Duration != null && other.Duration != null &&
Duration == other.Duration ||
Duration != null &&
Duration.Equals(other.Duration)
) &&
(
Redraw == other.Redraw &&
Redraw != null && other.Redraw != null &&
Redraw == other.Redraw ||
Redraw != null &&
Redraw.Equals(other.Redraw)
);
}
Expand Down
12 changes: 6 additions & 6 deletions Plotly.Blazor/AnimationLib/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ public bool Equals([AllowNull] Transition other)

return
(
Duration == other.Duration &&
Duration != null && other.Duration != null &&
Duration == other.Duration ||
Duration != null &&
Duration.Equals(other.Duration)
) &&
(
Easing == other.Easing &&
Easing != null && other.Easing != null &&
Easing == other.Easing ||
Easing != null &&
Easing.Equals(other.Easing)
) &&
(
Ordering == other.Ordering &&
Ordering != null && other.Ordering != null &&
Ordering == other.Ordering ||
Ordering != null &&
Ordering.Equals(other.Ordering)
);
}
Expand Down
Loading

0 comments on commit 42b14c8

Please sign in to comment.