Example #1
0
void Coordinates_test::
t_readonly()
{
    Coordinates c;
    QCOMPARE(c.size(), 0u);
    QCOMPARE(c.count(), 0);
    QVERIFY(c.isEmpty());
    c << 1.0 << -2.0;
    QCOMPARE(c.size(), 2u);
    QCOMPARE(c.count(), 2);
    QVERIFY(!c.isEmpty());
}//t_readonly
Example #2
0
void Coordinates_test::
t_convert()
{
    Coordinates c;
    c << 1.0 << 3.0;
    QCOMPARE(c.data()[1], 3.0);
    coordT *c2= c.data();
    const coordT *c3= c.data();
    QCOMPARE(c2, c3);
    std::vector<coordT> vc= c.toStdVector();
    QCOMPARE(vc.size(), c.size());
    for(size_t k= vc.size(); k--; ){
        QCOMPARE(vc[k], c[k]);
    }
    QList<coordT> qc= c.toQList();
    QCOMPARE(qc.count(), c.count());
    for(int k= qc.count(); k--; ){
        QCOMPARE(qc[k], c[k]);
    }
    Coordinates c4;
    c4= std::vector<double>(2, 0.0);
    QCOMPARE(c4.back(), 0.0);
    Coordinates c5(std::vector<double>(2, 0.0));
    QCOMPARE(c4.size(), c5.size());
    QVERIFY(c4==c5);
}//t_convert
Example #3
0
void Coordinates_test::
t_search()
{
    Coordinates c;
    c << 1.0 << 3.0 << 1.0;
    QVERIFY(c.contains(1.0));
    QVERIFY(c.contains(3.0));
    QVERIFY(!c.contains(0.0));
    QCOMPARE(c.count(1.0), 2);
    QCOMPARE(c.count(3.0), 1);
    QCOMPARE(c.count(0.0), 0);
    QCOMPARE(c.indexOf(1.0), 0);
    QCOMPARE(c.indexOf(3.0), 1);
    QCOMPARE(c.indexOf(1.0, -1), 2);
    QCOMPARE(c.indexOf(3.0, -1), -1);
    QCOMPARE(c.indexOf(3.0, -2), 1);
    QCOMPARE(c.indexOf(1.0, -3), 0);
    QCOMPARE(c.indexOf(1.0, -4), 0);
    QCOMPARE(c.indexOf(1.0, 1), 2);
    QCOMPARE(c.indexOf(3.0, 2), -1);
    QCOMPARE(c.indexOf(1.0, 2), 2);
    QCOMPARE(c.indexOf(1.0, 3), -1);
    QCOMPARE(c.indexOf(1.0, 4), -1);
    QCOMPARE(c.lastIndexOf(1.0), 2);
    QCOMPARE(c.lastIndexOf(3.0), 1);
    QCOMPARE(c.lastIndexOf(1.0, -1), 2);
    QCOMPARE(c.lastIndexOf(3.0, -1), 1);
    QCOMPARE(c.lastIndexOf(3.0, -2), 1);
    QCOMPARE(c.lastIndexOf(1.0, -3), 0);
    QCOMPARE(c.lastIndexOf(1.0, -4), -1);
    QCOMPARE(c.lastIndexOf(1.0, 1), 0);
    QCOMPARE(c.lastIndexOf(3.0, 2), 1);
    QCOMPARE(c.lastIndexOf(1.0, 2), 2);
    QCOMPARE(c.lastIndexOf(1.0, 3), 2);
    QCOMPARE(c.lastIndexOf(1.0, 4), 2);
    c.removeAll(3.0);
    QCOMPARE(c.count(), 2);
    c.removeAll(4.0);
    QCOMPARE(c.count(), 2);
    c.removeAll(1.0);
    QCOMPARE(c.count(), 0);
    c.removeAll(4.0);
    QCOMPARE(c.count(), 0);
}//t_search
Example #4
0
void Coordinates_test::
t_readwrite()
{
    Coordinates c;
    c.clear();
    QCOMPARE(c.count(), 0);
    c << 1.0 << 3.0;
    c.clear();
    QCOMPARE(c.count(), 0);
    c << 1.0 << 3.0;
    c.erase(c.begin(), c.end());
    QCOMPARE(c.count(), 0);
    c << 1.0 << 0.0;
    Coordinates::iterator i= c.erase(c.begin());
    QCOMPARE(*i, 0.0);
    i= c.insert(c.end(), 1.0);
    QCOMPARE(*i, 1.0);
    QCOMPARE(c.count(), 2);
    c.pop_back();
    QCOMPARE(c.count(), 1);   // 0
    QCOMPARE(c[0], 0.0);
    c.push_back(2.0);
    QCOMPARE(c.count(), 2);
    c.append(3.0);
    QCOMPARE(c.count(), 3);   // 0, 2, 3
    QCOMPARE(c[2], 3.0);
    c.insert(0, 4.0);
    QCOMPARE(c[0], 4.0);
    QCOMPARE(c[3], 3.0);
    c.insert(c.count(), 5.0);
    QCOMPARE(c.count(), 5);   // 4, 0, 2, 3, 5
    QCOMPARE(c[4], 5.0);
    c.move(4, 0);
    QCOMPARE(c.count(), 5);   // 5, 4, 0, 2, 3
    QCOMPARE(c[0], 5.0);
    c.pop_front();
    QCOMPARE(c.count(), 4);
    QCOMPARE(c[0], 4.0);
    c.prepend(6.0);
    QCOMPARE(c.count(), 5);   // 6, 4, 0, 2, 3
    QCOMPARE(c[0], 6.0);
    c.push_front(7.0);
    QCOMPARE(c.count(), 6);
    QCOMPARE(c[0], 7.0);
    c.removeAt(1);
    QCOMPARE(c.count(), 5);   // 7, 4, 0, 2, 3
    QCOMPARE(c[1], 4.0);
    c.removeFirst();
    QCOMPARE(c.count(), 4);   // 4, 0, 2, 3
    QCOMPARE(c[0], 4.0);
    c.removeLast();
    QCOMPARE(c.count(), 3);
    QCOMPARE(c.last(), 2.0);
    c.replace(2, 8.0);
    QCOMPARE(c.count(), 3);   // 4, 0, 8
    QCOMPARE(c[2], 8.0);
    c.swap(0, 2);
    QCOMPARE(c[2], 4.0);
    double d= c.takeAt(2);
    QCOMPARE(c.count(), 2);   // 8, 0
    QCOMPARE(d, 4.0);
    double d2= c.takeFirst();
    QCOMPARE(c.count(), 1);   // 0
    QCOMPARE(d2, 8.0);
    double d3= c.takeLast();
    QVERIFY(c.isEmpty()); \
    QCOMPARE(d3, 0.0);
}//t_readwrite
Example #5
0
void Coordinates_test::
t_mutable_coord_iterator()
{
    // Same tests as CoordinatesIterator
    Coordinates c;
    c << 1.0 << 3.0;
    MutableCoordinatesIterator i(c);
    MutableCoordinatesIterator i2= c;
    QVERIFY(i.findNext(1.0));
    QVERIFY(!i.findNext(2.0));
    QVERIFY(!i.findNext(3.0));
    QVERIFY(i.findPrevious(3.0));
    QVERIFY(!i.findPrevious(2.0));
    QVERIFY(!i.findPrevious(1.0));
    QVERIFY(i2.findNext(3.0));
    QVERIFY(i2.findPrevious(3.0));
    QVERIFY(i2.findNext(3.0));
    QVERIFY(i2.findPrevious(1.0));
    QVERIFY(i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    QVERIFY(i.hasNext());
    QVERIFY(!i.hasPrevious());
    i.toBack();
    i2.toFront();
    QVERIFY(!i.hasNext());
    QVERIFY(i.hasPrevious());
    QVERIFY(i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    Coordinates c2;
    i2= c2;
    QVERIFY(!i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    i2.toBack();
    QVERIFY(!i2.hasNext());
    QVERIFY(!i2.hasPrevious());
    QCOMPARE(i.peekPrevious(), 3.0);
    QCOMPARE(i.peekPrevious(), 3.0);
    QCOMPARE(i.previous(), 3.0);
    QCOMPARE(i.previous(), 1.0);
    QVERIFY(!i.hasPrevious());
    QCOMPARE(i.peekNext(), 1.0);
    QCOMPARE(i.next(), 1.0);
    QCOMPARE(i.peekNext(), 3.0);
    QCOMPARE(i.next(), 3.0);
    QVERIFY(!i.hasNext());
    i.toFront();
    QCOMPARE(i.next(), 1.0);

    // Mutable tests
    i.toFront();
    i.peekNext()= -1.0;
    QCOMPARE(i.peekNext(), -1.0);
    QCOMPARE((i.next()= 1.0), 1.0);
    QCOMPARE(i.peekPrevious(), 1.0);
    i.remove();
    QCOMPARE(c.count(), 1);
    i.remove();
    QCOMPARE(c.count(), 1);
    QCOMPARE(i.peekNext(), 3.0);
    i.insert(1.0);
    i.insert(2.0);
    QCOMPARE(c.count(), 3);
    QCOMPARE(i.peekNext(), 3.0);
    QCOMPARE(i.peekPrevious(), 2.0);
    i.peekPrevious()= -2.0;
    QCOMPARE(i.peekPrevious(), -2.0);
    QCOMPARE((i.previous()= 2.0), 2.0);
    QCOMPARE(i.peekNext(), 2.0);
    i.toBack();
    i.remove();
    QCOMPARE(c.count(), 3); // unchanged
    i.toFront();
    i.remove();
    QCOMPARE(c.count(), 3); // unchanged
    QCOMPARE(i.peekNext(), 1.0);
    i.remove();
    QCOMPARE(c.count(), 3); // unchanged
    i.insert(0.0);
    QCOMPARE(c.count(), 4);
    QCOMPARE(i.value(), 0.0);
    QCOMPARE(i.peekPrevious(), 0.0);
    i.setValue(-10.0);
    QCOMPARE(c.count(), 4); // unchanged
    QCOMPARE(i.peekNext(), 1.0);
    QCOMPARE(i.peekPrevious(), -10.0);
    i.findNext(1.0);
    i.setValue(-1.0);
    QCOMPARE(i.peekPrevious(), -1.0);
    i.setValue(1.0);
    QCOMPARE(i.peekPrevious(), 1.0);
    QCOMPARE(i.value(), 1.0);
    i.findPrevious(1.0);
    i.setValue(-1.0);
    QCOMPARE(i.peekNext(), -1.0);
    i.toBack();
    QCOMPARE(i.previous(), 3.0);
    i.setValue(-3.0);
    QCOMPARE(i.peekNext(), -3.0);
    double d= i.value();
    QCOMPARE(d, -3.0);
    QCOMPARE(i.previous(), 2.0);
}//t_mutable_coord_iterator