Skip to content

Commit a694558

Browse files
authored
Merge pull request #4 from synercoder/features/equality-operators
Features/equality operators
2 parents 585cedd + 7839035 commit a694558

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

src/Synercoding.Primitives/Point.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,23 @@ public bool Equals(Point other)
8989
/// <inheritdoc />
9090
public override string ToString()
9191
=> $"X: {X}, Y: {Y}";
92+
93+
/// <summary>
94+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are equal.
95+
/// </summary>
96+
/// <param name="left">The first value to compare.</param>
97+
/// <param name="right">The second value to compare.</param>
98+
/// <returns>true if left and right are equal; otherwise, false.</returns>
99+
public static bool operator ==(Point left, Point right)
100+
=> left.Equals(right);
101+
102+
/// <summary>
103+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are not equal.
104+
/// </summary>
105+
/// <param name="left">The first value to compare.</param>
106+
/// <param name="right">The second value to compare.</param>
107+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
108+
public static bool operator !=(Point left, Point right)
109+
=> !( left == right );
92110
}
93111
}

src/Synercoding.Primitives/Rectangle.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,23 @@ public bool Equals(Rectangle other)
163163
/// <inheritdoc/>
164164
public override string ToString()
165165
=> $"LLX {LLX}, LLY {LLY}, URX {URX}, URY {URY}";
166+
167+
/// <summary>
168+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are equal.
169+
/// </summary>
170+
/// <param name="left">The first value to compare.</param>
171+
/// <param name="right">The second value to compare.</param>
172+
/// <returns>true if left and right are equal; otherwise, false.</returns>
173+
public static bool operator ==(Rectangle left, Rectangle right)
174+
=> left.Equals(right);
175+
176+
/// <summary>
177+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are not equal.
178+
/// </summary>
179+
/// <param name="left">The first value to compare.</param>
180+
/// <param name="right">The second value to compare.</param>
181+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
182+
public static bool operator !=(Rectangle left, Rectangle right)
183+
=> !( left == right );
166184
}
167185
}

src/Synercoding.Primitives/Size.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,23 @@ public bool Equals(Size other)
101101
/// <inheritdoc/>
102102
public override string ToString()
103103
=> $"W: {Width}, H: {Height}";
104+
105+
/// <summary>
106+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are equal.
107+
/// </summary>
108+
/// <param name="left">The first value to compare.</param>
109+
/// <param name="right">The second value to compare.</param>
110+
/// <returns>true if left and right are equal; otherwise, false.</returns>
111+
public static bool operator ==(Size left, Size right)
112+
=> left.Equals(right);
113+
114+
/// <summary>
115+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are not equal.
116+
/// </summary>
117+
/// <param name="left">The first value to compare.</param>
118+
/// <param name="right">The second value to compare.</param>
119+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
120+
public static bool operator !=(Size left, Size right)
121+
=> !( left == right );
104122
}
105123
}

src/Synercoding.Primitives/Spacing.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,23 @@ public bool Equals(Spacing other)
121121
&& a.Right == b.Right
122122
&& a.Bottom == b.Bottom;
123123
}
124+
125+
/// <summary>
126+
/// Returns a value that indicates whether two specified <see cref="Spacing"/> values are equal.
127+
/// </summary>
128+
/// <param name="left">The first value to compare.</param>
129+
/// <param name="right">The second value to compare.</param>
130+
/// <returns>true if left and right are equal; otherwise, false.</returns>
131+
public static bool operator ==(Spacing left, Spacing right)
132+
=> left.Equals(right);
133+
134+
/// <summary>
135+
/// Returns a value that indicates whether two specified <see cref="Spacing"/> values are not equal.
136+
/// </summary>
137+
/// <param name="left">The first value to compare.</param>
138+
/// <param name="right">The second value to compare.</param>
139+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
140+
public static bool operator !=(Spacing left, Spacing right)
141+
=> !( left == right );
124142
}
125143
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
3+
namespace Synercoding.Primitives.Tests
4+
{
5+
public class PointTests
6+
{
7+
[Fact]
8+
public void EqualityOperator_InchAndMillimeters_NotEqual()
9+
{
10+
// Arrange
11+
var mmPoint = new Point(1, 1, Unit.Millimeters);
12+
var inPoint = new Point(1, 1, Unit.Inches);
13+
14+
// Act
15+
var result = mmPoint == inPoint;
16+
17+
// Assert
18+
Assert.False(result);
19+
}
20+
21+
[Fact]
22+
public void EqualityOperator_InchAnd254Millimeters_AreEqual()
23+
{
24+
// Arrange
25+
var mmPoint = new Point(25.4, 25.4, Unit.Millimeters);
26+
var inPoint = new Point(1, 1, Unit.Inches);
27+
28+
// Act
29+
var result = mmPoint == inPoint;
30+
31+
// Assert
32+
Assert.True(result);
33+
}
34+
}
35+
}

tests/Synercoding.Primitives.Tests/RectangleTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,33 @@ public void Expand_Spacing_ResultsInLargerRectangle()
1919
// Assert
2020
Assert.Equal(expected, result);
2121
}
22+
23+
[Fact]
24+
public void EqualityOperator_InchAndMillimeters_NotEqual()
25+
{
26+
// Arrange
27+
var mmRectangle = new Rectangle(1, 1, 1, 1, Unit.Millimeters);
28+
var inRectangle = new Rectangle(1, 1, 1, 1, Unit.Inches);
29+
30+
// Act
31+
var result = mmRectangle == inRectangle;
32+
33+
// Assert
34+
Assert.False(result);
35+
}
36+
37+
[Fact]
38+
public void EqualityOperator_InchAnd254Millimeters_AreEqual()
39+
{
40+
// Arrange
41+
var mmRectangle = new Rectangle(25.4, 25.4, 25.4, 25.4, Unit.Millimeters);
42+
var inRectangle = new Rectangle(1, 1, 1, 1, Unit.Inches);
43+
44+
// Act
45+
var result = mmRectangle == inRectangle;
46+
47+
// Assert
48+
Assert.True(result);
49+
}
2250
}
2351
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
3+
namespace Synercoding.Primitives.Tests
4+
{
5+
public class SizeTests
6+
{
7+
[Fact]
8+
public void EqualityOperator_InchAndMillimeters_NotEqual()
9+
{
10+
// Arrange
11+
var mmSize = new Size(1, 1, Unit.Millimeters);
12+
var inSize = new Size(1, 1, Unit.Inches);
13+
14+
// Act
15+
var result = mmSize == inSize;
16+
17+
// Assert
18+
Assert.False(result);
19+
}
20+
21+
[Fact]
22+
public void EqualityOperator_InchAnd254Millimeters_AreEqual()
23+
{
24+
// Arrange
25+
var mmSize = new Size(25.4, 25.4, Unit.Millimeters);
26+
var inSize = new Size(1, 1, Unit.Inches);
27+
28+
// Act
29+
var result = mmSize == inSize;
30+
31+
// Assert
32+
Assert.True(result);
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
3+
namespace Synercoding.Primitives.Tests
4+
{
5+
public class SpacingTests
6+
{
7+
[Fact]
8+
public void EqualityOperator_InchAndMillimeters_NotEqual()
9+
{
10+
// Arrange
11+
var mmSpacing = new Spacing(1, 1, 1, 1, Unit.Millimeters);
12+
var inSpacing = new Spacing(1, 1, 1, 1, Unit.Inches);
13+
14+
// Act
15+
var result = mmSpacing == inSpacing;
16+
17+
// Assert
18+
Assert.False(result);
19+
}
20+
21+
[Fact]
22+
public void EqualityOperator_InchAnd254Millimeters_AreEqual()
23+
{
24+
// Arrange
25+
var mmSpacing = new Spacing(25.4, 25.4, 25.4, 25.4, Unit.Millimeters);
26+
var inSpacing = new Spacing(1, 1, 1, 1, Unit.Inches);
27+
28+
// Act
29+
var result = mmSpacing == inSpacing;
30+
31+
// Assert
32+
Assert.True(result);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)