Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add equality operators for QgsRange
  • Loading branch information
nyalldawson committed Nov 25, 2020
1 parent 5ae0453 commit 752746d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/core/auto_generated/qgsrange.sip.in
Expand Up @@ -117,6 +117,10 @@ Returns ``True`` if this range overlaps another range.
.. seealso:: :py:func:`contains`
%End

bool operator==( const QgsRange<T> &other ) const;

bool operator!=( const QgsRange<T> &other ) const;

};


Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsrange.h
Expand Up @@ -167,6 +167,19 @@ class QgsRange
return false;
}

bool operator==( const QgsRange<T> &other ) const
{
return mLower == other.mLower &&
mUpper == other.mUpper &&
mIncludeLower == other.includeLower() &&
mIncludeUpper == other.includeUpper();
}

bool operator!=( const QgsRange<T> &other ) const
{
return ( ! operator==( other ) );
}

private:

T mLower;
Expand Down
14 changes: 14 additions & 0 deletions tests/src/python/test_qgsrange.py
Expand Up @@ -42,6 +42,13 @@ def testIsInfinite(self):
range2 = QgsIntRange(5, range.upper())
self.assertFalse(range2.isInfinite())

def testEquality(self):
self.assertEqual(QgsIntRange(1, 10), QgsIntRange(1, 10))
self.assertNotEqual(QgsIntRange(1, 10), QgsIntRange(1, 11))
self.assertNotEqual(QgsIntRange(1, 10), QgsIntRange(2, 10))
self.assertNotEqual(QgsIntRange(1, 10, False), QgsIntRange(1, 10))
self.assertNotEqual(QgsIntRange(1, 10, True, False), QgsIntRange(1, 10))

def testIsEmpty(self):
range = QgsIntRange(1, 1)
# should not be empty because 1 is included
Expand Down Expand Up @@ -212,6 +219,13 @@ def testGetters(self):
self.assertFalse(range.includeLower())
self.assertFalse(range.includeUpper())

def testEquality(self):
self.assertEqual(QgsDoubleRange(1, 10), QgsDoubleRange(1, 10))
self.assertNotEqual(QgsDoubleRange(1, 10), QgsDoubleRange(1, 11))
self.assertNotEqual(QgsDoubleRange(1, 10), QgsDoubleRange(2, 10))
self.assertNotEqual(QgsDoubleRange(1, 10, False), QgsDoubleRange(1, 10))
self.assertNotEqual(QgsDoubleRange(1, 10, True, False), QgsDoubleRange(1, 10))

def testIsInfinite(self):
range = QgsDoubleRange()
self.assertTrue(range.isInfinite())
Expand Down

0 comments on commit 752746d

Please sign in to comment.