File indexing completed on 2024-04-28 15:29:28

0001 /*
0002     SPDX-FileCopyrightText: 2012 Benjamin Port <benjamin.port@ben2367.fr>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <kplotaxis.h>
0008 
0009 #include <QTest>
0010 
0011 class KPlotAxisTest : public QObject
0012 {
0013     Q_OBJECT
0014 
0015 private Q_SLOTS:
0016     void initTestCase()
0017     {
0018         m_kPlotAxis = new KPlotAxis(QStringLiteral("label"));
0019     }
0020 
0021     void cleanupTestCase()
0022     {
0023         delete m_kPlotAxis;
0024     }
0025 
0026     void testVisible()
0027     {
0028         m_kPlotAxis->setVisible(true);
0029         QCOMPARE(m_kPlotAxis->isVisible(), true);
0030 
0031         m_kPlotAxis->setVisible(false);
0032         QCOMPARE(m_kPlotAxis->isVisible(), false);
0033     }
0034 
0035     void testTickLabelsShown()
0036     {
0037         m_kPlotAxis->setTickLabelsShown(true);
0038         QCOMPARE(m_kPlotAxis->areTickLabelsShown(), true);
0039 
0040         m_kPlotAxis->setTickLabelsShown(false);
0041         QCOMPARE(m_kPlotAxis->areTickLabelsShown(), false);
0042     }
0043 
0044     void testLabel()
0045     {
0046         QCOMPARE(m_kPlotAxis->label(), QString::fromLatin1("label"));
0047 
0048         m_kPlotAxis->setLabel(QStringLiteral("newLabel"));
0049         QCOMPARE(m_kPlotAxis->label(), QString::fromLatin1("newLabel"));
0050     }
0051 
0052     void testTickLabelFormat()
0053     {
0054         m_kPlotAxis->setTickLabelFormat('e', 3, 2);
0055         QCOMPARE(m_kPlotAxis->tickLabelFormat(), 'e');
0056         QCOMPARE(m_kPlotAxis->tickLabelWidth(), 3);
0057         QCOMPARE(m_kPlotAxis->tickLabelPrecision(), 2);
0058     }
0059 
0060     void testTickMarks()
0061     {
0062         m_kPlotAxis->setTickMarks(0.0, 12.0);
0063         QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 0.0 << 4.0 << 8.0 << 12.0);
0064         QCOMPARE(m_kPlotAxis->minorTickMarks(), QList<double>() << 1.0 << 2.0 << 3.0 << 5.0 << 6.0 << 7.0 << 9.0 << 10.0 << 11.0);
0065 
0066         m_kPlotAxis->setTickMarks(0.0, 120.0);
0067         QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 0.0 << 40.0 << 80.0 << 120.0);
0068         QCOMPARE(m_kPlotAxis->minorTickMarks(), QList<double>() << 10.0 << 20.0 << 30.0 << 50.0 << 60.0 << 70.0 << 90.0 << 100.0 << 110.0);
0069 
0070         m_kPlotAxis->setTickMarks(4.0, 29.0); // from 4 to 4+29 = 33
0071         QCOMPARE(m_kPlotAxis->majorTickMarks(), QList<double>() << 5.0 << 10.0 << 15.0 << 20.0 << 25.0 << 30.0);
0072     }
0073 
0074 private:
0075     KPlotAxis *m_kPlotAxis;
0076 };
0077 
0078 QTEST_MAIN(KPlotAxisTest)
0079 
0080 #include "kplotaxistest.moc"