Skip to content

Commit

Permalink
Merge pull request #139 from NN---/patch-2
Browse files Browse the repository at this point in the history
Add less than or equal and greater than or equal operators to ObjectIdentifier
  • Loading branch information
lextm authored Apr 8, 2023
2 parents f0e5d87 + 84305e9 commit 3e07e8b
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 @@ -451,6 +451,17 @@ public override int GetHashCode()
{
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 &gt;=.
Expand Down Expand Up @@ -485,6 +496,17 @@ public override int GetHashCode()
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 3e07e8b

Please sign in to comment.