From f88eea68b95773eb5683dcca6cf3fa59b9f00036 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Sat, 31 Mar 2007 01:44:41 +0000 Subject: [PATCH] test motif editor I was thinking this is where the source of my motifs disappearing might have been, but aparently the motif editor does still work correctly. --- alg/mussa.cpp | 2 +- qui/motif_editor/MotifEditor.cpp | 2 + qui/motif_editor/MotifEditor.hpp | 6 ++ qui/motif_editor/test/CMakeLists.txt | 1 + qui/motif_editor/test/TestMotifEditor.cpp | 3 + qui/motif_editor/test/TestMotifEditor.hpp | 74 +++++++++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 qui/motif_editor/test/TestMotifEditor.cpp create mode 100644 qui/motif_editor/test/TestMotifEditor.hpp diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 52d0dce..4b96d1b 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -328,7 +328,7 @@ void Mussa::append_sequence(boost::shared_ptr a_seq) } -const vector >& +const vector& Mussa::sequences() const { return the_seqs; diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index 8166e37..acde2d3 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -51,6 +51,8 @@ void MotifEditor::updateModel() // if our current analysis doesn't match the one in our // model, we probalby changed the analysis. // so delete and restart + // DET 2007mar30 (can this if statement ever be true? it doesn't look + // like there's a way to change the analysis?) if (model and model->getAnalysis() != analysis) { delete model; } diff --git a/qui/motif_editor/MotifEditor.hpp b/qui/motif_editor/MotifEditor.hpp index aaff9a7..1cc8a2f 100644 --- a/qui/motif_editor/MotifEditor.hpp +++ b/qui/motif_editor/MotifEditor.hpp @@ -24,6 +24,12 @@ public: //! resize cells void updateView(); + //! return the analysis, intended for testing + MussaRef get_analysis() { return analysis; } + //! return the internal model used by the editor + //! this is mostly intended for testing + MotifModel *get_model() { return model; } + public slots: //! create model and attach it to the table view void updateModel(); diff --git a/qui/motif_editor/test/CMakeLists.txt b/qui/motif_editor/test/CMakeLists.txt index 18cfc0c..9f37708 100644 --- a/qui/motif_editor/test/CMakeLists.txt +++ b/qui/motif_editor/test/CMakeLists.txt @@ -1,4 +1,5 @@ INCLUDE( TestMacros ) +MAKE_QUI_UNITTEST( TestMotifEditor ) MAKE_QUI_UNITTEST( TestMotifElement ) MAKE_QUI_UNITTEST( TestMotifModel ) \ No newline at end of file diff --git a/qui/motif_editor/test/TestMotifEditor.cpp b/qui/motif_editor/test/TestMotifEditor.cpp new file mode 100644 index 0000000..515c122 --- /dev/null +++ b/qui/motif_editor/test/TestMotifEditor.cpp @@ -0,0 +1,3 @@ +#include "TestMotifEditor.hpp" + +QTEST_MAIN(TestMotifEditor) diff --git a/qui/motif_editor/test/TestMotifEditor.hpp b/qui/motif_editor/test/TestMotifEditor.hpp new file mode 100644 index 0000000..1e29ccc --- /dev/null +++ b/qui/motif_editor/test/TestMotifEditor.hpp @@ -0,0 +1,74 @@ +#ifndef TESTMOTIFEDITOR_HPP_ +#define TESTMOTIFEDITOR_HPP_ +#include +#include +#include +#include + +#include +#include "alg/sequence.hpp" + +#include "qui/motif_editor/MotifEditor.hpp" +#include "qui/motif_editor/MotifModel.hpp" + +class TestMotifEditor : public QObject +{ + Q_OBJECT + +private slots: + + void testSimpleConstructor() { + MussaRef m1(new Mussa); + MotifEditor *editor = new MotifEditor(m1); + + QVERIFY(editor->get_analysis() == m1); + QVERIFY(editor->get_model() != 0); + } + + // do we still have motifs in our sequences after hitting apply? + void testEditColorApply() { + 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("AAAAAAAACCCC"); + m->set_motifs(motifs, colors); + + // do the sequences have the right motifs? + std::vector sequences1(m->sequences()); + QVERIFY(sequences1[0]->motifs().size() == 1); + QVERIFY(sequences1[1]->motifs().size() == 0); + + // get color + boost::shared_ptr cm(m->colorMapper()); + QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 1.0)); + + MotifEditor *editor(new MotifEditor(m)); + MotifModel *model(editor->get_model()); + // the AAGG motif and the emtpy motif + QVERIFY(model->size() == 2); + QModelIndex row0_color(model->index(0, MotifModel::ColorCell)); + + model->setData(row0_color, QVariant(QColor(0,255,0))); + // this is equivalent to pressing apply + editor->updateAnalysisMotifs(); + + std::vector sequences2(m->sequences()); + QVERIFY(sequences2[0]->motifs().size() == 1); + QVERIFY(sequences2[1]->motifs().size() == 0); + QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 1.0, 0.0)); + } +/* + +public slots: + void updateModel(); + void updateAnalysisMotifs(); + +signals: + void changedMotifs(); + */ +}; +#endif /*TESTMOTIFEDITOR_HPP_*/ -- 2.30.2