From 489a97bfb58bfe2e9981c4afd3f7a9da14919e63 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Sat, 31 Mar 2007 01:00:41 +0000 Subject: [PATCH] test MotifModel and MotifElement still haven't found the bug where motifs aren't being rendered on the GlSeqBrowser correctly. --- qui/CMakeLists.txt | 1 + qui/motif_editor/MotifModel.cpp | 6 +- qui/motif_editor/MotifModel.hpp | 1 + qui/motif_editor/test/CMakeLists.txt | 4 + qui/motif_editor/test/TestMotifElement.cpp | 4 + qui/motif_editor/test/TestMotifElement.hpp | 77 ++++++++++++ qui/motif_editor/test/TestMotifModel.cpp | 3 + qui/motif_editor/test/TestMotifModel.hpp | 138 +++++++++++++++++++++ 8 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 qui/motif_editor/test/CMakeLists.txt create mode 100644 qui/motif_editor/test/TestMotifElement.cpp create mode 100644 qui/motif_editor/test/TestMotifElement.hpp create mode 100644 qui/motif_editor/test/TestMotifModel.cpp create mode 100644 qui/motif_editor/test/TestMotifModel.hpp diff --git a/qui/CMakeLists.txt b/qui/CMakeLists.txt index 206dce7..680706c 100644 --- a/qui/CMakeLists.txt +++ b/qui/CMakeLists.txt @@ -108,5 +108,6 @@ SET_TARGET_PROPERTIES( ADD_SUBDIRECTORY( test ) +ADD_SUBDIRECTORY( motif_editor/test ) ADD_SUBDIRECTORY( seqbrowser/test ) ADD_SUBDIRECTORY( subanalysis/test ) diff --git a/qui/motif_editor/MotifModel.cpp b/qui/motif_editor/MotifModel.cpp index 0785721..d07798a 100644 --- a/qui/motif_editor/MotifModel.cpp +++ b/qui/motif_editor/MotifModel.cpp @@ -2,6 +2,8 @@ #include +const size_t MotifModel::model_column_size = 4; + MotifModel::MotifModel(MussaRef m, QObject *parent) : analysis(m), QAbstractTableModel(parent) @@ -124,7 +126,7 @@ MotifModel::rowCount( const QModelIndex& parent) const int MotifModel::columnCount(const QModelIndex& parent) const { - return 4; + return model_column_size; } QVariant @@ -136,7 +138,7 @@ MotifModel::data(const QModelIndex &index, int role) const if (index.row() >= motifs.size()) return QVariant(); - if (index.column() >= 4) + if (index.column() >= model_column_size) return QVariant(); const MotifElement& motif = motifs[index.row()]; diff --git a/qui/motif_editor/MotifModel.hpp b/qui/motif_editor/MotifModel.hpp index 5cf288a..9f51187 100644 --- a/qui/motif_editor/MotifModel.hpp +++ b/qui/motif_editor/MotifModel.hpp @@ -78,6 +78,7 @@ class MotifModel : public QAbstractTableModel //bool removeRows(int row, int count, // const QModelIndex& parent=QModelIndex()); //! \@} + static const size_t model_column_size; private: MussaRef analysis; model_type motifs; diff --git a/qui/motif_editor/test/CMakeLists.txt b/qui/motif_editor/test/CMakeLists.txt new file mode 100644 index 0000000..18cfc0c --- /dev/null +++ b/qui/motif_editor/test/CMakeLists.txt @@ -0,0 +1,4 @@ +INCLUDE( TestMacros ) + +MAKE_QUI_UNITTEST( TestMotifElement ) +MAKE_QUI_UNITTEST( TestMotifModel ) \ No newline at end of file diff --git a/qui/motif_editor/test/TestMotifElement.cpp b/qui/motif_editor/test/TestMotifElement.cpp new file mode 100644 index 0000000..070c097 --- /dev/null +++ b/qui/motif_editor/test/TestMotifElement.cpp @@ -0,0 +1,4 @@ +#include "TestMotifElement.hpp" + +QTEST_MAIN(TestMotifElement) + diff --git a/qui/motif_editor/test/TestMotifElement.hpp b/qui/motif_editor/test/TestMotifElement.hpp new file mode 100644 index 0000000..cf62d48 --- /dev/null +++ b/qui/motif_editor/test/TestMotifElement.hpp @@ -0,0 +1,77 @@ +#ifndef TESTMOTIFELEMENT_HPP_ +#define TESTMOTIFELEMENT_HPP_ +#include +#include + +#include "alg/sequence.hpp" +#include "qui/motif_editor/MotifElement.hpp" + +class TestMotifElement : public QObject +{ + Q_OBJECT + +private slots: + + void testSimpleConstructor() { + MotifElement me; + Color default_color(1.0, 0.0, 0.0, 1.0); + QVERIFY(me.getColor() == default_color); + QVERIFY(me.isEnabled() == true); + QVERIFY(me.isEmpty() == true); + QVERIFY(me.getSequence() == ""); + QVERIFY(me.getName() == ""); + } + + void testSequenceConstructor() { + Sequence s("AAAAAGGGGGG"); + Color white(1.0, 1.0, 1.0); + + MotifElement me(s, white); + QVERIFY(me.getSequence() == s.get_sequence()); + QVERIFY(me.getColor() == white); + QVERIFY(me.isEmpty() == false); + QVERIFY(me.getName() == ""); + } + + void testColorConverters() { + Sequence s("AAAAAGGGGGG"); + Color white(1.0, 1.0, 1.0); + QColor qwhite(255,255,255); + Color red(1.0, 0.0, 0.0); + QColor qred(255,0,0); + + MotifElement me(s, white); + QVERIFY(me.getColor() == white); + QVERIFY(me.getQColor() == qwhite); + + me.setColor(red); + QVERIFY(me.getColor() == red); + QVERIFY(me.getQColor() == qred); + } + + void testSequenceText() { + std::string seq_text("AAAAGGGGG"); + QString qs(seq_text.c_str()); + Sequence s(seq_text); + MotifElement me(s); + + QVERIFY(me.getSequence() == s); + QVERIFY(me.getSequence() == seq_text); + QVERIFY(me.getSequenceText() == qs); + + std::string seq_text2("GGGGTTTTT"); + QString qs2(seq_text2.c_str()); + me.setSequence(seq_text2); + QVERIFY(me.getSequence() == seq_text2); + QVERIFY(me.getSequenceText() == qs2); + } + + void testSequenceName() { + Sequence s("AAAAGGGG"); + MotifElement me(s); + me.setName("hello"); + QVERIFY(me.getName() == "hello"); + } +}; + +#endif /*TESTMOTIFELEMENT_HPP_*/ diff --git a/qui/motif_editor/test/TestMotifModel.cpp b/qui/motif_editor/test/TestMotifModel.cpp new file mode 100644 index 0000000..4eafc59 --- /dev/null +++ b/qui/motif_editor/test/TestMotifModel.cpp @@ -0,0 +1,3 @@ +#include "TestMotifModel.hpp" + +QTEST_MAIN(TestMotifModel) diff --git a/qui/motif_editor/test/TestMotifModel.hpp b/qui/motif_editor/test/TestMotifModel.hpp new file mode 100644 index 0000000..13c6fe0 --- /dev/null +++ b/qui/motif_editor/test/TestMotifModel.hpp @@ -0,0 +1,138 @@ +#ifndef TESTMOTIFMODEL_HPP_ +#define TESTMOTIFMODEL_HPP_ +#include +#include +#include +#include + +#include +#include "alg/sequence.hpp" + +#include "qui/motif_editor/MotifModel.hpp" +#include "qui/motif_editor/MotifElement.hpp" + +class TestMotifModel : public QObject +{ + Q_OBJECT + +private slots: + + void testSimpleConstructor() { + MussaRef m(new Mussa); + MotifModel *model = new MotifModel(m); + + QVERIFY(model->getAnalysis() == m); + // we should always have one empty row + QVERIFY(model->empty() == false); + QVERIFY(model->size() == 1); + QVERIFY(model->rowCount() == 1); + + QVERIFY(model->columnCount() == MotifModel::model_column_size); + + // make sure that one element is empty + MotifElement me(model->at(0)); + QVERIFY(me.getSequenceText() == ""); + QVERIFY(me.getName() == ""); + QVERIFY(me.isEnabled() == true); + + // this removes the last element? + model->pop_back(); + QVERIFY(model->empty() == true); + QVERIFY(model->size() == 0); + } + + void testInitializedMussaMotifs() { + std::vector motifs; + motifs.push_back("AAGG"); + std::vector colors; + colors.push_back(Color(0.0, 0.0, 1.0)); + + + MussaRef m(new Mussa); + m->append_sequence("AAAAGGGGTTTT"); + m->append_sequence("GGGCCCCTTGGTT"); + m->set_motifs(motifs, colors); + + MotifModel *model = new MotifModel(m); + + QVERIFY(model->getAnalysis() == m); + QVERIFY(model->size() == 2); + + // make sure that one element is empty + MotifElement me(model->at(0)); + QVERIFY(me.getSequenceText() == "AAGG"); + QVERIFY(me.getName() == ""); + QVERIFY(me.isEnabled() == true); + QVERIFY(me.getColor() == Color(0.0, 0.0, 1.0)); + } + + void testSetData() { + MussaRef m(new Mussa); + MotifModel *model = new MotifModel(m); + qRegisterMetaType("QModelIndex"); + QSignalSpy data_changed_spy(model, + SIGNAL(dataChanged(const QModelIndex&, + const QModelIndex&) + ) + ); + QVERIFY(model->size() == 1); + QVERIFY(data_changed_spy.count() == 0); + + QModelIndex row0_enabled(model->index(0, MotifModel::EnabledCell)); + QModelIndex row0_color(model->index(0, MotifModel::ColorCell)); + QModelIndex row0_name(model->index(0, MotifModel::NameCell)); + QModelIndex row0_seq(model->index(0, MotifModel::SequenceCell)); + + model->setData(row0_name, QVariant("tata box")); + QVERIFY(model->size() == 2); + QVERIFY(data_changed_spy.count() == 1); + QVERIFY(model->data(row0_name) == QVariant("tata box")); + + model->setData(row0_seq, QVariant("TTTAAA")); + QVERIFY(model->size() == 2); + QVERIFY(data_changed_spy.count() == 2); + QVERIFY(model->data(row0_seq) == QVariant("TTTAAA")); + + MotifElement me(model->at(0)); + QVERIFY(me.getName() == "tata box"); + QVERIFY(me.getSequenceText() == "TTTAAA"); + } + + void testIterator() { + MussaRef m(new Mussa); + MotifModel *model = new MotifModel(m); + QVERIFY(model->size() == 1); + + QModelIndex row0_enabled(model->index(0, MotifModel::EnabledCell)); + QModelIndex row0_color(model->index(0, MotifModel::ColorCell)); + QModelIndex row0_name(model->index(0, MotifModel::NameCell)); + QModelIndex row0_seq(model->index(0, MotifModel::SequenceCell)); + + model->setData(row0_color, QVariant(QColor(0,255,0))); + model->setData(row0_name, QVariant("tata box")); + model->setData(row0_seq, QVariant("TTTAAA")); + + QModelIndex row1_enabled(model->index(1, MotifModel::EnabledCell)); + model->setData(row1_enabled, QVariant(false)); + + for(MotifModel::const_iterator element = model->begin(); + element != model->end(); + ++element) + { + // first element + if ( (element-model->begin()) == 0) { + QVERIFY(element->getQColor() == QColor(0,255,0)); + QVERIFY(element->getName() == "tata box"); + QVERIFY(element->getSequenceText() == "TTTAAA"); + } if ( (element-model->begin()) == 1) { + QVERIFY(element->getQColor() == QColor(255,0,0)); + QVERIFY(element->getName() == ""); + QVERIFY(element->getSequenceText() == ""); + } if ( (element-model->begin()) > 1) { + QFAIL("Too many elements in model"); + } + } + } +}; + +#endif /*TESTMOTIFMODEL_HPP_*/ -- 2.30.2