示例#1
0
template<typename MatrixType> void test_reference(const MatrixType& m) {
  typedef typename MatrixType::Scalar Scalar;
  enum { Flag          =  MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor};
  enum { TransposeFlag = !MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor};
  typename MatrixType::Index rows = m.rows(), cols=m.cols();
  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flag         > MatrixX;
  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, TransposeFlag> MatrixXT;
  // Dynamic reference:
  typedef Eigen::Ref<const MatrixX  > Ref;
  typedef Eigen::Ref<const MatrixXT > RefT;

  Ref r1(m);
  Ref r2(m.block(rows/3, cols/4, rows/2, cols/2));
  RefT r3(m.transpose());
  RefT r4(m.topLeftCorner(rows/2, cols/2).transpose());

  VERIFY_RAISES_ASSERT(RefT r5(m));
  VERIFY_RAISES_ASSERT(Ref r6(m.transpose()));
  VERIFY_RAISES_ASSERT(Ref r7(Scalar(2) * m));

  // Copy constructors shall also never malloc
  Ref r8 = r1;
  RefT r9 = r3;

  // Initializing from a compatible Ref shall also never malloc
  Eigen::Ref<const MatrixX, Unaligned, Stride<Dynamic, Dynamic> > r10=r8, r11=m;

  // Initializing from an incompatible Ref will malloc:
  typedef Eigen::Ref<const MatrixX, Aligned> RefAligned;
  VERIFY_RAISES_ASSERT(RefAligned r12=r10);
  VERIFY_RAISES_ASSERT(Ref r13=r10); // r10 has more dynamic strides

}
示例#2
0
bool testClassBasics() {
   bool passedTests=true;

   RealNumber a=1,b=-22,c=5+5,d(1),e(2,1),f(-3),g(2,3);

   if(passedTests)
      passedTests = (a == 1);
   if(passedTests)
      passedTests = (b == -22);
   if(passedTests)
      passedTests = (c == 10);
   if(passedTests)
      passedTests = (d == 1);
   if(passedTests)
      passedTests = (e == 2);
   if(passedTests)
      passedTests = (f == -3);
   if(passedTests)
      passedTests = (g != 2 && g != 3);

   RealNumber r1(20,30), r2(30,30), r3(30,20), r4(2,3), r5(3,2);
   RealNumber r6 = r4;
   if(passedTests)
      passedTests = (r1 == r4);
   if(passedTests)
      passedTests = (r5 == r3);
   if(passedTests)
      passedTests = (r2 != r3);
   if(passedTests)
      passedTests = (r1 != r3);
   if(passedTests)
      passedTests = (r6 == r4);

   return passedTests;
}
示例#3
0
文件: main.cpp 项目: ducthangho/3D
int test()
{
	//Test it correctly or not
	MyRectangle enclosingRect(40, 40);
	MyRectangle r1(15, 30);
	MyRectangle r2(20, 25);
	MyRectangle r5(10, 10);
	MyRectangle r4(20, 8);
	MyRectangle r3(9, 7);

	std::vector<MyRectangle> listRect;
	listRect.push_back(r1);
	listRect.push_back(r2);
	listRect.push_back(r3);
	listRect.push_back(r4);
	listRect.push_back(r5);

	Node node(0, 0, 40, 40);

	node.packWithNoPreSort(listRect, node);
	for (auto rect : listRect)
	{
		rect.print();
	}


std:cout << "here is packing alogorthim in codeproject\n";
	PackingAlogorithm pa;
	pa.pack(listRect, enclosingRect);
	for (auto rect : listRect)
	{
		rect.print();
	}
}
示例#4
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    DeviceViewer w;

    QTextCodec *codec = QTextCodec::codecForName("CP1251");
    QTextCodec::setCodecForLocale(codec);

    /****Add Test Devices ****/
    QList<MemRegion> memList;


    MemRegion r1("Region1", rand(),"EEPROM1",0,     256*256*14);
    MemRegion r2("Region2", rand(),"EEPROM2",256*256*14, 256*256*25);
    MemRegion r3("Region3", rand(),"EEPROM3",256*256*25, 256*256*40);
    MemRegion r4("Region4", rand(),"EEPROM1",256*256*40, 256*256*58);
    MemRegion r5("Region5", rand(),"EEPROM2",256*256*58, 256*256*80);
    MemRegion r6("Region6", rand(),"EEPROM3",256*256*80, 256*256*99);
    memList << r1 << r2 << r3 << r4 << r5 << r6;

    QList<Node> nodeList;
    for(int i = 0; i < 9; i++){
        Node n;
        n.serialNum = rand();
        n.info = QString("Something about node %1 of Device1").arg(i);
        nodeList << n;
    }
    Device dev1("Device1", "Т0000255", nodeList, memList);

    nodeList.clear();
    for(int i = 0; i < 6; i++){
        Node n;
        n.serialNum = rand();
        n.info = QString("Something about node %1 of Device2").arg(i);
        nodeList << n;
    }
    Device dev2("Device2", "И0000364", nodeList, memList);

    nodeList.clear();
    for(int i = 0; i < 3; i++){
        Node n;
        n.serialNum = rand();
        n.info = QString("Something about node %1 of Device3").arg(i);
        nodeList << n;
    }
    Device dev3("Device3", "Я0000982", nodeList, memList);

    w.addDevice(&dev1);
    w.addDevice(&dev2);
    w.addDevice(&dev3);

    /*************************/

    w.show();

    return a.exec();
}
示例#5
0
static void r6(SkLayerRasterizer* rast, SkPaint& p) {
    rast->addLayer(p);
    
    p.setAntiAlias(false);
    SkLayerRasterizer* rast2 = new SkLayerRasterizer;
    r5(rast2, p);
    p.setRasterizer(rast2)->unref();
    p.setXfermodeMode(SkXfermode::kClear_Mode);
    rast->addLayer(p);
}
示例#6
0
static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) {
    rastBuilder->addLayer(p);

    p.setAntiAlias(false);
    SkLayerRasterizer::Builder rastBuilder2;
    r5(&rastBuilder2, p);
    p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
    p.setXfermodeMode(SkXfermode::kClear_Mode);
    rastBuilder->addLayer(p);
}
示例#7
0
CCreateWaveDlg::CCreateWaveDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCreateWaveDlg::IDD, pParent)
{
//   IDD_CREATEWAV DIALOGEX 0, 0, 151, 173
   CRect rect(CPoint(0,0),CSize(151,173));
   MapDialogRect(&rect);
   setFixedSize(rect.Width(),rect.Height());
   
//       DEFPUSHBUTTON   "Begin",IDC_BEGIN,37,152,52,14
   CButton* mfc1 = new CButton(this);
   CRect r1(CPoint(37,152),CSize(52,14));
   MapDialogRect(&r1);
   mfc1->Create(_T("Begin"),0,r1,this,IDC_BEGIN);
   mfc1->setDefault(true);
   mfcToQtWidget.insert(IDC_BEGIN,mfc1);
   QObject::connect(mfc1,SIGNAL(clicked()),this,SLOT(begin_clicked()));
//       PUSHBUTTON      "Cancel",IDCANCEL,92,152,52,14
   CButton* mfc2 = new CButton(this);
   CRect r2(CPoint(92,152),CSize(52,14));
   MapDialogRect(&r2);
   mfc2->Create(_T("Cancel"),0,r2,this,IDCANCEL);
   mfcToQtWidget.insert(IDCANCEL,mfc2);
   QObject::connect(mfc2,SIGNAL(clicked()),this,SLOT(cancel_clicked()));
//       GROUPBOX        "Song length",IDC_STATIC,7,7,137,47
   CGroupBox* mfc3 = new CGroupBox(this);
   mfc3->setTitle("Song length");
   CRect r3(CPoint(7,7),CSize(137,47));
   MapDialogRect(&r3);
   mfc3->setGeometry(r3);
   // IDC_STATIC do not get added to MFC-to-Qt map.
//       CONTROL         "Play the song",IDC_RADIO_LOOP,"Button",BS_AUTORADIOBUTTON,14,20,59,10
   CButton* mfc4 = new CButton(this);
   CRect r4(CPoint(14,20),CSize(59,10));
   MapDialogRect(&r4);
   mfc4->Create(_T("Play the song"),BS_AUTORADIOBUTTON,r4,this,IDC_RADIO_LOOP);
   mfcToQtWidget.insert(IDC_RADIO_LOOP,mfc4);
   QObject::connect(mfc4,SIGNAL(clicked()),this,SLOT(radioLoop_clicked()));
//       CONTROL         "Play for",IDC_RADIO_TIME,"Button",BS_AUTORADIOBUTTON,14,38,41,10
   CButton* mfc5 = new CButton(this);
   CRect r5(CPoint(14,38),CSize(41,10));
   MapDialogRect(&r5);
   mfc5->Create(_T("Play for"),BS_AUTORADIOBUTTON,r5,this,IDC_RADIO_TIME);
   mfcToQtWidget.insert(IDC_RADIO_TIME,mfc5);
   QObject::connect(mfc5,SIGNAL(clicked()),this,SLOT(radioTime_clicked()));
//       EDITTEXT        IDC_TIMES,73,19,36,12,ES_AUTOHSCROLL
//       CONTROL         "",IDC_SPIN_LOOP,"msctls_updown32",UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,105,17,11,17
//       LTEXT           "time(s)",IDC_STATIC,115,20,21,10,SS_CENTERIMAGE
//       EDITTEXT        IDC_SECONDS,53,37,44,12,ES_AUTOHSCROLL
//       CONTROL         "",IDC_SPIN_TIME,"msctls_updown32",UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,93,36,11,14
//       LTEXT           "mm:ss",IDC_STATIC,106,38,21,10,SS_CENTERIMAGE
//       GROUPBOX        "Channels",IDC_STATIC,7,60,137,87
//       LISTBOX         IDC_CHANNELS,14,71,124,70,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
}
示例#8
0
void 
OpenSteer::
BoxObstacle::
findIntersectionWithVehiclePath (const AbstractVehicle& vehicle,
                                 PathIntersection& pi) const
{
    // abbreviations
    const float w = width; // dimensions
    const float h = height;
    const float d = depth;
    const Vec3 s = side (); // local space
    const Vec3 u = up ();
    const Vec3 f = forward ();
    const Vec3 p = position ();
    const Vec3 hw = s * (0.5f * width); // offsets for face centers
    const Vec3 hh = u * (0.5f * height);
    const Vec3 hd = f * (0.5f * depth);
    const seenFromState sf = seenFrom ();

    // the box's six rectangular faces
    RectangleObstacle r1 (w, h,  s,  u,  f, p + hd, sf); // front
    RectangleObstacle r2 (w, h, -s,  u, -f, p - hd, sf); // back
    RectangleObstacle r3 (d, h, -f,  u,  s, p + hw, sf); // side
    RectangleObstacle r4 (d, h,  f,  u, -s, p - hw, sf); // other side
    RectangleObstacle r5 (w, d,  s, -f,  u, p + hh, sf); // top
    RectangleObstacle r6 (w, d, -s, -f, -u, p - hh, sf); // bottom

    // group the six RectangleObstacle faces together
    ObstacleGroup faces;
    faces.push_back (&r1);
    faces.push_back (&r2);
    faces.push_back (&r3);
    faces.push_back (&r4);
    faces.push_back (&r5);
    faces.push_back (&r6);

    // find first intersection of vehicle path with group of six faces
    PathIntersection next;
    firstPathIntersectionWithObstacleGroup (vehicle, faces, pi, next);

    // when intersection found, adjust PathIntersection for the box case
    if (pi.intersect)
    {
        pi.obstacle = this;
        pi.steerHint = ((pi.surfacePoint - position ()).normalize () *
                        (pi.vehicleOutside ? 1.0f : -1.0f));
    }
}
  void patrate(double lungime, int nivel, CPunct &p, CVector v)
  {
	double x, y;
	p.getxy(x, y);

	CPunct p1(x - lungime / 6, y - lungime / 6);
	CPunct p2(x + lungime / 6, y + lungime / 6);

	  v.deseneaza(p1, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p1, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p2, lungime / 3);
	  v.rotatie(-90);
	  v.deseneaza(p2, lungime / 3);
	  v.rotatie(270);

	if (nivel > 0)
	{
		CPunct r0(x - lungime / 3, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r0, v);

		CPunct r1(x - lungime / 3, y);
		patrate(lungime / 3, nivel - 1, r1, v);

		CPunct r2(x - lungime / 3, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r2, v);

		CPunct r3(x, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r3, v);

		CPunct r5(x, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r5, v);

		CPunct r6(x + lungime / 3, y - lungime / 3);
		patrate(lungime / 3, nivel - 1, r6, v);

		CPunct r7(x + lungime / 3, y);
		patrate(lungime / 3, nivel - 1, r7, v);

		CPunct r8(x + lungime / 3, y + lungime / 3);
		patrate(lungime / 3, nivel - 1, r8, v);
	}
  }
示例#10
0
  void	InitEntities(void)
  {
    boost::shared_ptr<AEntitySprites> sprites = boost::make_shared<AEntitySprites>("./PICS/char_sprites.png",
										   GS_im::w_sprite,
										   GS_im::h_sprite);
    if (!(*sprites))
      {
	std::cerr << "Error loading/splitting sprites" << std::endl;
	exit(EXIT_FAILURE);      
      }

    GameSystem::ElementsVector	v;
    RatiolizedVector2D		r(.0f, .0f, 400.0f, 400.0f);
    RatiolizedVector2D		r1(.0f, .0f, -400.0f, 400.0f);
    RatiolizedVector2D		r2(.0f, .0f, 200.0f, 400.0f);
    RatiolizedVector2D		r3(.0f, .0f, 100.0f, 400.0f);
    RatiolizedVector2D		r5(.0f, .0f, 0.0f, 0.0f);

    v.push_back(new Entity(this->_app, sprites,
    			   200, 300, 50, 64, 64));
    // v.push_back(new Entity(this->_app, sprites,
    // 			   200, 300, 120, 64, 64));

    this->AddElement(*(v.begin() + 0));
    // this->AddElement(*(v.begin() + 1));

    // (*(v.begin() + 0))->SetBehaviour(boost::make_shared<TrackerBehaviour>(*(v.begin() + 0), *(v.begin() + 1)));
    (*(v.begin() + 0))->SetBehaviour(boost::make_shared<ControlableBehaviour>(*(v.begin() + 0), this));


    std::cout << "Controlable : " << *(v.begin() + 0) << std::endl;
    // std::cout << "Tracker : " << *(v.begin() + 1) << std::endl;


    // this->bindKeyEventsGroup(sf::Key::Right, v, &GameSystem::Break);
    // this->bindKeyEventsGroup(sf::Key::Left, v, &GameSystem::UnBreak);

    this->SetCameraController(new DisplayZone(this->_app, boost::make_shared<AEntitySprites>("./PICS/grey_bg.png",
											     GS::SCREEN_WIDTH,
											     GS::SCREEN_HEIGHT),
					      0, 0));

  }
void Vc4Shader::Emit_Prologue_PS()
{
    assert(this->uShaderType == D3D10_SB_PIXEL_SHADER);
    
    for (uint8_t i = 0, iRegUsed = 0; iRegUsed < this->cInput; i++)
    {
        Vc4Register raX = this->InputRegister[i / 4][i % 4];

        if (raX.GetFlags().valid)
        {
            assert(raX.GetMux() == VC4_QPU_ALU_REG_A || raX.GetMux() == VC4_QPU_ALU_REG_B);

            Vc4Register r0(VC4_QPU_ALU_R0, VC4_QPU_WADDR_ACC0);

            // Issue mul inputs (from varying) with ra15 (W).
            {
                Vc4Instruction Vc4Inst;
                Vc4Register varying(VC4_QPU_ALU_REG_B, VC4_QPU_RADDR_VERYING);
                Vc4Register ra15(VC4_QPU_ALU_REG_A, 15);
                Vc4Inst.Vc4_m_FMUL(r0, varying, ra15);
                Vc4Inst.Emit(CurrentStorage);
            }

            // Issue add r5 to each input data to complete interpolation.
            {
                Vc4Instruction Vc4Inst;
                Vc4Register r5(VC4_QPU_ALU_R5);
                Vc4Inst.Vc4_a_FADD(raX, r0, r5);
                Vc4Inst.Emit(CurrentStorage);
            }

            iRegUsed++;
        }
    }

    { // Emit a NOP with 'sbwait'
        Vc4Instruction Vc4Inst;
        Vc4Inst.Vc4_Sig(VC4_QPU_SIG_WAIT_FOR_SCOREBOARD);
        Vc4Inst.Emit(CurrentStorage);
    }
}
示例#12
0
bool QMLManager::checkDuration(DiveObjectHelper *myDive, struct dive *d, QString duration)
{
	if (myDive->duration() != duration) {
		int h = 0, m = 0, s = 0;
		QRegExp r1(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2[\\s,:]*(\\d*)\\s*%3").arg(tr("h")).arg(tr("min")).arg(tr("sec")), Qt::CaseInsensitive);
		QRegExp r2(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2").arg(tr("h")).arg(tr("min")), Qt::CaseInsensitive);
		QRegExp r3(QStringLiteral("(\\d*)\\s*%1").arg(tr("min")), Qt::CaseInsensitive);
		QRegExp r4(QStringLiteral("(\\d*):(\\d*):(\\d*)"));
		QRegExp r5(QStringLiteral("(\\d*):(\\d*)"));
		QRegExp r6(QStringLiteral("(\\d*)"));
		if (r1.indexIn(duration) >= 0) {
			h = r1.cap(1).toInt();
			m = r1.cap(2).toInt();
			s = r1.cap(3).toInt();
		} else if (r2.indexIn(duration) >= 0) {
			h = r2.cap(1).toInt();
			m = r2.cap(2).toInt();
		} else if (r3.indexIn(duration) >= 0) {
			m = r3.cap(1).toInt();
		} else if (r4.indexIn(duration) >= 0) {
			h = r4.cap(1).toInt();
			m = r4.cap(2).toInt();
			s = r4.cap(3).toInt();
		} else if (r5.indexIn(duration) >= 0) {
			h = r5.cap(1).toInt();
			m = r5.cap(2).toInt();
		} else if (r6.indexIn(duration) >= 0) {
			m = r6.cap(1).toInt();
		}
		d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
		if (same_string(d->dc.model, "manually added dive")) {
			free(d->dc.sample);
			d->dc.sample = 0;
			d->dc.samples = 0;
		} else {
			qDebug() << "changing the duration on a dive that wasn't manually added - Uh-oh";
		}
		return true;
	}
	return false;
}
示例#13
0
文件: rect.cpp 项目: jgrande/ginga
TEST( rect, aside ) {
	canvas::Rect r1(100,100,100,100);
	canvas::Rect r2(100,100,10,100);
	canvas::Rect r3(190,100,10,100);
	canvas::Rect r4(100,100,100,10);
	canvas::Rect r5(100,190,100,10);
	canvas::Rect r6(125,125,50,50);

	ASSERT_TRUE(r2.aside(r1));
	ASSERT_TRUE(r3.aside(r1));
	ASSERT_TRUE(r4.aside(r1));
	ASSERT_TRUE(r5.aside(r1));
	ASSERT_FALSE(r6.aside(r1));
	ASSERT_FALSE(r1.aside(r1));
	
	ASSERT_FALSE(r1.aside(r2));
	ASSERT_FALSE(r1.aside(r3));
	ASSERT_FALSE(r1.aside(r4));
	ASSERT_FALSE(r1.aside(r5));
	ASSERT_FALSE(r1.aside(r6));
}
示例#14
0
void alignedvector3()
{
  Scalar s1 = internal::random<Scalar>();
  Scalar s2 = internal::random<Scalar>();
  typedef Matrix<Scalar,3,1> RefType;
  typedef Matrix<Scalar,3,3> Mat33;
  typedef AlignedVector3<Scalar> FastType;
  RefType  r1(RefType::Random()), r2(RefType::Random()), r3(RefType::Random()),
           r4(RefType::Random()), r5(RefType::Random()), r6(RefType::Random());
  FastType f1(r1), f2(r2), f3(r3), f4(r4), f5(r5), f6(r6);
  Mat33 m1(Mat33::Random());
  
  VERIFY_IS_APPROX(f1,r1);
  VERIFY_IS_APPROX(f4,r4);

  VERIFY_IS_APPROX(f4+f1,r4+r1);
  VERIFY_IS_APPROX(f4-f1,r4-r1);
  VERIFY_IS_APPROX(f4+f1-f2,r4+r1-r2);
  VERIFY_IS_APPROX(f4+=f3,r4+=r3);
  VERIFY_IS_APPROX(f4-=f5,r4-=r5);
  VERIFY_IS_APPROX(f4-=f5+f1,r4-=r5+r1);
  VERIFY_IS_APPROX(f5+f1-s1*f2,r5+r1-s1*r2);
  VERIFY_IS_APPROX(f5+f1/s2-s1*f2,r5+r1/s2-s1*r2);
  
  VERIFY_IS_APPROX(m1*f4,m1*r4);
  VERIFY_IS_APPROX(f4.transpose()*m1,r4.transpose()*m1);
  
  VERIFY_IS_APPROX(f2.dot(f3),r2.dot(r3));
  VERIFY_IS_APPROX(f2.cross(f3),r2.cross(r3));
  VERIFY_IS_APPROX(f2.norm(),r2.norm());

  VERIFY_IS_APPROX(f2.normalized(),r2.normalized());

  VERIFY_IS_APPROX((f2+f1).normalized(),(r2+r1).normalized());
  
  f2.normalize();
  r2.normalize();
  VERIFY_IS_APPROX(f2,r2);
}
示例#15
0
void Ray2Tests::testRectIntersections()
{
  Rect2 rect(Vector2(1.0f, 1.0f), Vector2(4.0f, 4.0f));
  
  Ray2 r1(Vector2(-1.0f, 2.0f), Vector2(1.0f, 0.0f)); // Enter from left
  Ray2 r2(Vector2(5.0f, 2.0f), Vector2(-1.0f, 0.0f)); // right
  
  Ray2 r3(Vector2(2.0f, -1.0f), Vector2(0.0f, 1.0f)); // bottom  
  Ray2 r4(Vector2(2.0f, 5.0f), Vector2(0.0f, -1.0f)); // top    
  
  Ray2 r5(Vector2(-1.0f, 2.0f), Vector2(-1.0f, 0.0f)); // Outside left
  Ray2 r6(Vector2(5.0f, 2.0f), Vector2(1.0f, 0.0f)); // right
  
  Ray2 r7(Vector2(2.0f, -1.0f), Vector2(0.0f, -1.0f)); // bottom  
  Ray2 r8(Vector2(2.0f, 5.0f), Vector2(0.0f, 1.0f)); // top    
  
  Ray2 r9(Vector2(2.0f, 2.0f), Vector2(1.0f, 1.0f)); // Inside out    
  Ray2 r10(Vector2(2.0f, 3.0f), Vector2(1.0f, -2.0f)); // Inside out      
  Ray2 r11(Vector2(1.2f, 3.0f), Vector2(-1.0f, -2.0f)); // Inside out        
  
  Ray2 r12(Vector2(1.2f, 5.0f), Vector2(1.2f, 1.0f)); // Outside
    
  CPTAssert(r1.intersect(rect));
  CPTAssert(r2.intersect(rect));
  CPTAssert(r3.intersect(rect));
  CPTAssert(r4.intersect(rect));      
  
  CPTAssert(!r5.intersect(rect));
  CPTAssert(!r6.intersect(rect));
  CPTAssert(!r7.intersect(rect));
  CPTAssert(!r8.intersect(rect));      

  CPTAssert(r9.intersect(rect));  
  CPTAssert(r10.intersect(rect));  
  CPTAssert(r11.intersect(rect));      
  
  CPTAssert(!r12.intersect(rect));        
}
示例#16
0
文件: main.cpp 项目: ducthangho/3D
int test2()
{
	Node enclosingRect(0, 0, 40, 40);
	MyRectangle r1(15, 30);
	MyRectangle r2(20, 25);
	MyRectangle r3(9, 7);
	MyRectangle r4(20, 8);
	MyRectangle r5(10, 10);

	std::vector<MyRectangle> listRect;
	listRect.push_back(r1);
	listRect.push_back(r2);
	listRect.push_back(r3);
	listRect.push_back(r4);
	listRect.push_back(r5);

	Time tt;
	for (int i = 0; i < 20000; i++)
	{
		auto w = rand() % 30 + 1;
		auto h = rand() % 40 + 1;
		MyRectangle a(w, h);
		listRect.push_back(a);
	}
	std::cout << "Data creation time = " << tt.duration() << " ms" << std::endl;
	Time t;
	Node enclosingRect2(0,0,5000, 5000);
	enclosingRect2.pack(listRect, enclosingRect2);
	std::cout << "Execution time = " << t.duration() << " ms" << std::endl;

	for (auto& a : listRect)
	{
		a.print();
	}
	return 0;
}
示例#17
0
文件: main.cpp 项目: netp/esinf
int main (int argc, char * const argv[]) {    
	Vertice<int, int> v1( 1, 1 );
	Vertice<int, int> v2( 2, 2 );
	Vertice<int, int> v3( 3, 3 );
	Vertice<int, int> v4( 4, 4 );
	Vertice<int, int> v5( 5, 5 );

	Ramo<int, int> r1( 1, &v3 );
	Ramo<int, int> r2( 6, &v2 );
	Ramo<int, int> r3( 3, &v4 );
	Ramo<int, int> r4( 4, &v4 );
	Ramo<int, int> r5( 1, &v5 );
	Ramo<int, int> r6( 5, &v4 );

	ListAdjGrafo<int, int> g2;

	g2.juntar_vertice( v1.get_conteudo());
	g2.juntar_vertice( v2.get_conteudo());
	g2.juntar_vertice( v3.get_conteudo());
	g2.juntar_vertice( v4.get_conteudo());
	g2.juntar_vertice( v5.get_conteudo());
	
	g2.juntar_ramo(r1.get_conteudo(), v1.get_conteudo(), v3.get_conteudo());
	g2.juntar_ramo(r2.get_conteudo(), v1.get_conteudo(), v2.get_conteudo());
	g2.juntar_ramo(r3.get_conteudo(), v2.get_conteudo(), v4.get_conteudo());
	g2.juntar_ramo(r4.get_conteudo(), v3.get_conteudo(), v4.get_conteudo());
	g2.juntar_ramo(r1.get_conteudo(), v3.get_conteudo(), v5.get_conteudo());
	g2.juntar_ramo(r6.get_conteudo(), v5.get_conteudo(), v4.get_conteudo());

	g2.escreve_grafo();
	
	cout << endl
		<< "----------------------------------"
		<< endl
	;

	ListAdjGrafo<int, int> g;
	
	g.juntar_vertice( 1 );
	g.juntar_vertice( 2 );
	g.juntar_vertice( 3 );
	g.juntar_vertice( 4 );
	g.juntar_vertice( 5 );

	g.juntar_ramo(1, 1, 3 );
	g.juntar_ramo(6, 1, 2 );
	g.juntar_ramo(3, 2, 4 );
	g.juntar_ramo(4, 3, 4 );
	g.juntar_ramo(1, 3, 5);
	g.juntar_ramo(5, 5, 4);
	
	g.escreve_grafo();

	cout << endl
		<< "O grau de entrada do vertice "
		<< g.encontra_vertice_chave(3)
		<< g.grau_entrada(4)
	;
	
	cout << endl
		<< "----------------------------------"
		<< endl
	;
	
	g.visita_largura(v1);
		
}
示例#18
0
// update the dive and return the notes field, stripped of the HTML junk
void QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
			       QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes,
			       QString startpressure, QString endpressure, QString gasmix)
{
#define DROP_EMPTY_PLACEHOLDER(_s) if ((_s) == QLatin1Literal("--")) (_s).clear()

	DROP_EMPTY_PLACEHOLDER(location);
	DROP_EMPTY_PLACEHOLDER(duration);
	DROP_EMPTY_PLACEHOLDER(depth);
	DROP_EMPTY_PLACEHOLDER(airtemp);
	DROP_EMPTY_PLACEHOLDER(watertemp);
	DROP_EMPTY_PLACEHOLDER(suit);
	DROP_EMPTY_PLACEHOLDER(buddy);
	DROP_EMPTY_PLACEHOLDER(diveMaster);
	DROP_EMPTY_PLACEHOLDER(weight);
	DROP_EMPTY_PLACEHOLDER(gasmix);
	DROP_EMPTY_PLACEHOLDER(startpressure);
	DROP_EMPTY_PLACEHOLDER(endpressure);
	DROP_EMPTY_PLACEHOLDER(notes);

#undef DROP_EMPTY_PLACEHOLDER

	struct dive *d = get_dive_by_uniq_id(diveId.toInt());
	// notes comes back as rich text - let's convert this into plain text
	QTextDocument doc;
	doc.setHtml(notes);
	notes = doc.toPlainText();

	if (!d) {
		qDebug() << "don't touch this... no dive";
		return;
	}
	bool diveChanged = false;
	bool needResort = false;

	invalidate_dive_cache(d);
	if (date != get_dive_date_string(d->when)) {
		diveChanged = needResort = true;
		QDateTime newDate;
		// what a pain - Qt will not parse dates if the day of the week is incorrect
		// so if the user changed the date but didn't update the day of the week (most likely behavior, actually),
		// we need to make sure we don't try to parse that
		QString format(QString(prefs.date_format) + QChar(' ') + prefs.time_format);
		if (format.contains(QLatin1String("ddd")) || format.contains(QLatin1String("dddd"))) {
			QString dateFormatToDrop = format.contains(QLatin1String("ddd")) ? QStringLiteral("ddd") : QStringLiteral("dddd");
			QDateTime ts;
			QLocale loc = getLocale();
			ts.setMSecsSinceEpoch(d->when * 1000L);
			QString drop = loc.toString(ts.toUTC(), dateFormatToDrop);
			format.replace(dateFormatToDrop, "");
			date.replace(drop, "");
		}
		newDate = QDateTime::fromString(date, format);
		if (!newDate.isValid()) {
			qDebug() << "unable to parse date" << date << "with the given format" << format;
			QRegularExpression isoDate("\\d+-\\d+-\\d+[^\\d]+\\d+:\\d+");
			if (date.contains(isoDate)) {
				newDate = QDateTime::fromString(date, "yyyy-M-d h:m:s");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "yy-M-d h:m:s");
				if (newDate.isValid())
					goto parsed;
			}
			QRegularExpression isoDateNoSecs("\\d+-\\d+-\\d+[^\\d]+\\d+");
			if (date.contains(isoDateNoSecs)) {
				newDate = QDateTime::fromString(date, "yyyy-M-d h:m");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "yy-M-d h:m");
				if (newDate.isValid())
					goto parsed;
			}
			QRegularExpression usDate("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+:\\d+");
			if (date.contains(usDate)) {
				newDate = QDateTime::fromString(date, "M/d/yyyy h:m:s");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "M/d/yy h:m:s");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:m:sap");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:m:sap");
				if (newDate.isValid())
					goto parsed;
			}
			QRegularExpression usDateNoSecs("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+");
			if (date.contains(usDateNoSecs)) {
				newDate = QDateTime::fromString(date, "M/d/yyyy h:m");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "M/d/yy h:m");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:map");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:map");
				if (newDate.isValid())
					goto parsed;
			}
			QRegularExpression leDate("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+:\\d+");
			if (date.contains(leDate)) {
				newDate = QDateTime::fromString(date, "d.M.yyyy h:m:s");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "d.M.yy h:m:s");
				if (newDate.isValid())
					goto parsed;
			}
			QRegularExpression leDateNoSecs("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+");
			if (date.contains(leDateNoSecs)) {
				newDate = QDateTime::fromString(date, "d.M.yyyy h:m");
				if (newDate.isValid())
					goto parsed;
				newDate = QDateTime::fromString(date, "d.M.yy h:m");
				if (newDate.isValid())
					goto parsed;
			}
		}
parsed:
		if (newDate.isValid()) {
			// stupid Qt... two digit years are always 19xx - WTF???
			// so if adding a hundred years gets you into something before a year from now...
			// add a hundred years.
			if (newDate.addYears(100) < QDateTime::currentDateTime().addYears(1))
				newDate = newDate.addYears(100);
			d->dc.when = d->when = newDate.toMSecsSinceEpoch() / 1000 + gettimezoneoffset(newDate.toMSecsSinceEpoch() / 1000);
		} else {
			qDebug() << "none of our parsing attempts worked for the date string";
		}
	}
	struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
	char *locationtext = NULL;
	if (ds)
		locationtext = ds->name;
	if (!same_string(locationtext, qPrintable(location))) {
		diveChanged = true;
		// this is not ideal - and it's missing the gps information
		// but for now let's just create a new dive site
		ds = get_dive_site_by_uuid(create_dive_site(qPrintable(location), d->when));
		d->dive_site_uuid = ds->uuid;
	}
	if (!gps.isEmpty()) {
		QString gpsString = getCurrentPosition();
		if (gpsString != QString("waiting for the next gps location")) {
			qDebug() << "from commitChanges call to getCurrentPosition returns" << gpsString;
			double lat, lon;
			if (parseGpsText(qPrintable(gpsString), &lat, &lon)) {
				struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
				if (ds) {
					ds->latitude.udeg = lat * 1000000;
					ds->longitude.udeg = lon * 1000000;
				} else {
					degrees_t latData, lonData;
					latData.udeg = lat;
					lonData.udeg = lon;
					d->dive_site_uuid = create_dive_site_with_gps("new site", latData, lonData, d->when);
				}
				qDebug() << "set up dive site with new GPS data";
			}
		} else {
			qDebug() << "still don't have a position - will need to implement some sort of callback";
		}
	}
	if (get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")) != duration) {
		diveChanged = true;
		int h = 0, m = 0, s = 0;
		QRegExp r1(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2[\\s,:]*(\\d*)\\s*%3").arg(tr("h")).arg(tr("min")).arg(tr("sec")), Qt::CaseInsensitive);
		QRegExp r2(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2").arg(tr("h")).arg(tr("min")), Qt::CaseInsensitive);
		QRegExp r3(QStringLiteral("(\\d*)\\s*%1").arg(tr("min")), Qt::CaseInsensitive);
		QRegExp r4(QStringLiteral("(\\d*):(\\d*):(\\d*)"));
		QRegExp r5(QStringLiteral("(\\d*):(\\d*)"));
		QRegExp r6(QStringLiteral("(\\d*)"));
		if (r1.indexIn(duration) >= 0) {
			h = r1.cap(1).toInt();
			m = r1.cap(2).toInt();
			s = r1.cap(3).toInt();
		} else if (r2.indexIn(duration) >= 0) {
			h = r2.cap(1).toInt();
			m = r2.cap(2).toInt();
		} else if (r3.indexIn(duration) >= 0) {
			m = r3.cap(1).toInt();
		} else if (r4.indexIn(duration) >= 0) {
			h = r4.cap(1).toInt();
			m = r4.cap(2).toInt();
			s = r4.cap(3).toInt();
		} else if (r5.indexIn(duration) >= 0) {
			h = r5.cap(1).toInt();
			m = r5.cap(2).toInt();
		} else if (r6.indexIn(duration) >= 0) {
			m = r6.cap(1).toInt();
		}
		d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
		if (same_string(d->dc.model, "manually added dive")) {
			free(d->dc.sample);
			d->dc.sample = 0;
			d->dc.samples = 0;
		} else {
			qDebug() << "changing the duration on a dive that wasn't manually added - Uh-oh";
		}

	}
	if (get_depth_string(d->maxdepth.mm, true, true) != depth) {
		int depthValue = parseLengthToMm(depth);
		// the QML code should stop negative depth, but massively huge depth can make
		// the profile extremely slow or even run out of memory and crash, so keep
		// the depth <= 500m
		if (0 <= depthValue && depthValue <= 500000) {
			diveChanged = true;
			d->maxdepth.mm = depthValue;
			if (same_string(d->dc.model, "manually added dive")) {
				d->dc.maxdepth.mm = d->maxdepth.mm;
				free(d->dc.sample);
				d->dc.sample = 0;
				d->dc.samples = 0;
			}
		}
	}
	if (get_temperature_string(d->airtemp, true) != airtemp) {
		diveChanged = true;
		d->airtemp.mkelvin = parseTemperatureToMkelvin(airtemp);
	}
	if (get_temperature_string(d->watertemp, true) != watertemp) {
		diveChanged = true;
		d->watertemp.mkelvin = parseTemperatureToMkelvin(watertemp);
	}
	// not sure what we'd do if there was more than one weight system
	// defined - for now just ignore that case
	if (weightsystem_none((void *)&d->weightsystem[1])) {
		if (get_weight_string(d->weightsystem[0].weight, true) != weight) {
			diveChanged = true;
			d->weightsystem[0].weight.grams = parseWeightToGrams(weight);
		}
	}
	// start and end pressures for first cylinder only
	if (get_pressure_string(d->cylinder[0].start, true) != startpressure || get_pressure_string(d->cylinder[0].end, true) != endpressure) {
		diveChanged = true;
		d->cylinder[0].start.mbar = parsePressureToMbar(startpressure);
		d->cylinder[0].end.mbar = parsePressureToMbar(endpressure);
		if (d->cylinder[0].end.mbar > d->cylinder[0].start.mbar)
			d->cylinder[0].end.mbar = d->cylinder[0].start.mbar;
	}
	// gasmix for first cylinder
	if (get_gas_string(d->cylinder[0].gasmix) != gasmix) {
		int o2 = parseGasMixO2(gasmix);
		int he = parseGasMixHE(gasmix);
		// the QML code SHOULD only accept valid gas mixes, but just to make sure
		if (o2 >= 0 && o2 <= 1000 &&
		    he >= 0 && he <= 1000 &&
		    o2 + he <= 1000) {
			diveChanged = true;
			d->cylinder[0].gasmix.o2.permille = o2;
			d->cylinder[0].gasmix.he.permille = he;
		}
	}
	if (!same_string(d->suit, qPrintable(suit))) {
		diveChanged = true;
		free(d->suit);
		d->suit = strdup(qPrintable(suit));
	}
	if (!same_string(d->buddy, qPrintable(buddy))) {
		diveChanged = true;
		free(d->buddy);
		d->buddy = strdup(qPrintable(buddy));
	}
	if (!same_string(d->divemaster, qPrintable(diveMaster))) {
		diveChanged = true;
		free(d->divemaster);
		d->divemaster = strdup(qPrintable(diveMaster));
	}
	if (!same_string(d->notes, qPrintable(notes))) {
		diveChanged = true;
		free(d->notes);
		d->notes = strdup(qPrintable(notes));
	}
	// now that we have it all figured out, let's see what we need
	// to update
	DiveListModel *dm = DiveListModel::instance();
	int oldModelIdx = dm->getDiveIdx(d->id);
	int oldIdx = get_idx_by_uniq_id(d->id);
	if (needResort) {
		// we know that the only thing that might happen in a resort is that
		// this one dive moves to a different spot in the dive list
		sort_table(&dive_table);
		int newIdx = get_idx_by_uniq_id(d->id);
		if (newIdx != oldIdx) {
			DiveObjectHelper *newDive = new DiveObjectHelper(d);
			DiveListModel::instance()->removeDive(oldModelIdx);
			DiveListModel::instance()->insertDive(oldModelIdx - (newIdx - oldIdx), newDive);
			diveChanged = false; // because we already modified things
		}
	}
	if (diveChanged) {
		if (d->maxdepth.mm == d->dc.maxdepth.mm &&
		    d->maxdepth.mm > 0 &&
		    same_string(d->dc.model, "manually added dive") &&
		    d->dc.samples == 0) {
			// so we have depth > 0, a manually added dive and no samples
			// let's create an actual profile so the desktop version can work it
			// first clear out the mean depth (or the fake_dc() function tries
			// to be too clever
			d->meandepth.mm = d->dc.meandepth.mm = 0;
			d->dc = *fake_dc(&d->dc, true);
		}
		DiveListModel::instance()->updateDive(oldModelIdx, d);
	}
	if (diveChanged || needResort)
		// we no longer save right away, but only the next time the app is not
		// in the foreground (or when explicitly requested)
		mark_divelist_changed(true);

}
示例#19
0
int main (int, char**)
{
  UnitTest t (966);

  ISO8601d iso;
  std::string::size_type start = 0;
  t.notok (iso.parse ("foo", start), "foo --> false");
  t.is ((int)start, 0,               "foo[0]");

  // Determine local and UTC time.
  time_t now = time (NULL);
  struct tm* local_now = localtime (&now);
  int local_s = (local_now->tm_hour * 3600) +
                (local_now->tm_min  * 60)   +
                local_now->tm_sec;
  local_now->tm_hour  = 0;
  local_now->tm_min   = 0;
  local_now->tm_sec   = 0;
  local_now->tm_isdst = -1;
  time_t local = mktime (local_now);
  std::cout << "# local midnight today " << local << "\n";

  local_now->tm_year  = 2013 - 1900;
  local_now->tm_mon   = 12 - 1;
  local_now->tm_mday  = 6;
  local_now->tm_isdst = 0;
  time_t local6 = mktime (local_now);
  std::cout << "# local midnight 2013-12-06 " << local6 << "\n";

  local_now->tm_year  = 2013 - 1900;
  local_now->tm_mon   = 12 - 1;
  local_now->tm_mday  = 1;
  local_now->tm_isdst = 0;
  time_t local1 = mktime (local_now);
  std::cout << "# local midnight 2013-12-01 " << local1 << "\n";

  struct tm* utc_now = gmtime (&now);
  int utc_s = (utc_now->tm_hour * 3600) +
              (utc_now->tm_min  * 60)   +
              utc_now->tm_sec;
  utc_now->tm_hour  = 0;
  utc_now->tm_min   = 0;
  utc_now->tm_sec   = 0;
  utc_now->tm_isdst = -1;
  time_t utc = timegm (utc_now);
  std::cout << "# utc midnight today " << utc << "\n";

  utc_now->tm_year  = 2013 - 1900;
  utc_now->tm_mon   = 12 - 1;
  utc_now->tm_mday  = 6;
  utc_now->tm_isdst = 0;
  time_t utc6 = timegm (utc_now);
  std::cout << "# utc midnight 2013-12-06 " << utc6 << "\n";

  utc_now->tm_year  = 2013 - 1900;
  utc_now->tm_mon   = 12 - 1;
  utc_now->tm_mday  = 1;
  utc_now->tm_isdst = 0;
  time_t utc1 = timegm (utc_now);
  std::cout << "# utc midnight 2013-12-01 " << utc1 << "\n";

  int hms = (12 * 3600) + (34 * 60) + 56; // The time 12:34:56 in seconds.
  int hm  = (12 * 3600) + (34 * 60);      // The time 12:34:00 in seconds.
  int z   = 3600;                         // TZ offset.

  int ld = local_s > hms ? 86400 : 0;     // Local extra day if now > hms.
  int ud = utc_s   > hms ? 86400 : 0;     // UTC extra day if now > hms.
  std::cout << "# ld " << ld << "\n";
  std::cout << "# ud " << ud << "\n";

  // Aggregated.
  //            input                         i  Year  Mo  Wk WD  Jul  Da   Secs     TZ    UTC      time_t
  testParse (t, "12:34:56  ",                 8,    0,  0,  0, 0,   0,  0,   hms,     0, false, local+hms+ld );

  // time-ext
  //            input                         i  Year  Mo  Wk WD  Jul  Da   Secs     TZ    UTC      time_t
  testParse (t, "12:34:56Z",                  9,    0,  0,  0, 0,   0,  0,   hms,     0,  true, utc+hms+ud   );
  testParse (t, "12:34Z",                     6,    0,  0,  0, 0,   0,  0,    hm,     0,  true, utc+hm+ud    );
  testParse (t, "12:34:56+01:00",            14,    0,  0,  0, 0,   0,  0,   hms,  3600, false, utc+hms-z+ud );
  testParse (t, "12:34:56+01",               11,    0,  0,  0, 0,   0,  0,   hms,  3600, false, utc+hms-z+ud );
  testParse (t, "12:34+01:00",               11,    0,  0,  0, 0,   0,  0,    hm,  3600, false, utc+hm-z+ud  );
  testParse (t, "12:34+01",                   8,    0,  0,  0, 0,   0,  0,    hm,  3600, false, utc+hm-z+ud  );
  testParse (t, "12:34:56",                   8,    0,  0,  0, 0,   0,  0,   hms,     0, false, local+hms+ld );
  testParse (t, "12:34",                      5,    0,  0,  0, 0,   0,  0,    hm,     0, false, local+hm+ld  );

  // datetime-ext
  //            input                         i  Year  Mo  Wk WD  Jul  Da   Secs     TZ    UTC      time_t
  testParse (t, "2013-12-06",                10, 2013, 12,  0, 0,   0,  6,     0,     0, false, local6    );
  testParse (t, "2013-340",                   8, 2013,  0,  0, 0, 340,  0,     0,     0, false, local6    );
  testParse (t, "2013-W49-5",                10, 2013,  0, 49, 5,   0,  0,     0,     0, false, local6    );
  testParse (t, "2013-W49",                   8, 2013,  0, 49, 0,   0,  0,     0,     0, false, local1    );

  testParse (t, "2013-12-06T12:34:56",       19, 2013, 12,  0, 0,   0,  6,   hms,     0, false, local6+hms);
  testParse (t, "2013-12-06T12:34",          16, 2013, 12,  0, 0,   0,  6,    hm,     0, false, local6+hm );
  testParse (t, "2013-340T12:34:56",         17, 2013,  0,  0, 0, 340,  0,   hms,     0, false, local6+hms);
  testParse (t, "2013-340T12:34",            14, 2013,  0,  0, 0, 340,  0,    hm,     0, false, local6+hm );
  testParse (t, "2013-W49-5T12:34:56",       19, 2013,  0, 49, 5,   0,  0,   hms,     0, false, local6+hms);
  testParse (t, "2013-W49-5T12:34",          16, 2013,  0, 49, 5,   0,  0,    hm,     0, false, local6+hm );
  testParse (t, "2013-W49T12:34:56",         17, 2013,  0, 49, 0,   0,  0,   hms,     0, false, local1+hms);
  testParse (t, "2013-W49T12:34",            14, 2013,  0, 49, 0,   0,  0,    hm,     0, false, local1+hm );

  testParse (t, "2013-12-06T12:34:56Z",      20, 2013, 12,  0, 0,   0,  6,   hms,     0,  true, utc6+hms  );
  testParse (t, "2013-12-06T12:34Z",         17, 2013, 12,  0, 0,   0,  6,    hm,     0,  true, utc6+hm   );
  testParse (t, "2013-340T12:34:56Z",        18, 2013,  0,  0, 0, 340,  0,   hms,     0,  true, utc6+hms  );
  testParse (t, "2013-340T12:34Z",           15, 2013,  0,  0, 0, 340,  0,    hm,     0,  true, utc6+hm   );
  testParse (t, "2013-W49-5T12:34:56Z",      20, 2013,  0, 49, 5,   0,  0,   hms,     0,  true, utc6+hms  );
  testParse (t, "2013-W49-5T12:34Z",         17, 2013,  0, 49, 5,   0,  0,    hm,     0,  true, utc6+hm   );
  testParse (t, "2013-W49T12:34:56Z",        18, 2013,  0, 49, 0,   0,  0,   hms,     0,  true, utc1+hms  );
  testParse (t, "2013-W49T12:34Z",           15, 2013,  0, 49, 0,   0,  0,    hm,     0,  true, utc1+hm   );

  testParse (t, "2013-12-06T12:34:56+01:00", 25, 2013, 12,  0, 0,   0,  6,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-12-06T12:34:56+01",    22, 2013, 12,  0, 0,   0,  6,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-12-06T12:34:56-01:00", 25, 2013, 12,  0, 0,   0,  6,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-12-06T12:34:56-01",    22, 2013, 12,  0, 0,   0,  6,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-12-06T12:34+01:00",    22, 2013, 12,  0, 0,   0,  6,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-12-06T12:34+01",       19, 2013, 12,  0, 0,   0,  6,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-12-06T12:34-01:00",    22, 2013, 12,  0, 0,   0,  6,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-12-06T12:34-01",       19, 2013, 12,  0, 0,   0,  6,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-340T12:34:56+01:00",   23, 2013,  0,  0, 0, 340,  0,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-340T12:34:56+01",      20, 2013,  0,  0, 0, 340,  0,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-340T12:34:56-01:00",   23, 2013,  0,  0, 0, 340,  0,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-340T12:34:56-01",      20, 2013,  0,  0, 0, 340,  0,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-340T12:34+01:00",      20, 2013,  0,  0, 0, 340,  0,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-340T12:34+01",         17, 2013,  0,  0, 0, 340,  0,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-340T12:34-01:00",      20, 2013,  0,  0, 0, 340,  0,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-340T12:34-01",         17, 2013,  0,  0, 0, 340,  0,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-W49-5T12:34:56+01:00", 25, 2013,  0, 49, 5,   0,  0,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-W49-5T12:34:56+01",    22, 2013,  0, 49, 5,   0,  0,   hms,  3600, false, utc6+hms-z);
  testParse (t, "2013-W49-5T12:34:56-01:00", 25, 2013,  0, 49, 5,   0,  0,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-W49-5T12:34:56-01",    22, 2013,  0, 49, 5,   0,  0,   hms, -3600, false, utc6+hms+z);
  testParse (t, "2013-W49-5T12:34+01:00",    22, 2013,  0, 49, 5,   0,  0,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-W49-5T12:34+01",       19, 2013,  0, 49, 5,   0,  0,    hm,  3600, false, utc6+hm-z );
  testParse (t, "2013-W49-5T12:34-01:00",    22, 2013,  0, 49, 5,   0,  0,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-W49-5T12:34-01",       19, 2013,  0, 49, 5,   0,  0,    hm, -3600, false, utc6+hm+z );
  testParse (t, "2013-W49T12:34:56+01:00",   23, 2013,  0, 49, 0,   0,  0,   hms,  3600, false, utc1+hms-z);
  testParse (t, "2013-W49T12:34:56+01",      20, 2013,  0, 49, 0,   0,  0,   hms,  3600, false, utc1+hms-z);
  testParse (t, "2013-W49T12:34:56-01:00",   23, 2013,  0, 49, 0,   0,  0,   hms, -3600, false, utc1+hms+z);
  testParse (t, "2013-W49T12:34:56-01",      20, 2013,  0, 49, 0,   0,  0,   hms, -3600, false, utc1+hms+z);
  testParse (t, "2013-W49T12:34+01:00",      20, 2013,  0, 49, 0,   0,  0,    hm,  3600, false, utc1+hm-z );
  testParse (t, "2013-W49T12:34+01",         17, 2013,  0, 49, 0,   0,  0,    hm,  3600, false, utc1+hm-z );
  testParse (t, "2013-W49T12:34-01:00",      20, 2013,  0, 49, 0,   0,  0,    hm, -3600, false, utc1+hm+z );
  testParse (t, "2013-W49T12:34-01",         17, 2013,  0, 49, 0,   0,  0,    hm, -3600, false, utc1+hm+z );

  // The only non-extended forms.
  testParse (t, "20131206T123456Z",          16, 2013, 12,  0, 0,   0,  6,   hms,     0,  true, utc6+hms  );
  testParse (t, "20131206T123456",           15, 2013, 12,  0, 0,   0,  6,   hms,     0, false, local6+hms);

  try
  {
    ISO8601d now;
    t.ok (now.toISO ().find ("1969") == std::string::npos, "'now' != 1969");

    ISO8601d yesterday;
    yesterday -= 86400;
    ISO8601d tomorrow;
    tomorrow += 86400;

    t.ok    (yesterday <= now,       "yesterday <= now");
    t.ok    (yesterday <  now,       "yesterday < now");
    t.notok (yesterday == now,       "!(yesterday == now)");
    t.ok    (yesterday != now,       "yesterday != now");
    t.ok    (now       >= yesterday, "now >= yesterday");
    t.ok    (now       >  yesterday, "now > yesterday");

    t.ok    (tomorrow >= now,        "tomorrow >= now");
    t.ok    (tomorrow >  now,        "tomorrow > now");
    t.notok (tomorrow == now,        "!(tomorrow == now)");
    t.ok    (tomorrow != now,        "tomorrow != now");
    t.ok    (now      <= tomorrow,   "now <= tomorrow");
    t.ok    (now      <  tomorrow,   "now < tomorrow");

    // ctor ("now")
    context.config.set ("weekstart", "monday");
    ISO8601d relative_now;
    t.ok (relative_now.sameHour (now),  "ISO8601d ().sameHour (ISO8601d (now))");
    t.ok (relative_now.sameDay (now),   "ISO8601d ().sameDay (ISO8601d (now))");
    t.ok (relative_now.sameWeek (now),  "ISO8601d ().sameWeek (ISO8601d (now))");
    t.ok (relative_now.sameMonth (now), "ISO8601d ().sameMonth (ISO8601d (now))");
    t.ok (relative_now.sameYear (now),  "ISO8601d ().sameYear (ISO8601d (now))");

    // Loose comparisons.
    ISO8601d left ("7/4/2008", "m/d/Y");
    ISO8601d comp1 ("7/4/2008", "m/d/Y");
    t.ok (left.sameDay   (comp1), "7/4/2008 is on the same day as 7/4/2008");
    t.ok (left.sameWeek  (comp1), "7/4/2008 is on the same week as 7/4/2008");
    t.ok (left.sameMonth (comp1), "7/4/2008 is in the same month as 7/4/2008");
    t.ok (left.sameYear  (comp1), "7/4/2008 is in the same year as 7/4/2008");

    ISO8601d comp2 ("7/5/2008", "m/d/Y");
    t.notok (left.sameDay   (comp2), "7/4/2008 is not on the same day as 7/5/2008");
    t.ok    (left.sameMonth (comp2), "7/4/2008 is in the same month as 7/5/2008");
    t.ok    (left.sameYear  (comp2), "7/4/2008 is in the same year as 7/5/2008");

    ISO8601d comp3 ("8/4/2008", "m/d/Y");
    t.notok (left.sameDay   (comp3), "7/4/2008 is not on the same day as 8/4/2008");
    t.notok (left.sameWeek  (comp3), "7/4/2008 is not on the same week as 8/4/2008");
    t.notok (left.sameMonth (comp3), "7/4/2008 is not in the same month as 8/4/2008");
    t.ok    (left.sameYear  (comp3), "7/4/2008 is in the same year as 8/4/2008");

    ISO8601d comp4 ("7/4/2009", "m/d/Y");
    t.notok (left.sameDay   (comp4), "7/4/2008 is not on the same day as 7/4/2009");
    t.notok (left.sameWeek  (comp3), "7/4/2008 is not on the same week as 7/4/2009");
    t.notok (left.sameMonth (comp4), "7/4/2008 is not in the same month as 7/4/2009");
    t.notok (left.sameYear  (comp4), "7/4/2008 is not in the same year as 7/4/2009");

    // Validity.
    t.ok    (ISO8601d::valid (2, 29, 2008), "valid: 2/29/2008");
    t.notok (ISO8601d::valid (2, 29, 2007), "invalid: 2/29/2007");

    t.ok    (ISO8601d::valid ("2/29/2008", "m/d/Y"), "valid: 2/29/2008");
    t.notok (ISO8601d::valid ("2/29/2007", "m/d/Y"), "invalid: 2/29/2007");

    t.ok    (ISO8601d::valid (366, 2008), "valid: 366 days in 2008");
    t.notok (ISO8601d::valid (366, 2007), "invalid: 366 days in 2007");

    // Time validity.
    t.ok    (ISO8601d::valid (2, 28, 2010,  0,  0,  0), "valid 2/28/2010 0:00:00");
    t.ok    (ISO8601d::valid (2, 28, 2010, 23, 59, 59), "valid 2/28/2010 23:59:59");
    t.notok (ISO8601d::valid (2, 28, 2010, 24, 59, 59), "valid 2/28/2010 24:59:59");
    t.notok (ISO8601d::valid (2, 28, 2010, -1,  0,  0), "valid 2/28/2010 -1:00:00");

    // Leap year.
    t.ok    (ISO8601d::leapYear (2008), "2008 is a leap year");
    t.notok (ISO8601d::leapYear (2007), "2007 is not a leap year");
    t.ok    (ISO8601d::leapYear (2000), "2000 is a leap year");
    t.notok (ISO8601d::leapYear (1900), "1900 is not a leap year");

    // Days in year.
    t.is (ISO8601d::daysInYear (2016), 366, "366 days in 2016");
    t.is (ISO8601d::daysInYear (2015), 365, "365 days in 2015");

    // Days in month.
    t.is (ISO8601d::daysInMonth (2, 2008), 29, "29 days in February 2008");
    t.is (ISO8601d::daysInMonth (2, 2007), 28, "28 days in February 2007");

    // Names.
    t.is (ISO8601d::monthName (1), "January",   "1 = January");
    t.is (ISO8601d::monthName (2), "February",  "2 = February");
    t.is (ISO8601d::monthName (3), "March",     "3 = March");
    t.is (ISO8601d::monthName (4), "April",     "4 = April");
    t.is (ISO8601d::monthName (5), "May",       "5 = May");
    t.is (ISO8601d::monthName (6), "June",      "6 = June");
    t.is (ISO8601d::monthName (7), "July",      "7 = July");
    t.is (ISO8601d::monthName (8), "August",    "8 = August");
    t.is (ISO8601d::monthName (9), "September", "9 = September");
    t.is (ISO8601d::monthName (10), "October",  "10 = October");
    t.is (ISO8601d::monthName (11), "November", "11 = November");
    t.is (ISO8601d::monthName (12), "December", "12 = December");

    // Names.
    t.is (ISO8601d::monthOfYear ("January"),   1,  "January   =  1");
    t.is (ISO8601d::monthOfYear ("February"),  2,  "February  =  2");
    t.is (ISO8601d::monthOfYear ("March"),     3,  "March     =  3");
    t.is (ISO8601d::monthOfYear ("April"),     4,  "April     =  4");
    t.is (ISO8601d::monthOfYear ("May"),       5,  "May       =  5");
    t.is (ISO8601d::monthOfYear ("June"),      6,  "June      =  6");
    t.is (ISO8601d::monthOfYear ("July"),      7,  "July      =  7");
    t.is (ISO8601d::monthOfYear ("August"),    8,  "August    =  8");
    t.is (ISO8601d::monthOfYear ("September"), 9,  "September =  9");
    t.is (ISO8601d::monthOfYear ("October"),   10, "October   = 10");
    t.is (ISO8601d::monthOfYear ("November"),  11, "November  = 11");
    t.is (ISO8601d::monthOfYear ("December"),  12, "December  = 12");

    t.is (ISO8601d::dayName (0), "Sunday",    "0 == Sunday");
    t.is (ISO8601d::dayName (1), "Monday",    "1 == Monday");
    t.is (ISO8601d::dayName (2), "Tuesday",   "2 == Tuesday");
    t.is (ISO8601d::dayName (3), "Wednesday", "3 == Wednesday");
    t.is (ISO8601d::dayName (4), "Thursday",  "4 == Thursday");
    t.is (ISO8601d::dayName (5), "Friday",    "5 == Friday");
    t.is (ISO8601d::dayName (6), "Saturday",  "6 == Saturday");

    t.is (ISO8601d::dayOfWeek ("SUNDAY"),    0, "SUNDAY == 0");
    t.is (ISO8601d::dayOfWeek ("sunday"),    0, "sunday == 0");
    t.is (ISO8601d::dayOfWeek ("Sunday"),    0, "Sunday == 0");
    t.is (ISO8601d::dayOfWeek ("Monday"),    1, "Monday == 1");
    t.is (ISO8601d::dayOfWeek ("Tuesday"),   2, "Tuesday == 2");
    t.is (ISO8601d::dayOfWeek ("Wednesday"), 3, "Wednesday == 3");
    t.is (ISO8601d::dayOfWeek ("Thursday"),  4, "Thursday == 4");
    t.is (ISO8601d::dayOfWeek ("Friday"),    5, "Friday == 5");
    t.is (ISO8601d::dayOfWeek ("Saturday"),  6, "Saturday == 6");

    ISO8601d happyNewYear (1, 1, 2008);
    t.is (happyNewYear.dayOfWeek (), 2, "1/1/2008 == Tuesday");
    t.is (happyNewYear.month (),     1, "1/1/2008 == January");
    t.is (happyNewYear.day (),       1, "1/1/2008 == 1");
    t.is (happyNewYear.year (),   2008, "1/1/2008 == 2008");

    t.is (happyNewYear.toString (), "1/1/2008", "toString 1/1/2008");

    int m, d, y;
    happyNewYear.toMDY (m, d, y);
    t.is (m, 1, "1/1/2008 == January");
    t.is (d, 1, "1/1/2008 == 1");
    t.is (y, 2008, "1/1/2008 == 2008");

    ISO8601d epoch (9, 8, 2001);
    t.ok ((int)epoch.toEpoch () < 1000000000, "9/8/2001 < 1,000,000,000");
    epoch += 172800;
    t.ok ((int)epoch.toEpoch () > 1000000000, "9/10/2001 > 1,000,000,000");

    ISO8601d fromEpoch (epoch.toEpoch ());
    t.is (fromEpoch.toString (), epoch.toString (), "ctor (time_t)");

    ISO8601d iso (1000000000);
    t.is (iso.toISO (), "20010909T014640Z", "1,000,000,000 -> 20010909T014640Z");

    // Quantization.
    ISO8601d quant (1234526400);
    t.is (quant.startOfDay ().toString ("YMDHNS"),   "20090213000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/13/2009 0:00:00");
    t.is (quant.startOfWeek ().toString ("YMDHNS"),  "20090208000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/8/2009 0:00:00");
    t.is (quant.startOfMonth ().toString ("YMDHNS"), "20090201000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/1/2009 0:00:00");
    t.is (quant.startOfYear ().toString ("YMDHNS"),  "20090101000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 1/1/2009 0:00:00");

    // Format parsing.
    ISO8601d fromString1 ("1/1/2008", "m/d/Y");
    t.is (fromString1.month (),   1, "ctor (std::string) -> m");
    t.is (fromString1.day (),     1, "ctor (std::string) -> d");
    t.is (fromString1.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString2 ("20080101", "YMD");
    t.is (fromString2.month (),   1, "ctor (std::string) -> m");
    t.is (fromString2.day (),     1, "ctor (std::string) -> d");
    t.is (fromString2.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString3 ("12/31/2007", "m/d/Y");
    t.is (fromString3.month (),  12, "ctor (std::string) -> m");
    t.is (fromString3.day (),    31, "ctor (std::string) -> d");
    t.is (fromString3.year (), 2007, "ctor (std::string) -> y");

    ISO8601d fromString4 ("01/01/2008", "m/d/Y");
    t.is (fromString4.month (),   1, "ctor (std::string) -> m");
    t.is (fromString4.day (),     1, "ctor (std::string) -> d");
    t.is (fromString4.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString5 ("Tue 05 Feb 2008 (06)", "a D b Y (V)");
    t.is (fromString5.month (),   2, "ctor (std::string) -> m");
    t.is (fromString5.day (),     5, "ctor (std::string) -> d");
    t.is (fromString5.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString6 ("Tuesday, February 5, 2008", "A, B d, Y");
    t.is (fromString6.month (),   2, "ctor (std::string) -> m");
    t.is (fromString6.day (),     5, "ctor (std::string) -> d");
    t.is (fromString6.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString7 ("w01 Tue 2008-01-01", "wV a Y-M-D");
    t.is (fromString7.month (),   1, "ctor (std::string) -> m");
    t.is (fromString7.day (),     1, "ctor (std::string) -> d");
    t.is (fromString7.year (), 2008, "ctor (std::string) -> y");

    ISO8601d fromString8 ("6/7/2010 1:23:45",  "m/d/Y h:N:S");
    t.is (fromString8.month (),     6, "ctor (std::string) -> m");
    t.is (fromString8.day (),       7, "ctor (std::string) -> d");
    t.is (fromString8.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString8.hour (),      1, "ctor (std::string) -> h");
    t.is (fromString8.minute (),   23, "ctor (std::string) -> N");
    t.is (fromString8.second (),   45, "ctor (std::string) -> S");

    ISO8601d fromString9 ("6/7/2010 01:23:45", "m/d/Y H:N:S");
    t.is (fromString9.month (),     6, "ctor (std::string) -> m");
    t.is (fromString9.day (),       7, "ctor (std::string) -> d");
    t.is (fromString9.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString9.hour (),      1, "ctor (std::string) -> h");
    t.is (fromString9.minute (),   23, "ctor (std::string) -> N");
    t.is (fromString9.second (),   45, "ctor (std::string) -> S");

    ISO8601d fromString10 ("6/7/2010 12:34:56", "m/d/Y H:N:S");
    t.is (fromString10.month (),     6, "ctor (std::string) -> m");
    t.is (fromString10.day (),       7, "ctor (std::string) -> d");
    t.is (fromString10.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString10.hour (),     12, "ctor (std::string) -> h");
    t.is (fromString10.minute (),   34, "ctor (std::string) -> N");
    t.is (fromString10.second (),   56, "ctor (std::string) -> S");

    // Day of year
    t.is (ISO8601d ("1/1/2011",   "m/d/Y").dayOfYear (),   1, "dayOfYear (1/1/2011)   ->   1");
    t.is (ISO8601d ("5/1/2011",   "m/d/Y").dayOfYear (), 121, "dayOfYear (5/1/2011)   -> 121");
    t.is (ISO8601d ("12/31/2011", "m/d/Y").dayOfYear (), 365, "dayOfYear (12/31/2011) -> 365");

    // Relative dates.
    ISO8601d r1 ("today");
    t.ok (r1.sameDay (now), "today = now");

    ISO8601d r4 ("sunday");
    if (now.dayOfWeek () >= 0)
      t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday");
    else
      t.ok (r4.sameDay (now + (0 - now.dayOfWeek ()) * 86400), "next sunday");;

    ISO8601d r5 ("monday");
    if (now.dayOfWeek () >= 1)
      t.ok (r5.sameDay (now + (1 - now.dayOfWeek () + 7) * 86400), "next monday");
    else
      t.ok (r5.sameDay (now + (1 - now.dayOfWeek ()) * 86400), "next monday");;

    ISO8601d r6 ("tuesday");
    if (now.dayOfWeek () >= 2)
      t.ok (r6.sameDay (now + (2 - now.dayOfWeek () + 7) * 86400), "next tuesday");
    else
      t.ok (r6.sameDay (now + (2 - now.dayOfWeek ()) * 86400), "next tuesday");;

    ISO8601d r7 ("wednesday");
    if (now.dayOfWeek () >= 3)
      t.ok (r7.sameDay (now + (3 - now.dayOfWeek () + 7) * 86400), "next wednesday");
    else
      t.ok (r7.sameDay (now + (3 - now.dayOfWeek ()) * 86400), "next wednesday");;

    ISO8601d r8 ("thursday");
    if (now.dayOfWeek () >= 4)
      t.ok (r8.sameDay (now + (4 - now.dayOfWeek () + 7) * 86400), "next thursday");
    else
      t.ok (r8.sameDay (now + (4 - now.dayOfWeek ()) * 86400), "next thursday");;

    ISO8601d r9 ("friday");
    if (now.dayOfWeek () >= 5)
      t.ok (r9.sameDay (now + (5 - now.dayOfWeek () + 7) * 86400), "next friday");
    else
      t.ok (r9.sameDay (now + (5 - now.dayOfWeek ()) * 86400), "next friday");;

    ISO8601d r10 ("saturday");
    if (now.dayOfWeek () >= 6)
      t.ok (r10.sameDay (now + (6 - now.dayOfWeek () + 7) * 86400), "next saturday");
    else
      t.ok (r10.sameDay (now + (6 - now.dayOfWeek ()) * 86400), "next saturday");;

    ISO8601d r11 ("eow");
    t.ok (r11 < now + (8 * 86400), "eow < 7 days away");

    ISO8601d r12 ("eocw");
    t.ok (r12 > now - (8 * 86400), "eocw < 7 days in the past");

    ISO8601d r13 ("eom");
    t.ok (r13.sameMonth (now), "eom in same month as now");

    ISO8601d r14 ("eocm");
    t.ok (r14.sameMonth (now), "eocm in same month as now");

    ISO8601d r15 ("eoy");
    t.ok (r15.sameYear (now), "eoy in same year as now");

    ISO8601d r16 ("sow");
    t.ok (r16 < now + (8 * 86400), "sow < 7 days away");

    ISO8601d r23 ("socw");
    t.ok (r23 > now - (8 * 86400), "sow < 7 days in the past");

    ISO8601d r17 ("som");
    t.notok (r17.sameMonth (now), "som not in same month as now");

    ISO8601d r18 ("socm");
    t.ok (r18.sameMonth (now), "socm in same month as now");

    ISO8601d r19 ("soy");
    t.notok (r19.sameYear (now), "soy not in same year as now");

    ISO8601d first ("1st");
    t.notok (first.sameMonth (now), "1st not in same month as now");
    t.is (first.day (),   1, "1st day is 1");

    ISO8601d later ("later");
    t.is (later.month (),   1, "later -> m = 1");
    t.is (later.day (),    18, "later -> d = 18");
    t.is (later.year (), 2038, "later -> y = 2038");

    // Quarters
    ISO8601d soq ("soq");
    ISO8601d eoq ("eoq");
    t.is (soq.day (),  1,      "soq is the first day of a month");
    t.is (eoq.day () / 10,  3, "eoq is the 30th or 31th of a month");
    t.is (soq.month () % 3, 1, "soq month is 1, 4, 7 or 10");
    t.is (eoq.month () % 3, 0, "eoq month is 3, 6, 9 or 12");

    // Note: these fail during the night of daylight savings end.
    t.ok (soq.sameYear (now) ||
          (now.month () >= 10 &&
           soq.year () == now.year () + 1), "soq is in same year as now");
    t.ok (eoq.sameYear (now),  "eoq is in same year as now");

    // ISO8601d::sameHour
    ISO8601d r20 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
    ISO8601d r21 ("6/7/2010 01:59:59", "m/d/Y H:N:S");
    t.ok (r20.sameHour (r21), "two dates within the same hour");

    ISO8601d r22 ("6/7/2010 00:59:59", "m/d/Y H:N:S");
    t.notok (r20.sameHour (r22), "two dates not within the same hour");

    // ISO8601d::operator-
    ISO8601d r25 (1234567890);
    t.is ((r25 - 1).toEpoch (), 1234567889, "1234567890 - 1 = 1234567889");

    // ISO8601d::operator--
    ISO8601d r26 (11, 7, 2010, 23, 59, 59);
    r26--;
    t.is (r26.toString ("YMDHNS"), "20101106235959", "decrement across fall DST boundary");

    ISO8601d r27 (3, 14, 2010, 23, 59, 59);
    r27--;
    t.is (r27.toString ("YMDHNS"), "20100313235959", "decrement across spring DST boundary");

    // ISO8601d::operator++
    ISO8601d r28 (11, 6, 2010, 23, 59, 59);
    r28++;
    t.is (r28.toString ("YMDHNS"), "20101107235959", "increment across fall DST boundary");

    ISO8601d r29 (3, 13, 2010, 23, 59, 59);
    r29++;
    t.is (r29.toString ("YMDHNS"), "20100314235959", "increment across spring DST boundary");

    // int ISO8601d::length (const std::string&);
    t.is (ISO8601d::length ("m"), 2,  "length 'm' --> 2");
    t.is (ISO8601d::length ("M"), 2,  "length 'M' --> 2");
    t.is (ISO8601d::length ("d"), 2,  "length 'd' --> 2");
    t.is (ISO8601d::length ("D"), 2,  "length 'D' --> 2");
    t.is (ISO8601d::length ("y"), 2,  "length 'y' --> 2");
    t.is (ISO8601d::length ("Y"), 4,  "length 'Y' --> 4");
    t.is (ISO8601d::length ("a"), 3,  "length 'a' --> 3");
    t.is (ISO8601d::length ("A"), 10, "length 'A' --> 10");
    t.is (ISO8601d::length ("b"), 3,  "length 'b' --> 3");
    t.is (ISO8601d::length ("B"), 10, "length 'B' --> 10");
    t.is (ISO8601d::length ("v"), 2,  "length 'v' --> 2");
    t.is (ISO8601d::length ("V"), 2,  "length 'V' --> 2");
    t.is (ISO8601d::length ("h"), 2,  "length 'h' --> 2");
    t.is (ISO8601d::length ("H"), 2,  "length 'H' --> 2");
    t.is (ISO8601d::length ("n"), 2,  "length 'n' --> 2");
    t.is (ISO8601d::length ("N"), 2,  "length 'N' --> 2");
    t.is (ISO8601d::length ("s"), 2,  "length 's' --> 2");
    t.is (ISO8601d::length ("S"), 2,  "length 'S' --> 2");
    t.is (ISO8601d::length ("j"), 3,  "length 'j' --> 3");
    t.is (ISO8601d::length ("J"), 3,  "length 'J' --> 3");

    t.is (ISO8601d::length (" "), 1, "length ' ' --> 1");

    // Depletion requirement.
    ISO8601d r30 ("Mon Jun 30 2014", "a b D Y");
    t.is (r30.toString ("YMDHNS"), "20140630000000", "Depletion required on complex format with spaces");

    ISO8601d r31 ("Mon Jun 30 2014 xxx", "a b D Y");
    t.is (r31.toString ("YMDHNS"), "20140630000000", "Depletion not required on complex format with spaces");
  }

  catch (const std::string& e)
  {
    t.fail ("Exception thrown.");
    t.diag (e);
  }

  return 0;
}
示例#20
0
void test_random() {
  double f;
  int i;
  Boolean status;
  CoolRandom r1 (SIMPLE);
  TEST ("CoolRandom r1(SIMPLE)", 1, 1);
  TEST ("r1.next()", (f=r1.next(), (f >= 0.0 && f <= 100.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r1.next() != r1.next());
  TEST ("for(i=0;i<100;i++) r1.next() != r1.next()", status, TRUE);
  CoolRandom r2 (SHUFFLE);
  TEST ("CoolRandom r2(SHUFFLE)", 1, 1);
  TEST ("r2.next()", (f=r2.next(), (f >= 0.0 && f <= 100.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r2.next() != r2.next());
  TEST ("for(i=0;i<100;i++) r2.next() != r2.next()", status, TRUE);
  CoolRandom r3 (ONE_CONGRUENTIAL);
  TEST ("CoolRandom r3(ONE_CONGRUENTIAL)", 1, 1);
  TEST ("r3.next()", (f=r3.next(), (f >= 0.0 && f <= 100.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r3.next() != r3.next());
  TEST ("for(i=0;i<100;i++) r3.next() != r3.next()", status, TRUE);
  CoolRandom r4 (THREE_CONGRUENTIAL);
  TEST ("CoolRandom r4(THREE_CONGRUENTIAL)", 1, 1);
  TEST ("r4.next()", (f=r4.next(), (f >= 0.0 && f <= 100.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r4.next() != r4.next());
  TEST ("for(i=0;i<100;i++) r4.next() != r4.next()", status, TRUE);
  CoolRandom r5 (SUBTRACTIVE);
  TEST ("CoolRandom r5(SUBTRACTIVE)", 1, 1);
  TEST ("r5.next()", (f=r5.next(), (f >= 0.0 && f <= 100.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++) 
    status &= (r5.next() != r5.next());
  TEST ("for(i=0;i<100;i++) r5.next() != r5.next()", status, TRUE);

  CoolRandom r6 (SIMPLE, 1, 3.0, 9.0);
  TEST ("CoolRandom r6(SIMPLE,1,3.0,9.0)", 1, 1);
  TEST ("r6.next()", (f=r6.next(), (f >= 3.0 && f <= 9.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r6.next() != r6.next());
  TEST ("for(i=0;i<100;i++) r6.next() != r6.next()", status, TRUE);
  CoolRandom r7 (SHUFFLE, 1, 3.0, 9.0);
  TEST ("CoolRandom r7(SHUFFLE,1,3.0,9.0)", 1, 1);
  TEST ("r7.next()", (f=r7.next(), (f >= 3.0 && f <= 9.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r7.next() != r7.next());
  TEST ("for(i=0;i<100;i++) r7.next() != r7.next()", status, TRUE);
  CoolRandom r8 (ONE_CONGRUENTIAL, 1, 3.0, 9.0);
  TEST ("CoolRandom r8(ONE_CONGRUENTIAL,1,3.0,9.0)", 1, 1);
  TEST ("r8.next()", (f=r8.next(), (f >= 3.0 && f <= 9.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r8.next() != r8.next());
  TEST ("for(i=0;i<100;i++) r8.next() != r8.next()", status, TRUE);
  CoolRandom r9 (THREE_CONGRUENTIAL, 1, 3.0, 9.0);
  TEST ("CoolRandom r9(THREE_CONGRUENTIAL,1,3.0,9.0)", 1, 1);
  TEST ("r9.next()", (f=r9.next(), (f >= 3.0 && f <= 9.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r9.next() != r9.next());
  TEST ("for(i=0;i<100;i++) r9.next() != r9.next()", status, TRUE);
  CoolRandom r0 (SUBTRACTIVE, 1, 3.0, 9.0);
  TEST ("CoolRandom r0(SUBTRACTIVE,1,3.0,9.0)", 1, 1);
  TEST ("r0.next()", (f=r0.next(), (f >= 3.0 && f <= 9.0)), 1);
  status = TRUE;
  for (i = 0; i < 100; i++)
    status &= (r0.next() != r0.next());
  TEST ("for(i=0;i<100;i++) r0.next() != r0.next()", status, TRUE);
}
示例#21
0
文件: date.t.cpp 项目: JensErat/task
int main (int argc, char** argv)
{
  UnitTest t (211);

  // Ensure environment has no influence.
  unsetenv ("TASKDATA");
  unsetenv ("TASKRC");

  try
  {
    Date now;
    Date yesterday;
    yesterday -= 86400;
    Date tomorrow;
    tomorrow += 86400;

    t.ok    (yesterday <= now,       "yesterday <= now");
    t.ok    (yesterday <  now,       "yesterday < now");
    t.notok (yesterday == now,       "!(yesterday == now)");
    t.ok    (yesterday != now,       "yesterday != now");
    t.ok    (now       >= yesterday, "now >= yesterday");
    t.ok    (now       >  yesterday, "now > yesterday");

    t.ok    (tomorrow >= now,        "tomorrow >= now");
    t.ok    (tomorrow >  now,        "tomorrow > now");
    t.notok (tomorrow == now,        "!(tomorrow == now)");
    t.ok    (tomorrow != now,        "tomorrow != now");
    t.ok    (now      <= tomorrow,   "now <= tomorrow");
    t.ok    (now      <  tomorrow,   "now < tomorrow");

    // Date::Date ("now")
    context.config.set ("weekstart", "monday");
    Date relative_now ("now");
    t.ok (relative_now.sameHour (now),  "Date ().sameHour (Date (now))");
    t.ok (relative_now.sameDay (now),   "Date ().sameDay (Date (now))");
    t.ok (relative_now.sameWeek (now),  "Date ().sameWeek (Date (now))");
    t.ok (relative_now.sameMonth (now), "Date ().sameMonth (Date (now))");
    t.ok (relative_now.sameYear (now),  "Date ().sameYear (Date (now))");

    // Loose comparisons.
    Date left ("7/4/2008");
    Date comp1 ("7/4/2008");
    t.ok (left.sameDay   (comp1), "7/4/2008 is on the same day as 7/4/2008");
    t.ok (left.sameWeek  (comp1), "7/4/2008 is on the same week as 7/4/2008");
    t.ok (left.sameMonth (comp1), "7/4/2008 is in the same month as 7/4/2008");
    t.ok (left.sameYear  (comp1), "7/4/2008 is in the same year as 7/4/2008");

    Date comp2 ("7/5/2008");
    t.notok (left.sameDay   (comp2), "7/4/2008 is not on the same day as 7/5/2008");
    t.ok    (left.sameMonth (comp2), "7/4/2008 is in the same month as 7/5/2008");
    t.ok    (left.sameYear  (comp2), "7/4/2008 is in the same year as 7/5/2008");

    Date comp3 ("8/4/2008");
    t.notok (left.sameDay   (comp3), "7/4/2008 is not on the same day as 8/4/2008");
    t.notok (left.sameWeek  (comp3), "7/4/2008 is not on the same week as 8/4/2008");
    t.notok (left.sameMonth (comp3), "7/4/2008 is not in the same month as 8/4/2008");
    t.ok    (left.sameYear  (comp3), "7/4/2008 is in the same year as 8/4/2008");

    Date comp4 ("7/4/2009");
    t.notok (left.sameDay   (comp4), "7/4/2008 is not on the same day as 7/4/2009");
    t.notok (left.sameWeek  (comp3), "7/4/2008 is not on the same week as 7/4/2009");
    t.notok (left.sameMonth (comp4), "7/4/2008 is not in the same month as 7/4/2009");
    t.notok (left.sameYear  (comp4), "7/4/2008 is not in the same year as 7/4/2009");

    // Validity.
    t.ok    (Date::valid (2, 29, 2008), "valid: 2/29/2008");
    t.notok (Date::valid (2, 29, 2007), "invalid: 2/29/2007");

    t.ok    (Date::valid ("2/29/2008"), "valid: 2/29/2008");
    t.notok (Date::valid ("2/29/2007"), "invalid: 2/29/2007");

    t.ok    (Date::valid (366, 2008), "valid: 366 days in 2008");
    t.notok (Date::valid (366, 2007), "invalid: 366 days in 2007");

    // Time validity.
    t.ok    (Date::valid (2, 28, 2010,  0,  0,  0), "valid 2/28/2010 0:00:00");
    t.ok    (Date::valid (2, 28, 2010, 23, 59, 59), "valid 2/28/2010 23:59:59");
    t.notok (Date::valid (2, 28, 2010, 24, 59, 59), "valid 2/28/2010 24:59:59");
    t.notok (Date::valid (2, 28, 2010, -1,  0,  0), "valid 2/28/2010 -1:00:00");

    // Leap year.
    t.ok    (Date::leapYear (2008), "2008 is a leap year");
    t.notok (Date::leapYear (2007), "2007 is not a leap year");
    t.ok    (Date::leapYear (2000), "2000 is a leap year");
    t.notok (Date::leapYear (1900), "1900 is not a leap year");

    // Days in month.
    t.is (Date::daysInMonth (2, 2008), 29, "29 days in February 2008");
    t.is (Date::daysInMonth (2, 2007), 28, "28 days in February 2007");

    // Names.
    t.is (Date::monthName (1), "January",   "1 = January");
    t.is (Date::monthName (2), "February",  "2 = February");
    t.is (Date::monthName (3), "March",     "3 = March");
    t.is (Date::monthName (4), "April",     "4 = April");
    t.is (Date::monthName (5), "May",       "5 = May");
    t.is (Date::monthName (6), "June",      "6 = June");
    t.is (Date::monthName (7), "July",      "7 = July");
    t.is (Date::monthName (8), "August",    "8 = August");
    t.is (Date::monthName (9), "September", "9 = September");
    t.is (Date::monthName (10), "October",  "10 = October");
    t.is (Date::monthName (11), "November", "11 = November");
    t.is (Date::monthName (12), "December", "12 = December");

    t.is (Date::dayName (0), "Sunday",    "0 == Sunday");
    t.is (Date::dayName (1), "Monday",    "1 == Monday");
    t.is (Date::dayName (2), "Tuesday",   "2 == Tuesday");
    t.is (Date::dayName (3), "Wednesday", "3 == Wednesday");
    t.is (Date::dayName (4), "Thursday",  "4 == Thursday");
    t.is (Date::dayName (5), "Friday",    "5 == Friday");
    t.is (Date::dayName (6), "Saturday",  "6 == Saturday");

    t.is (Date::dayOfWeek ("SUNDAY"),    0, "SUNDAY == 0");
    t.is (Date::dayOfWeek ("sunday"),    0, "sunday == 0");
    t.is (Date::dayOfWeek ("Sunday"),    0, "Sunday == 0");
    t.is (Date::dayOfWeek ("Monday"),    1, "Monday == 1");
    t.is (Date::dayOfWeek ("Tuesday"),   2, "Tuesday == 2");
    t.is (Date::dayOfWeek ("Wednesday"), 3, "Wednesday == 3");
    t.is (Date::dayOfWeek ("Thursday"),  4, "Thursday == 4");
    t.is (Date::dayOfWeek ("Friday"),    5, "Friday == 5");
    t.is (Date::dayOfWeek ("Saturday"),  6, "Saturday == 6");

    Date happyNewYear (1, 1, 2008);
    t.is (happyNewYear.dayOfWeek (), 2, "1/1/2008 == Tuesday");
    t.is (happyNewYear.month (),     1, "1/1/2008 == January");
    t.is (happyNewYear.day (),       1, "1/1/2008 == 1");
    t.is (happyNewYear.year (),   2008, "1/1/2008 == 2008");

    t.is (happyNewYear.toString (), "1/1/2008", "toString 1/1/2008");

    int m, d, y;
    happyNewYear.toMDY (m, d, y);
    t.is (m, 1, "1/1/2008 == January");
    t.is (d, 1, "1/1/2008 == 1");
    t.is (y, 2008, "1/1/2008 == 2008");

    Date epoch (9, 8, 2001);
    t.ok ((int)epoch.toEpoch () < 1000000000, "9/8/2001 < 1,000,000,000");
    epoch += 172800;
    t.ok ((int)epoch.toEpoch () > 1000000000, "9/10/2001 > 1,000,000,000");

    Date fromEpoch (epoch.toEpoch ());
    t.is (fromEpoch.toString (), epoch.toString (), "ctor (time_t)");

    Date iso (1000000000);
    t.is (iso.toISO (), "20010909T014640Z", "1,000,000,000 -> 20010909T014640Z");

    // Quantization.
    Date quant (1234526400);
    t.is (quant.startOfDay ().toString ("YMDHNS"),   "20090213000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/13/2009 0:00:00");
    t.is (quant.startOfWeek ().toString ("YMDHNS"),  "20090208000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/8/2009 0:00:00");
    t.is (quant.startOfMonth ().toString ("YMDHNS"), "20090201000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/1/2009 0:00:00");
    t.is (quant.startOfYear ().toString ("YMDHNS"),  "20090101000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 1/1/2009 0:00:00");

    // Date parsing.
    Date fromString1 ("1/1/2008");
    t.is (fromString1.month (),   1, "ctor (std::string) -> m");
    t.is (fromString1.day (),     1, "ctor (std::string) -> d");
    t.is (fromString1.year (), 2008, "ctor (std::string) -> y");

    Date fromString2 ("1/1/2008", "m/d/Y");
    t.is (fromString2.month (),   1, "ctor (std::string) -> m");
    t.is (fromString2.day (),     1, "ctor (std::string) -> d");
    t.is (fromString2.year (), 2008, "ctor (std::string) -> y");

    Date fromString3 ("20080101", "YMD");
    t.is (fromString3.month (),   1, "ctor (std::string) -> m");
    t.is (fromString3.day (),     1, "ctor (std::string) -> d");
    t.is (fromString3.year (), 2008, "ctor (std::string) -> y");

    Date fromString4 ("12/31/2007");
    t.is (fromString4.month (),  12, "ctor (std::string) -> m");
    t.is (fromString4.day (),    31, "ctor (std::string) -> d");
    t.is (fromString4.year (), 2007, "ctor (std::string) -> y");

    Date fromString5 ("12/31/2007", "m/d/Y");
    t.is (fromString5.month (),  12, "ctor (std::string) -> m");
    t.is (fromString5.day (),    31, "ctor (std::string) -> d");
    t.is (fromString5.year (), 2007, "ctor (std::string) -> y");

    Date fromString6 ("20071231", "YMD");
    t.is (fromString6.month (),  12, "ctor (std::string) -> m");
    t.is (fromString6.day (),    31, "ctor (std::string) -> d");
    t.is (fromString6.year (), 2007, "ctor (std::string) -> y");

    Date fromString7 ("01/01/2008", "m/d/Y");
    t.is (fromString7.month (),   1, "ctor (std::string) -> m");
    t.is (fromString7.day (),     1, "ctor (std::string) -> d");
    t.is (fromString7.year (), 2008, "ctor (std::string) -> y");

    Date fromString8 ("Tue 05 Feb 2008 (06)", "a D b Y (V)");
    t.is (fromString8.month (),   2, "ctor (std::string) -> m");
    t.is (fromString8.day (),     5, "ctor (std::string) -> d");
    t.is (fromString8.year (), 2008, "ctor (std::string) -> y");

    Date fromString9 ("Tuesday, February 5, 2008", "A, B d, Y");
    t.is (fromString9.month (),   2, "ctor (std::string) -> m");
    t.is (fromString9.day (),     5, "ctor (std::string) -> d");
    t.is (fromString9.year (), 2008, "ctor (std::string) -> y");

    Date fromString10 ("w01 Tue 2008-01-01", "wV a Y-M-D");
    t.is (fromString10.month (),   1, "ctor (std::string) -> m");
    t.is (fromString10.day (),     1, "ctor (std::string) -> d");
    t.is (fromString10.year (), 2008, "ctor (std::string) -> y");

    Date fromString11 ("6/7/2010 1:23:45",  "m/d/Y h:N:S");
    t.is (fromString11.month (),     6, "ctor (std::string) -> m");
    t.is (fromString11.day (),       7, "ctor (std::string) -> d");
    t.is (fromString11.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString11.hour (),      1, "ctor (std::string) -> h");
    t.is (fromString11.minute (),   23, "ctor (std::string) -> N");
    t.is (fromString11.second (),   45, "ctor (std::string) -> S");

    Date fromString12 ("6/7/2010 01:23:45", "m/d/Y H:N:S");
    t.is (fromString12.month (),     6, "ctor (std::string) -> m");
    t.is (fromString12.day (),       7, "ctor (std::string) -> d");
    t.is (fromString12.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString12.hour (),      1, "ctor (std::string) -> h");
    t.is (fromString12.minute (),   23, "ctor (std::string) -> N");
    t.is (fromString12.second (),   45, "ctor (std::string) -> S");

    Date fromString13 ("6/7/2010 12:34:56", "m/d/Y H:N:S");
    t.is (fromString13.month (),     6, "ctor (std::string) -> m");
    t.is (fromString13.day (),       7, "ctor (std::string) -> d");
    t.is (fromString13.year (),   2010, "ctor (std::string) -> Y");
    t.is (fromString13.hour (),     12, "ctor (std::string) -> h");
    t.is (fromString13.minute (),   34, "ctor (std::string) -> N");
    t.is (fromString13.second (),   56, "ctor (std::string) -> S");

    // Day of year
    t.is (Date ("1/1/2011",   "m/d/Y").dayOfYear (),   1, "dayOfYear (1/1/2011)   ->   1");
    t.is (Date ("5/1/2011",   "m/d/Y").dayOfYear (), 121, "dayOfYear (5/1/2011)   -> 121");
    t.is (Date ("12/31/2011", "m/d/Y").dayOfYear (), 365, "dayOfYear (12/31/2011) -> 365");

    // Easter
    Date e1 (Date::easter(1980));
    t.is (e1.toString (), "4/6/1980", "Easter 4/6/1980");
    Date e2 (Date::easter(1995));
    t.is (e2.toString (), "4/16/1995", "Easter 4/16/1995");
    Date e3 (Date::easter(2000));
    t.is (e3.toString (), "4/23/2000", "Easter 4/23/2000");
    Date e4 (Date::easter(2009));
    t.is (e4.toString (), "4/12/2009", "Easter 4/12/2009");
    Date e5 (Date::easter(2010));
    t.is (e5.toString (), "4/4/2010", "Easter 4/4/2010");
    Date e6 (Date::easter(2011));
    t.is (e6.toString (), "4/24/2011", "Easter 4/24/2011");
    Date e7 (Date::easter(2012));
    t.is (e7.toString (), "4/8/2012", "Easter 4/8/2012");
    Date e8 (Date::easter(2020));
    t.is (e8.toString (), "4/12/2020", "Easter 4/12/2020");

    // Relative dates.
    Date r1 ("today");
    t.ok (r1.sameDay (now), "today = now");

    Date r4 ("sunday");
    if (now.dayOfWeek () >= 0)
      t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday");
    else
      t.ok (r4.sameDay (now + (0 - now.dayOfWeek ()) * 86400), "next sunday");;

    Date r5 ("monday");
    if (now.dayOfWeek () >= 1)
      t.ok (r5.sameDay (now + (1 - now.dayOfWeek () + 7) * 86400), "next monday");
    else
      t.ok (r5.sameDay (now + (1 - now.dayOfWeek ()) * 86400), "next monday");;

    Date r6 ("tuesday");
    if (now.dayOfWeek () >= 2)
      t.ok (r6.sameDay (now + (2 - now.dayOfWeek () + 7) * 86400), "next tuesday");
    else
      t.ok (r6.sameDay (now + (2 - now.dayOfWeek ()) * 86400), "next tuesday");;

    Date r7 ("wednesday");
    if (now.dayOfWeek () >= 3)
      t.ok (r7.sameDay (now + (3 - now.dayOfWeek () + 7) * 86400), "next wednesday");
    else
      t.ok (r7.sameDay (now + (3 - now.dayOfWeek ()) * 86400), "next wednesday");;

    Date r8 ("thursday");
    if (now.dayOfWeek () >= 4)
      t.ok (r8.sameDay (now + (4 - now.dayOfWeek () + 7) * 86400), "next thursday");
    else
      t.ok (r8.sameDay (now + (4 - now.dayOfWeek ()) * 86400), "next thursday");;

    Date r9 ("friday");
    if (now.dayOfWeek () >= 5)
      t.ok (r9.sameDay (now + (5 - now.dayOfWeek () + 7) * 86400), "next friday");
    else
      t.ok (r9.sameDay (now + (5 - now.dayOfWeek ()) * 86400), "next friday");;

    Date r10 ("saturday");
    if (now.dayOfWeek () >= 6)
      t.ok (r10.sameDay (now + (6 - now.dayOfWeek () + 7) * 86400), "next saturday");
    else
      t.ok (r10.sameDay (now + (6 - now.dayOfWeek ()) * 86400), "next saturday");;

    Date r11 ("eow");
    t.ok (r11 < now + (8 * 86400), "eow < 7 days away");

    Date r12 ("eocw");
    t.ok (r12 > now - (8 * 86400), "eocw < 7 days in the past");

    Date r13 ("eom");
    t.ok (r13.sameMonth (now), "eom in same month as now");

    Date r14 ("eocm");
    t.ok (r14.sameMonth (now), "eocm in same month as now");

    Date r15 ("eoy");
    t.ok (r15.sameYear (now), "eoy in same year as now");

    Date r16 ("sow");
    t.ok (r16 < now + (8 * 86400), "sow < 7 days away");

    Date r23 ("socw");
    t.ok (r23 > now - (8 * 86400), "sow < 7 days in the past");

    Date r17 ("som");
    t.notok (r17.sameMonth (now), "som not in same month as now");

    Date r18 ("socm");
    t.ok (r18.sameMonth (now), "socm in same month as now");

    Date r19 ("soy");
    t.notok (r19.sameYear (now), "soy not in same year as now");

    Date first ("1st");
    t.notok (first.sameMonth (now), "1st not in same month as now");
    t.is (first.day (),   1, "1st day is 1");

    Date later ("later");
    t.is (later.month (),   1, "later -> m = 1");
    t.is (later.day (),    18, "later -> d = 18");
    t.is (later.year (), 2038, "later -> y = 2038");

    // Quarters
    Date soq ("soq");
    Date eoq ("eoq");
    t.is (soq.day (),  1,      "soq is the first day of a month");
    t.is (eoq.day () / 10,  3, "eoq is the 30th or 31th of a month");
    t.is (soq.month () % 3, 1, "soq month is 1, 4, 7 or 10");
    t.is (eoq.month () % 3, 0, "eoq month is 3, 6, 9 or 12");

    // Note: these fail during the night of daylight savings end.
    t.ok (soq.sameYear (now) ||
          (now.month () >= 10 &&
           soq.year () == now.year () + 1), "soq is in same year as now");
    t.ok (eoq.sameYear (now),  "eoq is in same year as now");

    // Date::sameHour
    Date r20 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
    Date r21 ("6/7/2010 01:59:59", "m/d/Y H:N:S");
    t.ok (r20.sameHour (r21), "two dates within the same hour");

    Date r22 ("6/7/2010 00:59:59", "m/d/Y H:N:S");
    t.notok (r20.sameHour (r22), "two dates not within the same hour");

    // Date::operator-
    Date r25 (1234567890);
    t.is ((r25 - 1).toEpoch (), 1234567889, "1234567890 - 1 = 1234567889");

    // Date::operator--
    Date r26 (11, 7, 2010, 23, 59, 59);
    r26--;
    t.is (r26.toString ("YMDHNS"), "20101106235959", "decrement across fall DST boundary");

    Date r27 (3, 14, 2010, 23, 59, 59);
    r27--;
    t.is (r27.toString ("YMDHNS"), "20100313235959", "decrement across spring DST boundary");

    // Date::operator++
    Date r28 (11, 6, 2010, 23, 59, 59);
    r28++;
    t.is (r28.toString ("YMDHNS"), "20101107235959", "increment across fall DST boundary");

    Date r29 (3, 13, 2010, 23, 59, 59);
    r29++;
    t.is (r29.toString ("YMDHNS"), "20100314235959", "increment across spring DST boundary");

    // int Date::length (const std::string&);
    t.is (Date::length ("m"), 2,  "length 'm' --> 2");
    t.is (Date::length ("M"), 2,  "length 'M' --> 2");
    t.is (Date::length ("d"), 2,  "length 'd' --> 2");
    t.is (Date::length ("D"), 2,  "length 'D' --> 2");
    t.is (Date::length ("y"), 2,  "length 'y' --> 2");
    t.is (Date::length ("Y"), 4,  "length 'Y' --> 4");
    t.is (Date::length ("a"), 3,  "length 'a' --> 3");
    t.is (Date::length ("A"), 10, "length 'A' --> 10");
    t.is (Date::length ("b"), 3,  "length 'b' --> 3");
    t.is (Date::length ("B"), 10, "length 'B' --> 10");
    t.is (Date::length ("v"), 2,  "length 'v' --> 2");
    t.is (Date::length ("V"), 2,  "length 'V' --> 2");
    t.is (Date::length ("h"), 2,  "length 'h' --> 2");
    t.is (Date::length ("H"), 2,  "length 'H' --> 2");
    t.is (Date::length ("n"), 2,  "length 'n' --> 2");
    t.is (Date::length ("N"), 2,  "length 'N' --> 2");
    t.is (Date::length ("s"), 2,  "length 's' --> 2");
    t.is (Date::length ("S"), 2,  "length 'S' --> 2");
    t.is (Date::length ("j"), 3,  "length 'j' --> 3");
    t.is (Date::length ("J"), 3,  "length 'J' --> 3");

    t.is (Date::length (" "), 1, "length ' ' --> 1");

    // Depletion requirement.
    Date r30 ("Mon Jun 30 2014", "a b D Y", false, false);
    t.is (r30.toString ("YMDHNS"), "20140630000000", "Depletion required on complex format with spaces");

    std::string::size_type i = 0;
    Date r31 ("Mon Jun 30 2014 xxx", i, "a b D Y", false, false);
    t.is (r31.toString ("YMDHNS"), "20140630000000", "Depletion not required on complex format with spaces");
    t.is ((int)i, 15,                                "Depletion not required on complex format with spaces, 15 chars");
  }

  catch (const std::string& e)
  {
    t.fail ("Exception thrown.");
    t.diag (e);
  }

  return 0;
}
示例#22
0
    r1(Stmt, n(Assn)                                                       )
    r1(Stmt, n(Prnt)                                                       )
    r1(Stmt, n(Ctrl)                                                       )

    r4(Assn, t(NAME), t(ASSN), n(Expr), t(SCOL)                            )
    r4(Assn, n(Aexp), t(ASSN), n(Expr), t(SCOL)                            )

    r3(Prnt, t(PRNT), n(Expr), t(SCOL)                                     )
    r4(Prnt, t(PRNT), t(STRL), n(Expr), t(SCOL)                            )

    r2(Ctrl, n(Cond), m(Elif)                                              )
    r3(Ctrl, n(Cond), m(Elif), n(Else)                                     )
    r1(Ctrl, n(Dowh)                                                       )
    r1(Ctrl, n(Whil)                                                       )

    r5(Cond, t(COND), n(Expr), t(LBRC), m(Stmt), t(RBRC)                   )
    r5(Elif, t(ELIF), n(Expr), t(LBRC), m(Stmt), t(RBRC)                   )
    r4(Else, t(ELSE), t(LBRC), m(Stmt), t(RBRC)                            )

    r7(Dowh, t(DOWH), t(LBRC), m(Stmt), t(RBRC), t(WHIL), n(Expr), t(SCOL) )
    r5(Whil, t(WHIL), n(Expr), t(LBRC), m(Stmt), t(RBRC)                   )

    r1(Atom, t(NAME)                                                       )
    r1(Atom, t(NMBR)                                                       )

    r1(Expr, n(Atom)                                                       )
    r1(Expr, n(Pexp)                                                       )
    r1(Expr, n(Bexp)                                                       )
    r1(Expr, n(Uexp)                                                       )
    r1(Expr, n(Texp)                                                       )
    r1(Expr, n(Aexp)                                                       )
示例#23
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(r*cos(c*du), h, r*sin(c*du), 0, 0, 0, 0, 3, 0); //head position;eye direction(0.0,0.0,0.0),original point;(0.0,1.0,0.0),head above direction¡£
	
	//cylinder a(1, 15, 0, 90, 0, 0, 5, 0); //r,h,xangle yangle zangle, module position(xx yy zz)
	//sphere b(3, 100, 100, 0, 0, 0, 0, 2.5, 0); //r,xangle yangle zangle, module position(xx yy zz)
	//cube c(5, 10, 0, 0, 1, 1, 1); //length xangle yangle zangle, module position(xx yy zz)
	//rectangularpyramid d(4, 0, 0, 0, 0, 2, 0); //length xangle yangle zangle, module position(xx yy zz)
	//triangularpyramid f(2, 0, 0, 0, 8, 8, 8);//length xangle yangle zangle, module position(xx yy zz)						
	//f.draw();
	sphere sp(3, 100, 100, 0, 0, -2, 0, 8, 0);
	cylinder cy(3, 5, 0, 90, 0, -3, 9, -10);
	cube cu(3, 0, 0, 0, 0, 8, 10);
	triangularpyramid tr(2, 0, 0, 0, 0, -6, 8);
	rectangularpyramid rec(2, 0, 0, 0, 0, -6, -8);

	cylinder k1(0.3, 2, 90, 0, 0, 0, 0, 0);
	cylinder k2(0.3, 2, -90, 0, 0, 0, 0, 0);
	cylinder k3(0.3, 2, -45, 0, 0, 0, 0, 0);
	cylinder k4(0.3, 2.5, 45, 0, 0, 0, 0, 0);

	cylinder u1(0.3, 2, 90, 0, 0, 0, 0, 3);
	cylinder u2(0.3, 1.5, -90, 0, 0, 0, 0, 3);
	cylinder u3(0.3, 2, 0, 0, 0, 0, -1.8, 3);
	cylinder u4(0.3, 2, 90, 0, 0, 0, 0, 5);
	cylinder u5(0.3, 1.5, -90, 0, 0, 0, 0, 5);  

	cylinder g1(0.3, 2, -90, 0, 0, 0, -0.5, 6.4);
	cylinder g2(0.3, 1.5, -90, 0, 0, 0, -0.5, 6.4);
	cylinder g3(0.3, 2, 0, 0, 0, 0, -0.3, 6.4);
	cylinder g4(0.3, 2, 0, 0, 0, 0, 1.3, 6.4);
	cylinder g5(0.3, 2, 90, 0, 0, 0, 0, 8.4);
	cylinder g6(0.3, 1.5, -90, 0, 0, 0, 0, 8.4);
	cylinder g7(0.3, 2, 0, 0, 0, 0, -1.8, 6.4);

	cylinder e1(0.3, 1.8, -90, 0, 0, 0, -0.2, 10);
	cylinder e2(0.3, 1.8, 90, 0, 0, 0, -0.2, 10);
	cylinder e3(0.3, 2, 0, 0, 0, 0, -0.3, 10);
	cylinder e4(0.3, 2, 0, 0, 0, 0, 1.3, 10);
	cylinder e5(0.3, 2, 0, 0, 0, 0, -1.8, 10);

	cylinder r1(0.3, 1.8, -90, 0, 0, 0, -0.2, 13.5);
	cylinder r2(0.3, 1.8, 90, 0, 0, 0, -0.2, 13.5);
	cylinder r3(0.3, 2, 0, 0, 0, 0, -0.3, 13.5);
	cylinder r4(0.3, 1.2, 0, 0, 0, 0, 1.3, 13.5);
	cylinder r5(0.3, 1.7, 60, 0, 0, 0, 1.3, 14.5);
	cylinder r6(0.3, 2.5, 45, 0, 0, 0, 0, 13.5);


	cylinder c1(0.3, 2, 90, 0, 0, 0, 0, -15);
	cylinder c2(0.3, 2, -90, 0, 0, 0, 0, -15); 
	cylinder c3(0.3, 3, 0, 0, 0, 0, -1.8, -15);
	cylinder c4(0.3, 3, 0, 0, 0, 0, 1.8, -15);

	cylinder plus1(0.3,3.5, 0, 0, 0, 0, 0, -11);
	cylinder plus2(0.3, 4, 90, 0, 0, 0, 2, -9.2);
	cylinder plus3(0.3, 3.5, 0, 0, 0, 0, 0, -6);
	cylinder plus4(0.3, 4, 90, 0, 0, 0, 2, -4.2);
	cy.draw();
	sp.draw();
	cu.draw();
	tr.draw();
	rec.draw();

	k1.draw();
	k2.draw();
	k3.draw();
	k4.draw();

	u1.draw();
	u2.draw();
	u3.draw();
	u4.draw();
	u5.draw();
	
	g1.draw();
	g2.draw();
	g3.draw();
	g4.draw();
	g5.draw();
	g6.draw();
	g7.draw();

	e1.draw();
	e2.draw();
	e3.draw();
	e4.draw();
	e5.draw();

	r1.draw();
	r2.draw();
	r3.draw();
	r4.draw();
	r5.draw();
	r6.draw();

	c1.draw();
	c2.draw();
	c3.draw();
	c4.draw();
	
	plus1.draw();
	plus2.draw();
	plus3.draw();
	plus4.draw();

	glFlush();
	
}
示例#24
0
void test_rational() {
  CoolRational r1;
  TEST ("CoolRational r1", r1.status(), N_OK);
  CoolRational r2(3,5);
  TEST ("CoolRational r2(3,5)", r2.status(), N_OK);
  TEST ("r2.numerator()", r2.numerator(), 3);
  TEST ("r2.denominator()", r2.denominator(), 5);
  TEST ("r1 != r2", r1 != r2, TRUE);
  CoolRational r3(9);
  TEST ("CoolRational r3(9)", r3.status(), N_OK);
  TEST ("r3.numerator()", r3.numerator(), 9);
  TEST ("r3.denominator()", r3.denominator(), 1);
  CoolRational r4(6,10);
  TEST ("CoolRational r4(6,10)", r4.status(), N_OK);
  TEST ("r4.numerator()", r4.numerator(), 3);
  TEST ("r4.denominator()", r4.denominator(), 5);
  TEST ("r2 == r4", r2 == r4, TRUE);
  TEST ("r1 = r2", (r1 = r2, r1 == r2), TRUE);
  TEST ("r1.status()", r1.status(), N_OK);
  TEST ("r1.numerator()", r1.numerator(), 3);
  TEST ("r1.denominator()", r1.denominator(), 5);
  TEST ("r1 == r4", r1 == r4, TRUE);
  TEST ("-r3",(r1 = -r3,(r1.numerator() == -9 && r1.denominator() == 1)),TRUE);
  CoolRational r5(r1);
  TEST ("CoolRational r5(r1)", r5 == r1, TRUE);
  TEST ("!r5", !r5, FALSE);
  TEST ("r3=r1+r2",(r3=r1+r2,r3.numerator()==-42 && r3.denominator()==5),TRUE);
  TEST ("r1+=r2", (r1+=r2, r1 == r3), TRUE);
  TEST ("r3.invert()",(r3.invert(),r3.numerator()==-5&& r3.denominator()==42),TRUE);
  TEST ("r5=r1+r3",(r5=r1+r3, r5.numerator()==-1789 && r5.denominator()==210), TRUE);
  TEST ("r1+=r3",(r1+=r3, r1 == r5), TRUE);
  TEST ("r4 = r1", (r4 = r1, r4 == r1), TRUE);
  TEST ("r5=r2-(r3.invert())", (r5=r2-(r3.invert()), r5.numerator()==9 && r5.denominator()==1),TRUE);
  TEST ("r2-=r3", (r2-=r3, r2 == r5), TRUE);
  TEST ("short (r1)", short(r1), -8);
  TEST ("int (r1)", int(r1), -8);
  TEST ("long (r1)", long(r1), -8);
  TEST ("float (r1)", (((float)(r1)) < -8.51904 && float(r1) > -8.51906), TRUE);
  TEST ("double (r1)", (((double)(r1)) < -8.51904 && double(r1) > -8.51906), TRUE);
  TEST ("r1.floor()", r1.floor(), -9);
  TEST ("r1.ceiling()", r1.ceiling(), -8);
  TEST ("r1.truncate()", r1.truncate(), -8);
  TEST ("r1.round()", r1.round(), -9);
  TEST ("r1 *= -1", (r1 *= CoolRational(-1), r1 == -r4), TRUE);
  TEST ("r1.floor()", r1.floor(), 8);
  TEST ("r1.ceiling()", r1.ceiling(), 9);
  TEST ("r1.truncate()", r1.truncate(), 8);
  TEST ("r1.round()", r1.round(), 9);
  TEST ("r4 < r1", r4 < r1, TRUE);
  TEST ("r4 <= r1", r4 <= r1, TRUE);
  TEST ("r4 <= r4", r4 <= r4, TRUE);
  TEST ("r1 > r4", r1 > r4, TRUE);
  TEST ("r1 >= r4", r1 >= r4, TRUE);
  TEST ("r1 >= r1", r1 <= r1, TRUE);
  TEST ("++r2", (++r2, r2.numerator() == 10 && r2.denominator() == 1), TRUE);
  TEST ("--r2", (--r2, r2 == r5), TRUE);
  TEST ("r1=r2", (r1=r2, r1.numerator() == 9 && r1.denominator() == 1), TRUE);
  TEST ("r4=r2*r3",(r4=r2*r3,r4.numerator()==-378 &&r4.denominator()==5),TRUE);
  TEST ("r2*=r3", (r2*=r3, r2 == r4), TRUE);
  TEST ("r2/r3", r2 / r3, r1);
  TEST ("r2/=r3", (r2/=r3, r2 == r1), TRUE);
  TEST ("r4%(r2/r3)", (r5=r4%(r2/r3), r5.numerator()==-3 && r5.denominator()==5), TRUE);
  TEST ("r4%=(r2/r3)", (r4%=(r2/r3), r4 == r5), TRUE);
}
RelationshipTable::RelationshipTable() {
    vector<string> arg1;
    vector<string> arg2;

    //ModifiesS (statements)
    arg1 = { "stmt", "assign", "while", "prog_line", "all" };
    arg2 = { "variable", "string", "all" };
    Relationship r1(2, arg1, arg2);
    relTable["modifies"] = r1;
    arg1.clear();
    arg2.clear();
    //cout << relTable.find("modifies*")->second.arg1.at(0);

    //UsesS (statements)
    arg1 = { "assign", "while", "prog_line", "all" };
    arg2 = { "variable", "string", "all" };
    Relationship r2(2, arg1, arg2);
    relTable["uses"] = r2;
    arg1.clear();
    arg2.clear();

    //Parent
    arg1 = { "prog_line", "while", "all" };
    arg2 = { "stmt", "assign", "prog_line", "while", "all" };
    Relationship r3(2, arg1, arg2);
    relTable["parent"] = r3;
    arg1.clear();
    arg2.clear();

    //Parent*
    arg1 = { "prog_line", "while" , "all" };
    arg2 = { "stmt", "assign", "prog_line", "while", "all" };
    Relationship r4(2, arg1, arg2);
    relTable["parent*"] = r4;
    arg1.clear();
    arg2.clear();

    //Follows
    arg1 = { "stmt", "assign", "prog_line", "while", "all" };
    arg2 = { "stmt", "assign", "prog_line", "while", "all" };
    Relationship r5(2, arg1, arg2);
    relTable["follows"] = r5;
    arg1.clear();
    arg2.clear();

    //Followst
    arg1 = { "stmt", "assign", "prog_line", "while", "all" };
    arg2 = { "stmt", "assign", "prog_line", "while", "all" };
    Relationship r6(2, arg1, arg2);
    relTable["follows*"] = r6;
    arg1.clear();
    arg2.clear();

    //Pattern
    arg1 = { "variable", "string", "all" };
    arg2 = { "variable", "constant", "string", "all" };
    Relationship r7(2, arg1, arg2);
    relTable["pattern"] = r7;
    arg1.clear();
    arg2.clear();
}
示例#26
0
文件: main.cpp 项目: ducthangho/3D
int test1()
{	
	//srand(1989);
	MyRectangle enclosingRect(40, 40);
	MyRectangle r1(15, 30);
	MyRectangle r2(20, 25);
	MyRectangle r3(9, 7);
	MyRectangle r4(20, 8);
	MyRectangle r5(10, 10);

	std::vector<MyRectangle> listRect;
	listRect.push_back(r1);
	listRect.push_back(r2);
	listRect.push_back(r3);
	listRect.push_back(r4);
	listRect.push_back(r5);

	std::vector<std::vector<AreaRect>> listArea;
	std::vector<AreaRect> row1;
	row1.emplace_back(15, 25, 0, 0, false);
	row1.emplace_back(20, 25, 15, 0, false);
	row1.emplace_back(5, 25, 35, 0, true);

	std::vector<AreaRect> row2;
	row2.emplace_back(15, 5, 0, 25, false);
	row2.emplace_back(20, 5, 15, 25, true);
	row2.emplace_back(5, 5, 35, 25, true);

	std::vector<AreaRect> row3;
	row3.emplace_back(15, 10, 0, 30, true);
	row3.emplace_back(20, 10, 15, 30, true);
	row3.emplace_back(5, 10, 35, 30, true);

	std::vector<AreaRect> row4;
	row4.emplace_back(15, 9, 0, 40, true);
	row4.emplace_back(20, 9, 15, 40, true);
	row4.emplace_back(5, 9, 35, 40, true);

	listArea.push_back(row1);
	listArea.push_back(row2);
	listArea.push_back(row3);
	listArea.push_back(row4);

	vector<vector<AreaRect>> listArea2;
	listArea2.reserve(100000);
	listArea2.emplace_back(1, AreaRect(enclosingRect.w, enclosingRect.h, 0, 0, true));
	
	PackingAlogorithm pa;
	float places[6];

	/*if (pa.findPlace(r1, enclosingRect, listArea2, places))
	{
		r1.x = places[0];
		r1.y = places[1];
		r1.print();
		pa.updateListArea(listArea2, r1, places[2], places[3], places[4], places[5]);
		pa.printListArea(listArea2);
	}
	cout << "--------------------------------" << endl;
	if (pa.findPlace(r2, enclosingRect, listArea2, places))
	{
		r2.x = places[0];
		r2.y = places[1];
		r2.print();
		pa.updateListArea(listArea2, r2, places[2], places[3], places[4], places[5]);
		pa.printListArea(listArea2);
	}
	cout << "--------------------------------" << endl;
	if (pa.findPlace(r5, enclosingRect, listArea2, places))
	{
		r5.x = places[0];
		r5.y = places[1];
		r5.print();
		pa.updateListArea(listArea2, r5, places[2], places[3], places[4], places[5]);
		pa.printListArea(listArea2);
	}
	cout << "--------------------------------" << endl;
	if (pa.findPlace(r4, enclosingRect, listArea2, places))
	{
		r4.x = places[0];
		r4.y = places[1];
		r4.print();
		pa.updateListArea(listArea2, r4, places[2], places[3], places[4], places[5],true);
		pa.printListArea(listArea2);
	}
	cout << "--------------------------------" << endl;
	if (pa.findPlace(r3, enclosingRect, listArea2, places))
	{
		r3.x = places[0];
		r3.y = places[1];
		r3.print();
		cout << "i: " << places[2] << "j: " << places[3] << "er: " << places[4] << "ec: " << places[5];
		pa.updateListArea(listArea2, r3, places[2], places[3], places[4], places[5],true);
		pa.printListArea(listArea2);
	}*/
	/*std::vector<MyRectangle> result = pa.pack(listRect, enclosingRect);
	for (auto& a : result)
	{
		a.print();
	}*/
	

	//std::vector<MyRectangle> listRect;
	Time tt;
	for (int i = 0; i < 20000; i++)
	{
		auto w = rand() % 30 + 1;
		auto h = rand() % 40 + 1;
		MyRectangle a(w,h);
		listRect.push_back(a);
	}
	std::cout << "Data creation time = " << tt.duration() << " ms" << std::endl;
	Time t;
	MyRectangle enclosingRect2(500,500);
	std::vector<MyRectangle> r = pa.pack(listRect, enclosingRect2);
	cout << r.size() << endl;
	std::cout << "Execution time = " << t.duration() << " ms" << std::endl;
	for (auto& a : r)
	{
		a.print();
	}
	return 0;
}
示例#27
0
END_TEST


START_TEST(test_constructors)
  {
  req r;
  std::vector<std::string> l;

  fail_unless(r.getHostlist(l) == PBSE_EMPTY);
  fail_unless(l.size() == 0);
  fail_unless(r.getTaskCount() == 1);
  fail_unless(r.getPlacementType() == "");
  fail_unless(r.getNodeAccessPolicy().size() == 0, r.getNodeAccessPolicy().c_str());
  fail_unless(r.getOS().size() == 0);
  fail_unless(r.getGres().size() == 0);
  fail_unless(r.getDisk() == 0);
  fail_unless(r.getSwap() == 0);
  fail_unless(r.getMemory() == 0);
  fail_unless(r.getExecutionSlots() == 1, "slots: %d", r.getExecutionSlots());

  std::string req2("5:lprocs=4:memory=12gb:place=socket=2:usecores:pack:gpus=2:mics=1:gres=matlab=1:feature=fast");
  req r2(req2);
  fail_unless(r2.getTaskCount() == 5, "task count is %d", r2.getTaskCount());
  fail_unless(r2.getPlacementType() == "socket=2", "value %s", r2.getPlacementType().c_str());
  fail_unless(r2.getNodeAccessPolicy().size() == 0);
  fail_unless(r2.getOS().size() == 0);
  fail_unless(r2.getGres() == "matlab=1");
  fail_unless(r2.getDisk() == 0);
  fail_unless(r2.getSwap() == 0);
  fail_unless(r2.getMemory() == 12 * 1024 * 1024);
  fail_unless(r2.getExecutionSlots() == 4);
  fail_unless(r2.getFeatures() == "fast", "features '%s'", r2.getFeatures().c_str());

  req copy_r2(r2);
  fail_unless(copy_r2.getTaskCount() == 5);
  fail_unless(copy_r2.getPlacementType() == r2.getPlacementType(), "copy value '%s' first value '%s'", copy_r2.getPlacementType().c_str(), r2.getPlacementType().c_str());
  fail_unless(copy_r2.getNodeAccessPolicy().size() == 0);
  fail_unless(copy_r2.getOS().size() == 0);
  fail_unless(copy_r2.getGres() == "matlab=1");
  fail_unless(copy_r2.getDisk() == 0);
  fail_unless(copy_r2.getSwap() == 0);
  fail_unless(copy_r2.getMemory() == 12 * 1024 * 1024);
  fail_unless(copy_r2.getExecutionSlots() == 4);
  fail_unless(copy_r2.getFeatures() == "fast", "features '%s'", copy_r2.getFeatures().c_str());
 
  std::string req3("5:lprocs=4:memory=12gb:place=node:mics=1:feature=fast");
  req r3(req3);
  fail_unless(r3.getPlacementType() == "node");

  std::string req4("5:lprocs=4:memory=12gb:place=numanode=1:mics=1:feature=fast");
  req r4(req4);
  fail_unless(r4.getPlacementType() == "numanode=1", r4.getPlacementType().c_str());
 
  std::string req5("5:lprocs=4:memory=12gb:place=core:mics=1:feature=fast");
  req r5(req5);
  fail_unless(r5.getThreadUsageString() == "usecores", "thread usage '%s'", r5.getThreadUsageString().c_str());

  std::string req6("5:lprocs=4:place=thread");
  req r6(req6);
  fail_unless(r6.getThreadUsageString() == "usethreads", "thread usage '%s'", r6.getThreadUsageString().c_str());

  // make sure miss-spellings are caught
  std::string error;
  req str_set;

  fail_unless(str_set.set_from_submission_string(strdup("5:lproc=2"), error) != PBSE_NONE);
  good_err = true;
  fail_unless(str_set.set_from_submission_string(strdup("5:lprocs=2:place=sockets=2"), error) != PBSE_NONE);

  fail_unless(str_set.set_from_submission_string(strdup("4:lprocs=all"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("4:memory=12gb:memory=1024mb"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("-1:lprocs=4"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("1:lprocs=-4"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("1:lprocs=4:memory=0"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("3:gpus=2:reseterr:exclusive_thread:opsys=cent6"), error) == PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("1:lprocs=all:place=core"), error) != PBSE_NONE);
  fail_unless(str_set.set_from_submission_string(strdup("1:lprocs=all:place=thread=2"), error) != PBSE_NONE);

  std::string req7("2:place=numanode");
  req r7(req7);
  r7.set_index(0);

  std::vector<std::string> names;
  std::vector<std::string> values;
  r7.get_values(names, values);

  fail_unless(names[0] == "task_count.0", names[0].c_str());
  fail_unless(names[1] == "lprocs.0", names[1].c_str());
  fail_unless(names[2] == "numanode.0", names[2].c_str());
  fail_unless(values[0] == "2");
  fail_unless(values[1] == "1");
  fail_unless(values[2] == "1");

  std::string req8("2:place=core");
  req r8(req8);
  r8.set_index(0);

  names.clear();
  values.clear();
  r8.get_values(names, values);

  fail_unless(names[0] == "task_count.0", names[0].c_str());
  fail_unless(names[1] == "lprocs.0", names[1].c_str());
  fail_unless(values[0] == "2");
  fail_unless(values[1] == "1");
  }