File indexing completed on 2024-12-22 04:40:16
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "rangetest.h" 0009 #include "core/range.h" 0010 0011 #include <QTest> // krazy:exclude=c++/includes 0012 0013 using namespace SubtitleComposer; 0014 0015 void 0016 RangeTest::testConstructors() 0017 { 0018 QVERIFY(Range::MaxIndex > 0); 0019 0020 Range fullRange = Range::full(); 0021 QVERIFY(fullRange.start() == 0); 0022 QVERIFY(fullRange.end() == Range::MaxIndex); 0023 0024 Range lowerRange = Range::lower(16); 0025 QVERIFY(lowerRange.start() == 0); 0026 QVERIFY(lowerRange.end() == 16); 0027 0028 Range upperRange = Range::upper(16); 0029 QVERIFY(upperRange.start() == 16); 0030 QVERIFY(upperRange.end() == Range::MaxIndex); 0031 0032 Range range(13, 32); 0033 QVERIFY(range.start() == 13); 0034 QVERIFY(range.end() == 32); 0035 } 0036 0037 void 0038 RangeTest::testLimits() 0039 { 0040 QVERIFY(Range::MaxIndex > 0); 0041 0042 Range range(13, 99); 0043 QVERIFY(!range.contains(12)); 0044 QVERIFY(range.contains(13)); 0045 QVERIFY(range.contains(99)); 0046 QVERIFY(!range.contains(100)); 0047 } 0048 0049 void 0050 RangeTest::testOperators() 0051 { 0052 QVERIFY(Range::MaxIndex > 0); 0053 0054 Range range(13, 99); 0055 QVERIFY(range == Range(13, 99)); 0056 QVERIFY(range != Range(12, 99)); 0057 QVERIFY(range != Range(13, 100)); 0058 QVERIFY(range != Range(13, 100)); 0059 0060 QVERIFY(Range(11, 15) > Range(8, 10)); 0061 QVERIFY(!(Range(11, 15) > Range(8, 12))); 0062 QVERIFY(!(Range(7, 8) > Range(8, 12))); 0063 0064 QVERIFY(Range(8, 15) >= Range(7, 10)); 0065 QVERIFY(Range(10, 15) >= Range(7, 10)); 0066 QVERIFY(Range(11, 15) >= Range(7, 10)); 0067 QVERIFY(Range(7, 10) >= Range(7, 10)); 0068 QVERIFY(!(Range(7, 9) >= Range(7, 10))); 0069 QVERIFY(!(Range(6, 11) >= Range(7, 10))); 0070 QVERIFY(!(Range(7, 9) >= Range(6, 10))); 0071 0072 QVERIFY(Range(8, 10) < Range(11, 15)); 0073 QVERIFY(!(Range(8, 12) < Range(11, 15))); 0074 QVERIFY(!(Range(8, 12) < Range(7, 8))); 0075 0076 QVERIFY(Range(7, 10) <= Range(8, 15)); 0077 QVERIFY(Range(7, 10) <= Range(10, 15)); 0078 QVERIFY(Range(7, 10) <= Range(11, 15)); 0079 QVERIFY(Range(7, 10) <= Range(7, 10)); 0080 QVERIFY(!(Range(7, 10) <= Range(7, 9))); 0081 QVERIFY(!(Range(7, 10) <= Range(6, 11))); 0082 QVERIFY(!(Range(6, 10) <= Range(7, 9))); 0083 } 0084 0085 QTEST_GUILESS_MAIN(RangeTest);