Ejemplo n.º 1
0
void ProjectTester::startNotEarlier()
{
    Project project;
    project.setId( project.uniqueNodeId() );
    project.registerNodeId( &project );
    project.setConstraintStartTime( DateTime::fromString( "2011-01-01T00:00:00" ) );
    project.setConstraintEndTime( DateTime::fromString( "2011-01-12T00:00:00" ) );

    createCalendar( project );

    ResourceGroup *g = createWorkResources( project, 1 );

    Task *t = project.createTask();
    t->setName( "T1" );
    project.addTask( t, &project );
    t->estimate()->setUnit( Duration::Unit_h );
    t->estimate()->setExpectedEstimate( 1.0 );
    t->estimate()->setType( Estimate::Type_Effort );
    createRequest( t, g->resourceAt( 0 ) );

    t->setConstraint( Node::StartNotEarlier );
    t->setConstraintStartTime( DateTime::fromString( "2011-01-02T11:00:00" ) );

    ScheduleManager *sm = project.createScheduleManager( "Test Plan" );
    project.addScheduleManager( sm );

    QString s = "Calculate forward, Task: StartNotEarlier ------------------------------";
    qDebug()<<s;
    Debug::print( t, s );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

    Debug::print( &project, s );
    Debug::print( t, s );

    QVERIFY( t->startTime() >= t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 1, 0 ) );

    s = "Calculate forward, 2 Tasks ------------------------------";
    qDebug()<<s;

    Task *t2 = project.createTask();
    t2->setName( "T2" );
    project.addTask( t2, &project );
    t2->estimate()->setUnit( Duration::Unit_d );
    t2->estimate()->setExpectedEstimate( 7.0 );
    t2->estimate()->setType( Estimate::Type_Effort );

    createRequest( t2, g->resourceAt( 0 ) );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

    Debug::print( &project, s );
    Debug::print( t, s );
    Debug::print( t2, s );

    QVERIFY( t->startTime() >= t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 1, 0 ) );

    s = "Calculate backward, 2 Tasks ------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( true );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( project, sm, true/*nothread*/ );
    }

    Debug::print( &project, s );
    Debug::print( t, s );
    Debug::print( t2, s );
    Debug::printSchedulingLog( *sm, s );
    
    QVERIFY( t->startTime() >= t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 1, 0 ) );
}
Ejemplo n.º 2
0
void ProjectTester::oneTask()
{
    QDate today = QDate::fromString( "2012-02-01", Qt::ISODate );
    QDate tomorrow = today.addDays( 1 );
    QDate yesterday = today.addDays( -1 );
    QTime t1( 9, 0, 0 );
    QTime t2 ( 17, 0, 0 );
    int length = t1.msecsTo( t2 );

    Task *t = m_project->createTask();
    t->setName( "T1" );
    m_project->addTask( t, m_project );
    t->estimate()->setUnit( Duration::Unit_d );
    t->estimate()->setExpectedEstimate( 1.0 );
    t->estimate()->setType( Estimate::Type_Duration );

    ScheduleManager *sm = m_project->createScheduleManager( "Test Plan" );
    m_project->addScheduleManager( sm );
    

    QString s = "Calculate forward, Task: Fixed duration ------------------------------";
    qDebug()<<s;

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }
    Debug::printSchedulingLog( *sm, s );
    Debug::print( m_project, s );
    Debug::print( t, s );

    QCOMPARE( t->startTime(), m_project->startTime() );
    QCOMPARE( t->endTime(), DateTime(t->startTime().addDays( 1 )) );

    s = "Calculate forward, Task: Length --------------------------------------";
    qDebug()<<s;

    t->estimate()->setCalendar( m_calendar );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( m_calendar, s );
    Debug::print( m_project, s, true );

    QCOMPARE( t->startTime(), m_calendar->firstAvailableAfter( m_project->startTime(), m_project->endTime() ) );
    QCOMPARE( t->endTime(), DateTime( t->startTime().addMSecs( length ) ) );

    s = "Calculate forward, Task: Effort --------------------------------------";
    qDebug()<<s;

    ResourceGroup *g = new ResourceGroup();
    m_project->addResourceGroup( g );
    Resource *r = new Resource();
    r->setAvailableFrom( QDateTime( yesterday, QTime(), Qt::LocalTime ) );
    r->setCalendar( m_calendar );
    m_project->addResource( g, r );

    ResourceGroupRequest *gr = new ResourceGroupRequest( g );
    t->addRequest( gr );
    ResourceRequest *rr = new ResourceRequest( r, 100 );
    gr->addResourceRequest( rr );
    t->estimate()->setType( Estimate::Type_Effort );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), m_calendar->firstAvailableAfter( m_project->startTime(), m_project->endTime() ) );
    QCOMPARE( t->endTime(), DateTime( t->startTime().addMSecs( length ) ) );


    s = "Calculate forward, Task: MustStartOn --------------------------------------";
    qDebug()<<s;

    t->setConstraint( Node::MustStartOn );
    t->setConstraintStartTime( DateTime( tomorrow, t1 ) );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate backward, Task: MustStartOn --------------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( true );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );
    Debug::printSchedulingLog( *sm, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate backward, Task: StartNotEarlier --------------------------------------";
    qDebug()<<s;

    t->setConstraint( Node::StartNotEarlier );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate forward, Task: StartNotEarlier --------------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( false );
    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate forward, Task: MustFinishOn --------------------------------------";
    qDebug()<<s;

    t->setConstraint( Node::MustFinishOn );
    t->setConstraintEndTime( DateTime( tomorrow, t2 ) );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->endTime(), t->constraintEndTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate backward, Task: MustFinishOn --------------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( true );
    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->endTime(), t->constraintEndTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate backward, Task: FinishNotLater --------------------------------------";
    qDebug()<<s;

    t->setConstraint( Node::FinishNotLater );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->endTime(), t->constraintEndTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate forward, Task: FinishNotLater --------------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( false );
    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( m_project, s, true );

    QVERIFY( t->endTime() <= t->constraintEndTime() );
    QCOMPARE( t->endTime(), t->startTime() + Duration( 0, 8, 0 ) );

    s = "Calculate forward, Task: FixedInterval --------------------------------------";
    qDebug()<<s;

    t->setConstraint( Node ::FixedInterval );

    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->constraintEndTime() );

    s = "Calculate backward, Task: FixedInterval --------------------------------------";
    qDebug()<<s;

    sm->setSchedulingDirection( true );
    {
        KPlatoRCPSPlugin rcps( 0, QVariantList() );
        rcps.calculate( *m_project, sm, true/*nothread*/ );
    }

    Debug::print( t, s );

    QCOMPARE( t->startTime(), t->constraintStartTime() );
    QCOMPARE( t->endTime(), t->constraintEndTime() );

}