Ejemplo n.º 1
0
void TestQgsCoordinateTransform::isShortCircuited()
{
  QgsCoordinateTransform tr;
  //invalid transform shortcircuits
  QVERIFY( tr.isShortCircuited() );

  QgsCoordinateReferenceSystem srs1;
  srs1.createFromSrid( 3994 );
  QgsCoordinateReferenceSystem srs2;
  srs2.createFromSrid( 4326 );

  // valid source, invalid destination
  QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem() );
  QVERIFY( tr2.isShortCircuited() );

  // invalid source, valid destination
  QgsCoordinateTransform tr3( QgsCoordinateReferenceSystem(), srs2 );
  QVERIFY( tr3.isShortCircuited() );

  // equal, valid source and destination
  QgsCoordinateTransform tr4( srs1, srs1 );
  QVERIFY( tr4.isShortCircuited() );

  // valid but different source and destination
  QgsCoordinateTransform tr5( srs1, srs2 );
  QVERIFY( !tr5.isShortCircuited() );

  // try to short circuit by changing dest
  tr5.setDestinationCrs( srs1 );
  QVERIFY( tr5.isShortCircuited() );
}
Ejemplo n.º 2
0
void TestQgsCoordinateTransform::isValid()
{
  QgsCoordinateTransform tr;
  QVERIFY( !tr.isValid() );

  QgsCoordinateReferenceSystem srs1;
  srs1.createFromSrid( 3994 );
  QgsCoordinateReferenceSystem srs2;
  srs2.createFromSrid( 4326 );

  // valid source, invalid destination
  QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem() );
  QVERIFY( !tr2.isValid() );

  // invalid source, valid destination
  QgsCoordinateTransform tr3( QgsCoordinateReferenceSystem(), srs2 );
  QVERIFY( !tr3.isValid() );

  // valid source, valid destination
  QgsCoordinateTransform tr4( srs1, srs2 );
  QVERIFY( tr4.isValid() );

  // try to invalidate by setting source as invalid
  tr4.setSourceCrs( QgsCoordinateReferenceSystem() );
  QVERIFY( !tr4.isValid() );

  QgsCoordinateTransform tr5( srs1, srs2 );
  // try to invalidate by setting destination as invalid
  tr5.setDestinationCrs( QgsCoordinateReferenceSystem() );
  QVERIFY( !tr5.isValid() );
}
Ejemplo n.º 3
0
void test_SHARC2() {
	SumOfSines vox1(196), vox2(196), vox3(196), vox4(196), vox5(196);
	SHARC_Library * lib;
	SHARC_Spectrum * sp1, * sp2, * sp3, * sp4, * sp5;
	lib = new SHARC_Library("../../../Code/sharc");
							// access a spectrum, load it into a SumOfSines, and scale it by a triangle envelope
	sp1 = lib->spectrum_named("altoflute_vibrato", "g3");	
	vox1.add_partials(csl_min(sp1->_num_partials, 20), sp1->_partials);
	vox1.create_cache();			// cache the waveform (since it's a harmonic overtone spectrum)
	Triangle tr1(3, 0.75); 			
	vox1.set_scale(tr1);
							// repeat for 3 other delayed examples
	sp2 = lib->spectrum_named("bass_clarinet", "g3");	
	vox2.add_partials(csl_min(sp2->_num_partials, 20), sp2->_partials);
	vox2.create_cache();			// cache the waveform
	Triangle tr2(3, 0.75); 		
	vox2.set_scale(tr2);
	sp3 = lib->spectrum_named("cello_vibrato", "g3");	
	vox3.add_partials(csl_min(sp3->_num_partials, 20), sp3->_partials);
	vox3.create_cache();			// cache the waveform
	Triangle tr3(3, 0.75); 		
	vox3.set_scale(tr3);
	sp4 = lib->spectrum_named("trombone", "g3");	
	vox4.add_partials(csl_min(sp4->_num_partials, 20), sp4->_partials);
	vox4.create_cache();			// cache the waveform
	Triangle tr4(3, 0.75); 		
	vox4.set_scale(tr4);
	sp5 = lib->spectrum_named("violin_martele", "g3");	
	vox5.add_partials(csl_min(sp4->_num_partials, 20), sp4->_partials);
	vox5.create_cache();			// cache the waveform
	Triangle tr5(3, 0.75); 		
	vox5.set_scale(tr5);

	Mixer mix(2);		// create a stereo mixer
	mix.add_input(vox1);	mix.add_input(vox2); 	
	mix.add_input(vox3); 	mix.add_input(vox4); 	mix.add_input(vox5);
	
	logMsg("playing SumOfSines mix...");	// I don't use run_test() here because I need to trigger the envelopes while it's playing	
	gIO->set_root(mix);			// turn it on
	tr1.trigger();				// trigger the 1st envelope
	usleep(1500000);			// wait 1.5 sec
	tr2.trigger();				// trigger the 2nd envelope
	usleep(1500000);			// wait 1.5 sec
	tr3.trigger();				// trigger the 3rd envelope
	usleep(1500000);			// wait 1.5 sec
	tr4.trigger();				// trigger the 4th envelope
	usleep(1500000);			// wait 1.5 sec
	tr5.trigger();				// trigger the 5th envelope
	usleep(3000000);			// wait 3 seconds
	gIO->clear_root();			// turn it off
	logMsg("SumOfSines done.");
}
Ejemplo n.º 4
0
void loop() {	stateChanged=false;
int pn1=random(0,11);
switch (pn1) {
	case 0:
		//None
		tr2();
		break;
	case 1:
		//None
		tr3();
		break;
	case 2:
		//None
		tr4();
		break;
	case 3:
		//None
		tr5();
		break;
	case 4:
		//None
		tr7();
		break;
	case 5:
		//wait 1 milli
		tr8();
		break;
	case 6:
		//None
		tr9();
		break;
	case 7:
		//None
		tr10();
		break;
	case 8:
		//None
		tr11();
		break;
	case 9:
		//None
		tr6();
		break;
	case 10:
		//None
		tr12();
		break;
	}
if (stateChanged){
	outputStatusLine();}
}
void fillPoisson(int nbg, int nsiglike_sideband, int nsideband, TH1 * fill, int prior = JEFFREYS_PRIOR, int N = 10000) 
{
  TRandom3 tr3(0);
  for (int i = 0; i < N; i++)
  {
    if (prior == FLAT_PRIOR) 
    {
      fill->Fill(tr3.Poisson(gammarnd(nbg+1,1) * gammarnd(nsiglike_sideband+1,1) / gammarnd(nsideband+1,1))); 
    }
    else if (prior == JEFFREYS_PRIOR) 
    {
      fill->Fill(tr3.Poisson(gammarnd(nbg+0.5,1) * gammarnd(nsiglike_sideband+0.5,1) / gammarnd(nsideband+0.5,1))); 
    }
    else
    {
      fill->Fill(tr3.Poisson(gammarnd(nbg,1) * gammarnd(nsiglike_sideband,1) / gammarnd(nsideband,1))); 
    }
  }
}
Ejemplo n.º 6
0
void ZShape2dMC(){
  double signal_weight = 3531.89/30459500.;//3504
  if (!doMG) signal_weight = 1966.7 / 42705454.; //

  TH1D* mc_truegen;
  vector<TH1D*> mc_truegen_cteq, mc_truegen_fsr_pileup;
  GetGen(signal_weight, mc_truegen, mc_truegen_cteq, mc_truegen_fsr_pileup);
  
  cout<<"Get MC distribution"<<endl;
  vector<TGraphAsymmErrors*> g_MC_phistar;
  TGraphAsymmErrors* g_MC_phistar_temp1=ConvertToTGraph(mc_truegen);
  g_MC_phistar.push_back(g_MC_phistar_temp1);
  
  vector<TGraphAsymmErrors*> g_MC_phistar_cteq;
  for (size_t u=0; u<mc_truegen_cteq.size(); u++){
    TGraphAsymmErrors* g_MC_phistar_temp=ConvertToTGraph(mc_truegen_cteq[u]);
    g_MC_phistar_cteq.push_back(g_MC_phistar_temp);
  }
  vector<TGraphAsymmErrors*> g_MC_phistar_fsr_pileup;
  for (size_t u=0; u<mc_truegen_fsr_pileup.size(); u++){
    TGraphAsymmErrors* g_MC_phistar_temp=ConvertToTGraph(mc_truegen_fsr_pileup[u]);
    g_MC_phistar_fsr_pileup.push_back(g_MC_phistar_temp);
  }

  vector<TGraphAsymmErrors *> g_MC_norm = CreateCopy(g_MC_phistar);
  vector<TGraphAsymmErrors *> g_MC_norm_cteq = CreateCopy(g_MC_phistar_cteq);
  vector<TGraphAsymmErrors *> g_MC_norm_fsr_pileup = CreateCopy(g_MC_phistar_fsr_pileup);
  NormalizeGraph(g_MC_phistar, 0);
  NormalizeGraph(g_MC_phistar_cteq, 0);
  NormalizeGraph(g_MC_phistar_fsr_pileup, 0);
  NormalizeGraph(g_MC_norm, 1);
  NormalizeGraph(g_MC_norm_cteq, 1);
  NormalizeGraph(g_MC_norm_fsr_pileup, 1);

  TGraphAsymmErrors* g_syst_mc_cteq = CalcTotalSysU_updown(g_MC_phistar_cteq,g_MC_phistar_cteq[0],1,1);
  TGraphAsymmErrors* g_syst_mc_fsr  = CalcTotalSysU_fsr(g_MC_phistar_fsr_pileup[0],g_MC_phistar[0]);
  TGraphAsymmErrors* g_syst_norm_mc_cteq = CalcTotalSysU_updown(g_MC_norm_cteq,g_MC_norm_cteq[0],1,1);
  TGraphAsymmErrors* g_syst_norm_mc_fsr  = CalcTotalSysU_fsr(g_MC_norm_fsr_pileup[0],g_MC_norm[0]);
  
  vector<TGraphAsymmErrors *> g_mc_syst;
  g_mc_syst.push_back(g_MC_phistar[0]);
  g_mc_syst.push_back(g_syst_mc_fsr);
  if (!doMG) g_mc_syst.push_back(g_syst_mc_cteq);
  vector<std::string> syst_mc_list;
  syst_mc_list.push_back("unfolding");
  syst_mc_list.push_back("fsr");
  if (!doMG) syst_mc_list.push_back("cteq");
  TGraphAsymmErrors* g_mc_final=GetMCFinal(g_mc_syst, syst_mc_list, 0);
  
  vector<TGraphAsymmErrors *> g_mc_syst_norm;
  g_mc_syst_norm.push_back(g_MC_norm[0]);
  g_mc_syst_norm.push_back(g_syst_norm_mc_fsr);
  if (!doMG) g_mc_syst_norm.push_back(g_syst_norm_mc_cteq);
  vector<std::string> syst_mc_list_norm;
  syst_mc_list_norm.push_back("unfolding");
  syst_mc_list_norm.push_back("fsr");
  if (!doMG) syst_mc_list_norm.push_back("cteq");
  TGraphAsymmErrors* g_mc_final_norm=GetMCFinal(g_mc_syst_norm, syst_mc_list_norm, 1);
  
  string textn="Output/TESTMC_Graph_Abs_";
  if (doMG)   textn+="MG_";
  else        textn+="PH_";
  if (elec==0)textn+="Dressed.root";
  if (elec==1)textn+="Born.root";
  if (elec==2)textn+="Naked.root";
  TFile tr2(textn.c_str(),"RECREATE");
  g_mc_final->Write();

  textn="Output/TESTMC_Graph_Norm_";
  if (doMG)   textn+="MG_";
  else        textn+="PH_";
  if (elec==0)textn+="Dressed.root";
  if (elec==1)textn+="Born.root";
  if (elec==2)textn+="Naked.root";
  TFile tr3(textn.c_str(),"RECREATE");
  g_mc_final_norm->Write();
}
Ejemplo n.º 7
0
void CTTypes::RunTestCaseL(TInt aCurTestCase)
	{
	switch(aCurTestCase)
		{
	case 1:
		{
		__UHEAP_MARK;
		TestRgb tr1(0,0,0, this);
		TestRgb tr2(100,100,100, this);
		TestRgb tr3(10,20,30, this);
		TestRgb tr4(110,160,210, this);
		TestRgb tr5(255,255,255, this);
		INFO_PRINTF1(_L("TRgb"));
		tr1.Test();
		tr2.Test();
		tr3.Test();
		tr4.Test();
		tr5.Test();
		((CTTypesStep*)iStep)->CloseTMSGraphicsStep();
		__UHEAP_MARKEND;
		}
		break;
	case 2:
		{
		INFO_PRINTF1(_L("TTypeface"));
		TestTypeface ttf1(_L(""), 0, this);
		TestTypeface ttf2(_L("Font name"), 1, this);
		TestTypeface ttf3(_L("Font name"), 2, this);
		TestTypeface ttf4(_L("Font name"), 3, this);
		TestTypeface ttf5(_L("Font name"), 4, this);
		TestTypeface ttf6(_L("Font name"), 5, this);
		TestTypeface ttf7(_L("Font name"), 6, this);
		TestTypeface ttf8(_L("Another font name"), 7, this);
		ttf1.Test();
		ttf2.Test();
		ttf3.Test();
		ttf4.Test();
		ttf5.Test();
		ttf6.Test();
		ttf7.Test();
		ttf8.Test();
		}
		break;
	case 3:
		{
		TestMargins tm1(0,0,0,0, this);
		TestMargins tm2(10,20,30,40, this);
		TestMargins tm3(-10,-20,-30,-40, this);
		INFO_PRINTF1(_L("TMargins"));
		tm1.Test();
		tm2.Test();
		tm3.Test();
		}
		break;
	case 4:
		{
		TestPageSpec tps1(TPageSpec::EPortrait,TSize(0,0), this);
		TestPageSpec tps2(TPageSpec::ELandscape,TSize(0,0), this);
		TestPageSpec tps3(TPageSpec::EPortrait,TSize(10,-5), this);
		TestPageSpec tps4(TPageSpec::ELandscape,TSize(15,-20), this);
		TestPageSpec tps5(TPageSpec::EPortrait,TSize(1000,1500), this);
		TestPageSpec tps6(TPageSpec::ELandscape,TSize(2000,500), this);
		INFO_PRINTF1(_L("TPageSpec"));
		tps1.Test();
		tps2.Test();
		tps3.Test();
		tps4.Test();
		tps5.Test();
		tps6.Test();
		}
		break;
	case 5:
		{
		INFO_PRINTF1(_L("FontEffect"));
        	((CTTypesStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-0002"));
		TestFontEffect te(this); 
		((CTTypesStep*)iStep)->RecordTestResultL();
		te.Test();
		}
		break;
	case 6:
		{
		INFO_PRINTF1(_L("TFontSyle"));
		TestTFontStyle ts(this);
		ts.Test();
		}
		break;
	case 7:
		{
		TTypeface typeface;
		typeface.iName=_L("Font name");
		TFontStyle fontstyle;
		TestFontSpec tfspec(typeface,200,fontstyle, this);
		INFO_PRINTF1(_L("TFontSpec"));
		tfspec.Test();
		}
		break;
	case 8:
		{
/*
		TestLine tl1(TPoint(10,10),TPoint(90,90), this);
		TestLine tl2(TPoint(100,150),TPoint(50,-50), this);
		TestLine tl3(TPoint(-50,50),TPoint(60,-40), this);
		TestLine tl4(TPoint(-100,0),TPoint(0,200), this);
		TestLine tl5(TPoint(150,-50),TPoint(50,75), this);
		TestLine tl6(TPoint(0,-100),TPoint(-50,-150), this);
		TestLine tl7(TPoint(-1000,-1000),TPoint(1000,1000), this);
		TestLine tl8(TPoint(1000,-1000),TPoint(-1000,1000), this);
		TestLine tl9(TPoint(500,-1000),TPoint(-500,1000), this);
		TestLine tl10(TPoint(-500,-1000),TPoint(500,1000), this);
		TestLine tl11(TPoint(1000,-500),TPoint(-1000,500), this);
		TestLine tl12(TPoint(1000,500),TPoint(-1000,-500), this);
		INFO_PRINTF1(_L("TLinearDDA"));
		tl1.Test();
		tl2.Test();
		tl3.Test();
		tl4.Test();
		tl5.Test();
		tl6.Test();
		tl7.Test();
		tl8.Test();
		tl9.Test();
		tl10.Test();
		tl11.Test();
		tl12.Test();
*/
		INFO_PRINTF1(_L("TLinearDDA is only for Graphics team. Removed."));
		}
		break;
	case 9:
		{
		INFO_PRINTF1(_L("CTypefaceStore"));
		TestTFStore ttfs(this);
		ttfs.Test();
		}
		break;
	case 10:
		{
		INFO_PRINTF1(_L("CFontCache"));
		TestFontCache tfc(this);
		tfc.Test();
		}
		break;
	case 11:
		{
/*
		INFO_PRINTF1(_L("CScaleCropPicture"));
		TestPicture tp(this);
		tp.Test();
*/
		INFO_PRINTF1(_L("CScaleCropPicture is only for Graphics team. Removed."));
		}
		break;
	case 12:
		{
/*
		INFO_PRINTF1(_L("CPalette"));
		TestPalette tpal(this);
		tpal.Test();
*/
		INFO_PRINTF1(_L("CPalette is only for Graphics team. Removed."));
		}
		break;
	case 13:
		{
		INFO_PRINTF1(_L("TDisplayModeUtils"));
		TestDisplayModeUtils tdmu(this);
		tdmu.Test();
		}
		break;
	case 14:
        	((CTTypesStep*)iStep)->SetOverallTestStepID(_L("GRAPHICS-GDI-0001"));
		((CTTypesStep*)iStep)->RecordTestResultL();
		((CTTypesStep*)iStep)->CloseTMSGraphicsStep();
		TestComplete();		
		break;
		}
	}
Ejemplo n.º 8
0
int main_test_tree(int argc, char **argv) {
	unsigned int maxloop = 1;
	if (argc > 1)
		maxloop = atoi(argv[1]);

	for (unsigned int j = 0; j < maxloop; ++j) {
		tree<std::string> tr9;
		tr9.set_head("hi");
		tr9.insert(tr9.begin().begin(), "0");
		tr9.insert(tr9.begin().begin(), "1");
		print_tree(tr9, tr9.begin(), tr9.end());

		tree<std::string> tr;
		tree<std::string>::pre_order_iterator html, body, h1, h3, bh1, mv1;

		std::cout << "empty tree to begin with:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		html = tr.insert(tr.begin(), "html");
		tr.insert(html, "extra");
//		tr.insert(html,"zextra2");
		body = tr.append_child(html, "body");
		h1 = tr.append_child(body, "h1");
		std::cout << tr.index(h1) << std::endl;
		bh1 = tr.insert(h1, "before h1");
		tr.append_child(h1, "some text");
		tree<std::string>::sibling_iterator more_text = tr.append_child(body,
				"more text");

		std::cout << " 'more text' is sibling " << tr.index(more_text)
				<< " in its sibling range" << std::endl;

		std::cout << "filled tree:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		std::cout << "filled tree, post-order traversal:" << std::endl;
		print_tree_post(tr, tr.begin_post(), tr.end_post());

		tr.swap(bh1);
		std::cout << "swapped elements:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());
		tr.swap(h1);
		std::cout << "swapped back:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		tree<std::string> copytree(h1);
		std::cout << "copied tree:" << std::endl;
		print_tree(copytree, copytree.begin(), copytree.end());

		// Now test the STL algorithms
		std::cout << "result of search for h1 and kasper:" << std::endl;
		tree<std::string>::pre_order_iterator it;
		it = std::find(tr.begin(), tr.end(), std::string("h1"));
		if (it != tr.end())
			print_tree(tr, it, tr.next_sibling(it));
		else
			std::cout << "h1 not found" << std::endl;
		it = std::find(tr.begin(), tr.end(), std::string("kasper"));
		if (it != tr.end())
			print_tree(tr, it, tr.next_sibling(it));
		else
			std::cout << "kasper not found" << std::endl;
		std::cout << std::endl;

		// remove the h1, replace it with new subtree
		tree<std::string> replacement;
		h3 = replacement.insert(replacement.begin(), "h3");
		replacement.append_child(h3, "text in h3");
		std::cout << "replacement tree:" << std::endl;
		print_tree(replacement, replacement.begin(), replacement.end());
		print_tree(tr, tr.begin(), tr.end());
		h1 = tr.replace(tree<std::string>::sibling_iterator(h1),
				tr.next_sibling(h1), tree<std::string>::sibling_iterator(h3),
				tr.next_sibling(h3));
		std::cout << "filled tree with replacement done:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		// replace h3 node while keeping children
		h1 = tr.replace(h1, "<foobar>");
		print_tree(tr, tr.begin(), tr.end());

		// add a sibling to the head
		tr.insert_after(h1, "more");

		// Copy object.
		tree<std::string> tr2 = tr;
		print_tree(tr2, tr2.begin(), tr2.end());
		tree<std::string> tr3(tr);

		// reparent "before h1" to h3 node
		tr.reparent(h1, bh1, tr.next_sibling(bh1));
		std::cout << "moved content:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		// iterate over children only
		tree<std::string>::sibling_iterator ch = tr.begin(h1);
		std::cout << "children of h1:" << std::endl;
		while (ch != tr.end(h1)) {
			std::cout << (*ch) << std::endl;
			++ch;
		}
		std::cout << std::endl;

		// flatten the h3 node
		tr.flatten(h1);
		std::cout << "flattened (at h3) tree:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		// Erase the subtree of tr below body.
		tr.erase_children(body);
		std::cout << "children of body erased:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());
		it = std::find(tr.begin(), tr.end(), "h1");
		if (it != tr.end())
			print_tree(tr, it, tr.next_sibling(it));
		else
			std::cout << "h1 not found" << std::endl;

		// Erase everything
		tr.erase(tr.begin());
		std::cout << "erased tree:" << std::endl;
		print_tree(tr, tr.begin(), tr.end());

		// The copies are deep, ie. all nodes have been copied.
		std::cout << "copies still exist:" << std::endl;
		print_tree(tr2, tr2.begin(), tr2.end());
		print_tree(tr3, tr3.begin(), tr3.end());

		// Test comparison
		std::cout << "testing comparison functions:" << std::endl;
		std::cout
				<< std::equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 1)"
				<< std::endl;
		// modify content but not structure
		tree<std::string>::pre_order_iterator fl3 = tr3.begin();
		fl3 += 4; // pointing to "<foobar>" node
		std::cout << (*fl3) << std::endl;
		std::string tmpfl3 = (*fl3);
		(*fl3) = "modified";
		std::cout
				<< std::equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 0)"
				<< std::endl;
		std::cout
				<< tr2.equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 0)"
				<< std::endl;
		std::cout << tr2.equal(tr2.begin(), tr2.end(), tr3.begin(), truefunc)
				<< " (should be 1)" << std::endl;
		// modify tr3 structure (but not content)
		(*fl3) = tmpfl3;
		tr3.flatten(fl3);
		std::cout << "tree flattened, test again" << std::endl;
		print_tree(tr3, tr3.begin(), tr3.end());

		// Test comparison again
		std::cout
				<< tr2.equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 0)"
				<< std::endl;
		std::cout
				<< std::equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 1)"
				<< std::endl;
		// Change content
		(*fl3) = "modified";
		// Test comparison again
		std::cout
				<< std::equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 0)"
				<< std::endl;
		std::cout
				<< tr2.equal(tr2.begin(), tr2.end(), tr3.begin(),
						std::equal_to<std::string>()) << " (should be 0)"
				<< std::endl;

		// Testing sort. First add a subtree to one leaf
		tree<std::string>::pre_order_iterator txx3 = tr3.begin();
		txx3 += 5;
		tr3.append_child(txx3, "ccc");
		tr3.append_child(txx3, "bbb");
		tr3.append_child(txx3, "bbb");
		tr3.append_child(txx3, "aaa");
		std::less<std::string> comp;
		tree<std::string>::pre_order_iterator bdy = tr3.begin();
		bdy += 2;
		assert(tr.is_valid(bdy));
		std::cout << "unsorted subtree:" << std::endl;
		print_tree(tr3, tr3.begin(), tr3.end());
		tree<std::string>::sibling_iterator sortit1 = tr3.begin(bdy), sortit2 =
				tr3.begin(bdy);
		sortit1 += 2;
		sortit2 += 4;
		assert(tr.is_valid(sortit1));
		assert(tr.is_valid(sortit2));
		std::cout << "partially sorted subtree: (" << "sorted from "
				<< (*sortit1) << " to " << (*sortit2)
				<< ", excluding the last element)" << std::endl;

		mv1 = tr3.begin();
		++mv1;
		tr3.sort(sortit1, sortit2);
		print_tree(tr3, tr3.begin(), tr3.end());
		tr3.sort(tr3.begin(bdy), tr3.end(bdy), comp, true); // false: no sorting of subtrees
//    Sorting the entire tree, level by level, is much simpler:
//		tr3.sort(tr3.begin(), tr3.end(), true);
		std::cout << "sorted subtree:" << std::endl;
		print_tree(tr3, tr3.begin(), tr3.end());

		// Michael's problem
//		std::cout << mv1.node << ", " << tr3.feet << ", " << tr3.feet->prev_sibling << std::endl;
//		std::cout << mv1.node->next_sibling << ", " << tr3.feet->prev_sibling << ", " << tr3.end().node << std::endl;
//		tr3.sort(tr3.begin(), tr3.end(), true);		
//		std::cout << mv1.node << ", " << tr3.feet << ", " << tr3.feet->prev_sibling << std::endl;
//		std::cout << mv1.node->next_sibling << ", " << tr3.feet->prev_sibling << ", " << tr3.end().node << std::endl;
//		print_tree(tr3, tr3.begin(), tr3.end());
//		tr3.sort(tr3.begin(), tr3.end(), true);
//		std::cout << mv1.node << ", " << tr3.feet << ", " << tr3.feet->prev_sibling << std::endl;
//		std::cout << mv1.node->next_sibling << ", " << tr3.feet->prev_sibling << ", " << tr3.end().node << std::endl;
//		print_tree(tr3, tr3.begin(), tr3.end());
//		return 1;

		// Test merge algorithm.
		std::cout << "test merge" << std::endl;
		tree<std::string> mtree;
		tree<std::string>::pre_order_iterator mt1, mt2, mt3;
		mt1 = mtree.insert(mtree.begin(), "html");
		mt2 = mtree.append_child(mt1, "head");
		mt3 = mtree.append_child(mt1, "body");
// Adding it without head having any children tests whether we can
// insert at the end of an empty list of children. 
		mtree.append_child(mt2, "title");
		mtree.append_child(mt3, "h1");
		mtree.append_child(mt3, "h1");

		tree<std::string> mtBree;
		tree<std::string>::pre_order_iterator mtB1, mtB2;
		mtB1 = mtBree.insert(mtBree.begin(), "head");
		mtB2 = mtBree.append_child(mtB1, "another title");
		print_tree(mtree, mtree.begin(), mtree.end());
		print_tree(mtBree, mtBree.begin(), mtBree.end());

		mtree.merge(mtree.begin(), mtree.end(), mtBree.begin(), mtBree.end(),
				true);
		print_tree(mtree, mtree.begin(), mtree.end());
		mtree.merge(mtree.begin(mtree.begin()), mtree.end(mtree.begin()),
				mtBree.begin(), mtBree.end(), true);
		print_tree(mtree, mtree.begin(), mtree.end());

		// Print tree in reverse (test operator--)
		print_tree_rev(mtree, mtree.end(), mtree.begin());
		print_tree_rev_post(mtree, mtree.end_post(), mtree.begin_post());

		// Breadth-first
		tree<std::string> bft;
		tree<std::string>::iterator bfB, bfC, bfD;
		bft.set_head("A");
		bfB = bft.append_child(bft.begin(), "B");
		bfC = bft.append_child(bft.begin(), "C");
		bfD = bft.append_child(bft.begin(), "D");
		bft.append_child(bfB, "E");
		bft.append_child(bfB, "F");
		bft.append_child(bfC, "G");
		bft.append_child(bfC, "H");
		bft.append_child(bfD, "I");
		tree<std::string>::breadth_first_queued_iterator bfq =
				bft.begin_breadth_first();
		while (bfq != bft.end_breadth_first()) {
			std::cout << *bfq << std::endl;
			++bfq;
		}

		print_tree(bft, bft.begin(), bft.end());
		bft.wrap(bfD, "wrap");
		print_tree(bft, bft.begin(), bft.end());

		tree<std::string>::leaf_iterator li = tr.begin_leaf(bfC);
		while (li != tr.end_leaf(bfC)) {
			std::cout << *li << std::endl;
			++li;
		}

//		test_move_constructor();

	}
	return 0;
}
Ejemplo n.º 9
0
int testTriangle() {
	int numErr = 0;

	logMessage(_T("TESTING  -  class GM_3dTriangle ...\n\n"));

	// Default constructor, triangle must be invalid
	GM_3dTriangle tr;
	if (tr.isValid()) {
		logMessage(_T("\tERROR - Default constructor creates valid triangle\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Default constructor creates invalid triangle\n"));
	}

	// Get/Set
	GM_3dPoint v1(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint v2(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint v3(getRandomDouble(), getRandomDouble(), getRandomDouble());
	tr[0] = GM_3dLine(v1, v2);
	tr[1] = GM_3dLine(v2, v3);
	tr[2] = GM_3dLine(v3, v1);
	if (!tr.isValid() || tr[0].begin() != v1 || tr[0].end() != v2 || tr[1].begin() != v2 || tr[1].end() != v3
				|| tr[2].begin() != v3 || tr[2].end() != v1) {
		logMessage(_T("\tERROR - Get/Set not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Get/Set working\n"));
	}

	// Copy constructor
	GM_3dTriangle tr1(tr);
	if (!tr1.isValid() || tr[0] != tr1[0] || tr[1] != tr1[1] || tr[2] != tr1[2]) {
		logMessage(_T("\tERROR - Copy constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Copy constructor working\n"));
	}

	// Constructor (points)
	GM_3dTriangle tr2(v1, v2, v3);
	if (!tr1.isValid() || tr[0] != tr2[0] || tr[1] != tr2[1] || tr[2] != tr2[2]) {
		logMessage(_T("\tERROR - Constructor (points) not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor (points) working\n"));
	}

	// Constructor (lines)
	GM_3dTriangle tr3(tr[0], tr[1], tr[2]);
	if (!tr1.isValid() || tr[0] != tr3[0] || tr[1] != tr3[1] || tr[2] != tr3[2]) {
		logMessage(_T("\tERROR - Constructor (lines) not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor (lines) working\n"));
	}

	// Inversion
	tr1.invert();
	if (!tr1.isValid() || tr1[0].begin() != tr[0].end() || tr1[0].end() != tr[0].begin() || tr1[1].begin() != tr[1].end() || tr1[1].end() != tr[1].begin() ||
				tr1[2].begin() != tr[2].end() || tr1[2].end() != tr[2].begin()) {
		logMessage(_T("\tERROR - Triangle inversion not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Triangle inversion working\n"));
	}

	// Vertical check
	GM_3dPoint vPoint = GM_3dLine(v1, v2).center();
	vPoint.z(vPoint.z() + getRandomDouble());
	GM_3dTriangle VTr(v1, v2, vPoint);
	if (!VTr.isValid() || !VTr.isVertical()) {
		logMessage(_T("\tERROR - Vertical check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Vertical check working\n"));
	}

	// Horizontal check
	GM_3dTriangle HTr(tr);
	double z = getRandomDouble();
	for (unsigned int i = 0 ; i < 3 ; i++) {
		HTr[i].begin().z(z);
		HTr[i].end().z(z);
	}
	if (!HTr.isValid() || !HTr.isHorizontal()) {
		logMessage(_T("\tERROR - Horizontal check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Horizontal check working\n"));
	}

	// Connection check
	GM_3dTriangle discTr(tr);
	discTr[0].begin().x(discTr[0].begin().x() + 2.0 * GM_DIFF_TOLERANCE);
	if (!discTr.isValid() || discTr.isConnected() || !tr.isConnected()) {
		logMessage(_T("\tERROR - Connection check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Connection check working\n"));
	}

	// Max/Min z
	double maxZ = tr.maxZ();
	double minZ = tr.minZ();
	double checkMaxZ = -DBL_MAX;
	double checkMinZ = DBL_MAX;
	for (unsigned int i = 0 ; i < 3 ; i++) {
		if (tr[i].begin().z() > checkMaxZ) checkMaxZ = tr[i].begin().z();
		if (tr[i].begin().z() < checkMinZ) checkMinZ = tr[i].begin().z();
		if (tr[i].end().z() > checkMaxZ) checkMaxZ = tr[i].end().z();
		if (tr[i].end().z() < checkMinZ) checkMinZ = tr[i].end().z();
	}
	if (checkMinZ != minZ || checkMaxZ != maxZ) {
		logMessage(_T("\tERROR - Min/Max z not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Min/Max z working\n"));
	}

	return numErr;
}