1 /* 2 SPDX-FileCopyrightText: 2012 Benjamin Port <benjamin.port@ben2367.fr> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #include <kplotaxis.h> 8 9 #include <QTest> 10 11 class KPlotAxisTest : public QObject 12 { 13 Q_OBJECT 14 15 private Q_SLOTS: initTestCase()16 void initTestCase() 17 { 18 m_kPlotAxis = new KPlotAxis(QStringLiteral("label")); 19 } 20 cleanupTestCase()21 void cleanupTestCase() 22 { 23 delete m_kPlotAxis; 24 } 25 testVisible()26 void testVisible() 27 { 28 m_kPlotAxis->setVisible(true); 29 QCOMPARE(m_kPlotAxis->isVisible(), true); 30 31 m_kPlotAxis->setVisible(false); 32 QCOMPARE(m_kPlotAxis->isVisible(), false); 33 } 34 testTickLabelsShown()35 void testTickLabelsShown() 36 { 37 m_kPlotAxis->setTickLabelsShown(true); 38 QCOMPARE(m_kPlotAxis->areTickLabelsShown(), true); 39 40 m_kPlotAxis->setTickLabelsShown(false); 41 QCOMPARE(m_kPlotAxis->areTickLabelsShown(), false); 42 } 43 testLabel()44 void testLabel() 45 { 46 QCOMPARE(m_kPlotAxis->label(), QString::fromLatin1("label")); 47 48 m_kPlotAxis->setLabel(QStringLiteral("newLabel")); 49 QCOMPARE(m_kPlotAxis->label(), QString::fromLatin1("newLabel")); 50 } 51 testTickLabelFormat()52 void testTickLabelFormat() 53 { 54 m_kPlotAxis->setTickLabelFormat('e', 3, 2); 55 QCOMPARE(m_kPlotAxis->tickLabelFormat(), 'e'); 56 QCOMPARE(m_kPlotAxis->tickLabelWidth(), 3); 57 QCOMPARE(m_kPlotAxis->tickLabelPrecision(), 2); 58 } 59 testTickMarks()60 void testTickMarks() 61 { 62 m_kPlotAxis->setTickMarks(0.0, 12.0); 63 QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 0.0 << 4.0 << 8.0 << 12.0); 64 QCOMPARE(m_kPlotAxis->minorTickMarks(), QList<double>() << 1.0 << 2.0 << 3.0 << 5.0 << 6.0 << 7.0 << 9.0 << 10.0 << 11.0); 65 66 m_kPlotAxis->setTickMarks(0.0, 120.0); 67 QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 0.0 << 40.0 << 80.0 << 120.0); 68 QCOMPARE(m_kPlotAxis->minorTickMarks(), QList<double>() << 10.0 << 20.0 << 30.0 << 50.0 << 60.0 << 70.0 << 90.0 << 100.0 << 110.0); 69 70 m_kPlotAxis->setTickMarks(4.0, 29.0); // from 4 to 4+29 = 33 71 QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 5.0 << 10.0 << 15.0 << 20.0 << 25.0 << 30.0); 72 } 73 74 private: 75 KPlotAxis *m_kPlotAxis; 76 }; 77 78 QTEST_MAIN(KPlotAxisTest) 79 80 #include "kplotaxistest.moc" 81