|
| 1 | +/*************************************************************************** |
| 2 | + testqgsrange.cpp |
| 3 | + ------------------- |
| 4 | + Date : March 2021 |
| 5 | + Copyright : (C) 2021 Nyall Dawson |
| 6 | + Email : nyall dot dawson at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | +#include "qgstest.h" |
| 16 | +#include <QObject> |
| 17 | + |
| 18 | +#include "qgsrange.h" |
| 19 | + |
| 20 | +class TestQgsRange: public QObject |
| 21 | +{ |
| 22 | + Q_OBJECT |
| 23 | + |
| 24 | + private slots: |
| 25 | + void initTestCase();// will be called before the first testfunction is executed. |
| 26 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 27 | + void init();// will be called before each testfunction is executed. |
| 28 | + void cleanup();// will be called after every testfunction. |
| 29 | + void testMergeRangesDate(); |
| 30 | + void testMergeRangesDateTime(); |
| 31 | + |
| 32 | + private: |
| 33 | + |
| 34 | +}; |
| 35 | + |
| 36 | +void TestQgsRange::initTestCase() |
| 37 | +{ |
| 38 | +} |
| 39 | + |
| 40 | +void TestQgsRange::cleanupTestCase() |
| 41 | +{ |
| 42 | +} |
| 43 | + |
| 44 | +void TestQgsRange::init() |
| 45 | +{ |
| 46 | + |
| 47 | +} |
| 48 | + |
| 49 | +void TestQgsRange::cleanup() |
| 50 | +{ |
| 51 | + |
| 52 | +} |
| 53 | + |
| 54 | +void TestQgsRange::testMergeRangesDate() |
| 55 | +{ |
| 56 | + QList< QgsDateRange > ranges { QgsDateRange( QDate( 2020, 1, 10 ), QDate( 2020, 1, 15 ) ), |
| 57 | + QgsDateRange( QDate( 2020, 1, 20 ), QDate( 2020, 1, 25 ) ), |
| 58 | + QgsDateRange( QDate( 2020, 1, 9 ), QDate( 2020, 1, 11 ) ), |
| 59 | + QgsDateRange( QDate( 2020, 1, 19 ), QDate( 2020, 1, 27 ) ), |
| 60 | + QgsDateRange( QDate( 2020, 1, 1 ), QDate( 2020, 1, 3 ) ) }; |
| 61 | + |
| 62 | + QList< QgsDateRange > res = QgsDateRange::mergeRanges( ranges ); |
| 63 | + QCOMPARE( res.size(), 3 ); |
| 64 | + QCOMPARE( res.at( 0 ).begin(), QDate( 2020, 1, 1 ) ); |
| 65 | + QCOMPARE( res.at( 0 ).end(), QDate( 2020, 1, 3 ) ); |
| 66 | + QCOMPARE( res.at( 1 ).begin(), QDate( 2020, 1, 9 ) ); |
| 67 | + QCOMPARE( res.at( 1 ).end(), QDate( 2020, 1, 15 ) ); |
| 68 | + QCOMPARE( res.at( 2 ).begin(), QDate( 2020, 1, 19 ) ); |
| 69 | + QCOMPARE( res.at( 2 ).end(), QDate( 2020, 1, 27 ) ); |
| 70 | +} |
| 71 | + |
| 72 | +void TestQgsRange::testMergeRangesDateTime() |
| 73 | +{ |
| 74 | + QList< QgsDateTimeRange > ranges { QgsDateTimeRange( QDateTime( QDate( 2020, 1, 10 ), QTime( 0, 0, 0 ) ), QDateTime( QDate( 2020, 1, 15 ), QTime( 0, 0, 0 ) ) ), |
| 75 | + QgsDateTimeRange( QDateTime( QDate( 2020, 1, 20 ), QTime( 0, 0, 0 ) ), QDateTime( QDate( 2020, 1, 25 ), QTime( 0, 0, 0 ) ) ), |
| 76 | + QgsDateTimeRange( QDateTime( QDate( 2020, 1, 9 ), QTime( 0, 0, 0 ) ), QDateTime( QDate( 2020, 1, 11 ), QTime( 0, 0, 0 ) ) ), |
| 77 | + QgsDateTimeRange( QDateTime( QDate( 2020, 1, 19 ), QTime( 0, 0, 0 ) ), QDateTime( QDate( 2020, 1, 27 ), QTime( 0, 0, 0 ) ) ), |
| 78 | + QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ), QTime( 0, 0, 0 ) ), QDateTime( QDate( 2020, 1, 3 ), QTime( 0, 0, 0 ) ) ) }; |
| 79 | + |
| 80 | + QList< QgsDateTimeRange > res = QgsDateTimeRange::mergeRanges( ranges ); |
| 81 | + QCOMPARE( res.size(), 3 ); |
| 82 | + QCOMPARE( res.at( 0 ).begin(), QDateTime( QDate( 2020, 1, 1 ), QTime( 0, 0, 0 ) ) ); |
| 83 | + QCOMPARE( res.at( 0 ).end(), QDateTime( QDate( 2020, 1, 3 ), QTime( 0, 0, 0 ) ) ); |
| 84 | + QCOMPARE( res.at( 1 ).begin(), QDateTime( QDate( 2020, 1, 9 ), QTime( 0, 0, 0 ) ) ); |
| 85 | + QCOMPARE( res.at( 1 ).end(), QDateTime( QDate( 2020, 1, 15 ), QTime( 0, 0, 0 ) ) ); |
| 86 | + QCOMPARE( res.at( 2 ).begin(), QDateTime( QDate( 2020, 1, 19 ), QTime( 0, 0, 0 ) ) ); |
| 87 | + QCOMPARE( res.at( 2 ).end(), QDateTime( QDate( 2020, 1, 27 ), QTime( 0, 0, 0 ) ) ); |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +QGSTEST_MAIN( TestQgsRange ) |
| 92 | +#include "testqgsrange.moc" |
0 commit comments