Пример #1
0
////////////////////////////////////////////////////////////////////////////////
// Merge step 3: merge elementary intervals (each interval is <= SAMPLE_STRIDE)
////////////////////////////////////////////////////////////////////////////////
static void merge(
    uint *dstKey,
    uint *dstVal,
    uint *srcAKey,
    uint *srcAVal,
    uint *srcBKey,
    uint *srcBVal,
    uint lenA,
    uint lenB,
    uint sortDir
){
    checkOrder(srcAKey, lenA, sortDir);
    checkOrder(srcBKey, lenB, sortDir);

    for(uint i = 0; i < lenA; i++){
        uint dstPos = binarySearchExclusive(srcAKey[i], srcBKey, lenB, sortDir) + i;
        assert( dstPos < lenA + lenB );
        dstKey[dstPos] = srcAKey[i];
        dstVal[dstPos] = srcAVal[i];
    }

    for(uint i = 0; i < lenB; i++){
        uint dstPos = binarySearchInclusive(srcBKey[i], srcAKey, lenA, sortDir) + i;
        assert( dstPos < lenA + lenB );
        dstKey[dstPos] = srcBKey[i];
        dstVal[dstPos] = srcBVal[i];
    }
}
int main() {
    int A[N];
    for (int i = 0; i < N; i++)
      A[i] = i+1;
    shuffle(A, 10000);
    //print(A, N);

    clock_t t1 = clock();  
    insertSort(A, N);
    clock_t t2 = clock();

    checkOrder(A, N);
    printf("size of input: %d.\n", N);
    printf("running time: %f secs.\n", double(t2-t1) / CLOCKS_PER_SEC);

    return 0;
}
void Foam::interpolation2DTable<Type>::readTable()
{
    fileName fName(fileName_);
    fName.expand();

    // Read data from file
    reader_()(fName, *this);

    if (this->empty())
    {
        FatalErrorInFunction
            << "table read from " << fName << " is empty" << nl
            << exit(FatalError);
    }

    // Check that the data are in ascending order
    checkOrder();
}
Пример #4
0
void TestShapeAnimations::getTriggerEvent()
{
    MockDocument doc;
    KPrShapeAnimations animations(&doc);
    new ModelTest(&animations, this);
    createAnimationTree(&animations);
    // Test Trigger Event
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    // Test group
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::Group)).toInt(), 1);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::Group)).toInt(), 1);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::Group)).toInt(), 1);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::Group)).toInt(), 1);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::Group)).toInt(), 1);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::Group)).toInt(), 2);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::Group)).toInt(), 2);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::Group)).toInt(), 3);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::Group)).toInt(), 3);

    checkOrder(&animations);
}
Пример #5
0
void VTextBlockData::insertPreviewInfo(VPreviewInfo *p_info)
{
    bool inserted = false;
    for (auto it = m_previews.begin(); it != m_previews.end();) {
        VPreviewInfo *ele = *it;

        if (p_info->m_imageInfo < ele->m_imageInfo) {
            // Insert p_info here.
            m_previews.insert(it, p_info);
            inserted = true;
            break;
        } else if (p_info->m_imageInfo == ele->m_imageInfo) {
            // Update the timestamp.
            delete ele;
            *it = p_info;
            inserted = true;
            qDebug() << "update eixsting image's timestamp" << p_info->m_imageInfo.toString();
            break;
        } else if (p_info->m_imageInfo.intersect(ele->m_imageInfo)) {
            // The new one intersect with an old one.
            // Remove the old one.
            Q_ASSERT(ele->m_timeStamp < p_info->m_timeStamp);
            qDebug() << "remove intersecting old image" << ele->m_imageInfo.toString();
            delete ele;
            it = m_previews.erase(it);
        } else {
            ++it;
        }
    }

    if (!inserted) {
        // Append it.
        m_previews.append(p_info);
    }

    Q_ASSERT(checkOrder());
}
Пример #6
0
void TestShapeAnimations::setTriggerEvent()
{
    MockDocument doc;
    KPrShapeAnimations animations(&doc);
    new ModelTest(&animations, this);
    createAnimationTree(&animations);
    // From On click
    // To After Previous
    animations.setNodeType(m_animation[5], KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // To With Previous
    animations.setNodeType(m_animation[7], KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // From After Previous
    // To On click
    animations.setNodeType(m_animation[3], KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // To With previous
    animations.setNodeType(m_animation[6], KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // From with previous
    // To On click
    animations.setNodeType(m_animation[1], KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // To after previous
    animations.setNodeType(m_animation[6], KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    // From On click
    // To After Previous (with childrem)
    animations.setNodeType(m_animation[3], KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    //From On Click
    // To after previous (invald for the first animation)
    animations.setNodeType(m_animation[0], KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);

    //To with previous (invalid for the first item)
    animations.setNodeType(m_animation[0], KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(0, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(1, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::OnClick);
    QCOMPARE(animations.data(animations.index(2, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(3, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(4, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(5, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(6, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::AfterPrevious);
    QCOMPARE(animations.data(animations.index(7, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    QCOMPARE(animations.data(animations.index(8, KPrShapeAnimations::NodeType)).toInt(),
             (int)KPrShapeAnimation::WithPrevious);
    checkOrder(&animations);
    QVERIFY(animations.rowCount() == ANIMATIONS_COUNT);
}