From 84305e933fafa781f671bd8e217b4b1f91a94711 Mon Sep 17 00:00:00 2001 From: NN Date: Tue, 19 May 2020 20:30:30 +0300 Subject: [PATCH] Add less than or equal and greater than or equal operators to ObjectIdentifier. --- SharpSnmpLib/ObjectIdentifier.cs | 22 +++++++++++++++++++ .../Unit/ObjectIdentifierTestFixture.cs | 16 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/SharpSnmpLib/ObjectIdentifier.cs b/SharpSnmpLib/ObjectIdentifier.cs index 46cd44e88..5317bcb35 100644 --- a/SharpSnmpLib/ObjectIdentifier.cs +++ b/SharpSnmpLib/ObjectIdentifier.cs @@ -454,6 +454,17 @@ public int CompareTo(object obj) { return left.CompareTo(right) > 0; } + + /// + /// Implements the operator >=. + /// + /// The left. + /// The right. + /// The result of the operator. + public static bool operator >=(ObjectIdentifier left, ObjectIdentifier right) + { + return left.CompareTo(right) >= 0; + } /// /// Implements the operator <. @@ -466,6 +477,17 @@ public int CompareTo(object obj) return left.CompareTo(right) < 0; } + /// + /// Implements the operator <=. + /// + /// The left. + /// The right. + /// The result of the operator. + public static bool operator <=(ObjectIdentifier left, ObjectIdentifier right) + { + return left.CompareTo(right) <= 0; + } + /// /// The comparison. /// diff --git a/Tests/CSharpCore/Unit/ObjectIdentifierTestFixture.cs b/Tests/CSharpCore/Unit/ObjectIdentifierTestFixture.cs index 5e790bb8f..a9c12b17b 100644 --- a/Tests/CSharpCore/Unit/ObjectIdentifierTestFixture.cs +++ b/Tests/CSharpCore/Unit/ObjectIdentifierTestFixture.cs @@ -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() {