Skip to content

Commit

Permalink
Add less than or equal and greater than or equal operators to ObjectI…
Browse files Browse the repository at this point in the history
…dentifier.
  • Loading branch information
NN--- authored and Konstantin Sharon committed May 19, 2020
1 parent 1d2b6b0 commit 84305e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions SharpSnmpLib/ObjectIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ public int CompareTo(object obj)
{
return left.CompareTo(right) > 0;
}

/// <summary>
/// Implements the operator &gt;=.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator >=(ObjectIdentifier left, ObjectIdentifier right)
{
return left.CompareTo(right) >= 0;
}

/// <summary>
/// Implements the operator &lt;.
Expand All @@ -466,6 +477,17 @@ public int CompareTo(object obj)
return left.CompareTo(right) < 0;
}

/// <summary>
/// Implements the operator &lt;=.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator <=(ObjectIdentifier left, ObjectIdentifier right)
{
return left.CompareTo(right) <= 0;
}

/// <summary>
/// The comparison.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Tests/CSharpCore/Unit/ObjectIdentifierTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ public void TestGreaterThan()
Assert.True(new ObjectIdentifier("0.0").Compare(new ObjectIdentifier("1.1")) < 0);
}

[Fact]
public void TestGreaterThanOrEqual()
{
Assert.True(new ObjectIdentifier("1.1") >= new ObjectIdentifier("0.0"));
Assert.True(new ObjectIdentifier("1.1") >= new ObjectIdentifier("1.1"));
Assert.True(new ObjectIdentifier("0.0.0") >= new ObjectIdentifier("0.0"));
}

[Fact]
public void TestLessThanOrEqual()
{
Assert.True(new ObjectIdentifier("0.0") <= new ObjectIdentifier("1.1"));
Assert.True(new ObjectIdentifier("1.1") <= new ObjectIdentifier("1.1"));
Assert.True(new ObjectIdentifier("0.0") <= new ObjectIdentifier("0.0.0"));
}

[Fact]
public void TestConversion()
{
Expand Down

0 comments on commit 84305e9

Please sign in to comment.