diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(analysis) add_subdirectory(import_export) add_subdirectory(nsl) +add_subdirectory(spreadsheet) diff --git a/tests/spreadsheet/CMakeLists.txt b/tests/spreadsheet/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/CMakeLists.txt @@ -0,0 +1,9 @@ +INCLUDE_DIRECTORIES(${GSL_INCLUDE_DIR}) + +add_executable (trivialtest TrivialTest.cpp) + +target_link_libraries(trivialtest Qt5::Test) +target_link_libraries(trivialtest ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES}) +target_link_libraries(trivialtest labplot2lib) + +add_test(NAME trivialtest COMMAND trivialtest) diff --git a/tests/spreadsheet/TrivialTest.h b/tests/spreadsheet/TrivialTest.h new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/TrivialTest.h @@ -0,0 +1,53 @@ +/*************************************************************************** + File : TrivialTest.h + Project : LabPlot + Description : Tests for the Spreadsheet's trivial features + -------------------------------------------------------------------- + Copyright : (C) 2019 Shubham (aryan100jangid@gmail.com) + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + ***************************************************************************/ + +#ifndef TRIVIALTEST_H +#define TRIVIALTEST_H + +#include + +#include "backend/spreadsheet/Spreadsheet.h" + +class TrivialTest : public QObject { + Q_OBJECT + +public: + TrivialTest(); + ~TrivialTest(); + +private slots: + void testRowCount(); + void testColumnCount(); + void testRowColumnValues(); + void testAddRemoveRow(); + void testAddRemoveColumn(); + +private: + Spreadsheet *sheet; +}; + +#endif diff --git a/tests/spreadsheet/TrivialTest.cpp b/tests/spreadsheet/TrivialTest.cpp new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/TrivialTest.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + File : TrivialTest.cpp + Project : LabPlot + Description : Tests for the Spreadsheet's trivial features + -------------------------------------------------------------------- + Copyright : (C) 2019 Shubham (aryan100jangid@gmail.com) + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + ***************************************************************************/ + +#include "TrivialTest.h" + +TrivialTest::TrivialTest() { + sheet = new Spreadsheet("test", false); + + sheet->column(0)->setValueAt(0, 10.0); + sheet->column(0)->setValueAt(1, 20.0); + sheet->column(0)->setValueAt(2, 30.0); + + sheet->column(1)->setValueAt(0, 100.0); + sheet->column(1)->setValueAt(1, 200.0); + sheet->column(1)->setValueAt(2, 300.0); + + sheet->column(2)->setValueAt(0, 1000.0); + sheet->column(2)->setValueAt(1, 2000.0); + sheet->column(2)->setValueAt(2, 3000.0); +} + +TrivialTest::~TrivialTest() { + delete sheet; +} + +void TrivialTest::testRowCount() { + QCOMPARE(sheet->rowCount(), 3); +} + +void TrivialTest::testColumnCount() { + QCOMPARE(sheet->columnCount(), 3); +} + +void TrivialTest::testRowColumnValues() { + QCOMPARE(sheet->column(0)->valueAt(0), 10.0); + QCOMPARE(sheet->column(0)->valueAt(1), 20.0); + QCOMPARE(sheet->column(2)->valueAt(1), 2000.0); + QCOMPARE(sheet->column(2)->valueAt(0), 1000.0); +} + +void TrivialTest::testAddRemoveRow() { + // Test adding a row + QCOMPARE(sheet->rowCount(), 3); + sheet->insertRows(3, 1); + QCOMPARE(sheet->rowCount(), 4); + + // Test removing a row + sheet->removeRows(3, 1); + QCOMPARE(sheet->rowCount(), 3); +} + +void TrivialTest::testAddRemoveColumn() { + // Test adding a column + QCOMPARE(sheet->columnCount(), 3); + sheet->insertColumns(3, 1); + QCOMPARE(sheet->columnCount(), 4); + + // Test removing a column + sheet->removeColumns(3, 1); + QCOMPARE(sheet->columnCount(), 3); +} + +QTEST_MAIN(TrivialTest)