test MotifModel and MotifElement
authorDiane Trout <diane@caltech.edu>
Sat, 31 Mar 2007 01:00:41 +0000 (01:00 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 31 Mar 2007 01:00:41 +0000 (01:00 +0000)
still haven't found the bug where motifs aren't being rendered
on the GlSeqBrowser correctly.

qui/CMakeLists.txt
qui/motif_editor/MotifModel.cpp
qui/motif_editor/MotifModel.hpp
qui/motif_editor/test/CMakeLists.txt [new file with mode: 0644]
qui/motif_editor/test/TestMotifElement.cpp [new file with mode: 0644]
qui/motif_editor/test/TestMotifElement.hpp [new file with mode: 0644]
qui/motif_editor/test/TestMotifModel.cpp [new file with mode: 0644]
qui/motif_editor/test/TestMotifModel.hpp [new file with mode: 0644]

index 206dce793a7cd7cf5892674a82c64c61ae80301a..680706ca0b60c266ae338d3b7c97588309ea1343 100644 (file)
@@ -108,5 +108,6 @@ SET_TARGET_PROPERTIES(
 
 
 ADD_SUBDIRECTORY( test )
+ADD_SUBDIRECTORY( motif_editor/test )
 ADD_SUBDIRECTORY( seqbrowser/test )
 ADD_SUBDIRECTORY( subanalysis/test )
index 0785721f1f74ea74b89aca3abe4a3e38061ac43d..d07798abd3f1241591b5892aa60ecf265f6cab89 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <QColor>
 
+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()];
index 5cf288a99c6a1b21b0614b7bdc4911799f08ad66..9f51187dceba4ed9ff2ee0ca1a685030ecbf9ebc 100644 (file)
@@ -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 (file)
index 0000000..18cfc0c
--- /dev/null
@@ -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 (file)
index 0000000..070c097
--- /dev/null
@@ -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 (file)
index 0000000..cf62d48
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef TESTMOTIFELEMENT_HPP_
+#define TESTMOTIFELEMENT_HPP_
+#include <QtGui>
+#include <QtTest/QtTest>
+
+#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 (file)
index 0000000..4eafc59
--- /dev/null
@@ -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 (file)
index 0000000..13c6fe0
--- /dev/null
@@ -0,0 +1,138 @@
+#ifndef TESTMOTIFMODEL_HPP_
+#define TESTMOTIFMODEL_HPP_
+#include <QtGui>
+#include <QVariant>
+#include <QtTest/QtTest>
+#include <QtTest/QSignalSpy>
+
+#include <vector>
+#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<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("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>("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_*/