test motif editor
[mussa.git] / qui / motif_editor / test / TestMotifEditor.hpp
diff --git a/qui/motif_editor/test/TestMotifEditor.hpp b/qui/motif_editor/test/TestMotifEditor.hpp
new file mode 100644 (file)
index 0000000..1e29ccc
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef TESTMOTIFEDITOR_HPP_
+#define TESTMOTIFEDITOR_HPP_
+#include <QtGui>
+#include <QVariant>
+#include <QtTest/QtTest>
+#include <QtTest/QSignalSpy>
+
+#include <vector>
+#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<Sequence> motifs;
+    motifs.push_back("AAGG");
+    std::vector<Color> 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<SequenceRef> sequences1(m->sequences());
+    QVERIFY(sequences1[0]->motifs().size() == 1);
+    QVERIFY(sequences1[1]->motifs().size() == 0);
+    
+    // get color
+    boost::shared_ptr<AnnotationColors> 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<SequenceRef> 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_*/