Skip to content

Commit 9c1229e

Browse files
authored
Merge pull request #5 from synercoder/bug-fixes/inverse-multiplication-operator
Bug fixes/inverse multiplication operator
2 parents a694558 + 08c6fe4 commit 9c1229e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/Synercoding.Primitives/UnitValue.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ public bool Equals(UnitValue other)
216216
public static UnitValue operator *(UnitValue a, double b)
217217
=> new UnitValue(a.Value * b, a.Unit);
218218

219+
/// <summary>
220+
/// Multiply a given <see cref="UnitValue"/> by a <see cref="double"/>
221+
/// </summary>
222+
/// <param name="a">The <see cref="UnitValue"/> to multiply</param>
223+
/// <param name="b">The <see cref="double"/> to multiply by</param>
224+
/// <returns>The result of the multiplication operation</returns>
225+
public static UnitValue operator *(double a, UnitValue b)
226+
=> new UnitValue(b.Value * a, b.Unit);
227+
219228
/// <summary>
220229
/// Divide a given <see cref="UnitValue"/> by another <see cref="UnitValue"/>
221230
/// </summary>

tests/Synercoding.Primitives.Tests/UnitValueTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,39 @@ public void FromDesignation_WithPixels_ThrowsArgumentException()
139139

140140
Assert.Throws<ArgumentException>(() => Unit.FromDesignation(designation));
141141
}
142+
143+
[Fact]
144+
public void MultiplicationOperator_WithLeftDouble_IsUnitValue()
145+
{
146+
// Arrange
147+
var left = 2d;
148+
var right = new UnitValue(5, Unit.Millimeters);
149+
var expected = new UnitValue(10, Unit.Millimeters);
150+
151+
// Act
152+
var result = left * right;
153+
154+
// Assert
155+
Assert.Equal(expected, result);
156+
Assert.Equal(expected.Value, result.Value);
157+
Assert.Equal(expected.Unit, result.Unit);
158+
}
159+
160+
[Fact]
161+
public void MultiplicationOperator_WithRightDouble_IsUnitValue()
162+
{
163+
// Arrange
164+
var left = new UnitValue(5, Unit.Millimeters);
165+
var right = 2d;
166+
var expected = new UnitValue(10, Unit.Millimeters);
167+
168+
// Act
169+
var result = left * right;
170+
171+
// Assert
172+
Assert.Equal(expected, result);
173+
Assert.Equal(expected.Value, result.Value);
174+
Assert.Equal(expected.Unit, result.Unit);
175+
}
142176
}
143177
}

0 commit comments

Comments
 (0)