Beispiel #1
0
int main(void)
{
	static const struct st3 a = {1, 2, 3, 4, 5, 6};

	l1(100);
	l2(100, 200);
	l3(100, 200, 300);
	l4(100, 200, 300, 400);
	l5(100, 200, 300, 400, 500);
	l6(100, 200, 300, 400, 500, 600);
	l7(100, 200, 300, 400, 500, 600, 700);
	l8(100, 200, 300, 400, 500, 600, 700, 800);

	d1();
	d2(43);
	d3(100, 200);
	d4(a);
	d5('a', 43, a);
	d6('a', 1);

	c1(44);
	c2(100, 'a', 3.4);
	c3(200, 2.777, 'q');
	c4(200, 1);
	c5(1.1, 2.2);
	c6(1.23, 45.6);
	c7('z', 0x200);

	a1('a');
	a2(10);
	a3(20);
	a4(102030405060LL);

	b1('a', 20);
	b2(30, 'b');
	b3(10, 20, 30, 40, 50, 60);

	s1(sx);
	s1p(&sx);
	s2(sy);
	s3(sz);
	s4(sq);
	s5(sa);
	s6(sb);

	r1();
	r3();
	r4();

	q1(200, sx);
	q2(300, 't', sx);
	q3(400, 410, sy);
	q4(500, 510, sq);
	q5(600, 610, 'z', 'q', sq);

	real1("fresh air");
	real2();

	return 0;
}
Beispiel #2
0
    void initB() {
        this->clearAppend(this->m_csB);

        R1Variable<T> d1(1), d2(2), d3(3), d4(4), d5(5), d6(6);

        this->m_csB.addConstraint(d1 * d2 == d5);
        this->m_csB.addConstraint(d1 * d3 == d6);
        this->m_csB.addConstraint(d5 * d6 == d4);

        this->m_csB.swap_AB_if_beneficial();

        // witness always consistent
        this->m_witnessB.assignVar(d1, T(m_d1));
        this->m_witnessB.assignVar(d2, T(m_d2));
        this->m_witnessB.assignVar(d3, T(m_d3));
        this->m_witnessB.assignVar(d4, T(m_d1 * m_d1 * m_d2 * m_d3));
        this->m_witnessB.assignVar(d5, T(m_d1 * m_d2));
        this->m_witnessB.assignVar(d6, T(m_d1 * m_d3));

        // public inputs may be inconsistent
        this->m_inputB.assignVar(d1, T(m_d1));
        this->m_inputB.assignVar(d2, T(m_d2));
        this->m_inputB.assignVar(d3, T(m_d3));
        this->m_inputB.assignVar(d4, T(m_d4));

        this->finalize(this->m_csB);
    }
Beispiel #3
0
void testCompare()
{
    // Date1 = Date2
    vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2);
    vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2);

    VASSERT_EQ("1.1", true,  d1 == d2);
    VASSERT_EQ("1.2", false, d1 != d2);
    VASSERT_EQ("1.3", true,  d1 <= d2);
    VASSERT_EQ("1.4", false, d1 <  d2);
    VASSERT_EQ("1.5", true,  d1 >= d2);
    VASSERT_EQ("1.6", false, d1 >  d2);

    // Date1 < Date2
    vmime::datetime d3(2005, 4, 22, 14, 6, 0);
    vmime::datetime d4(2005, 4, 22, 15, 6, 0);

    VASSERT_EQ("2.1", false, d3 == d4);
    VASSERT_EQ("2.2", true,  d3 != d4);
    VASSERT_EQ("2.3", true,  d3 <= d4);
    VASSERT_EQ("2.4", true,  d3 <  d4);
    VASSERT_EQ("2.5", false, d3 >= d4);
    VASSERT_EQ("2.6", false, d3 >  d4);

    // Date1 > Date2
    vmime::datetime d5(2005, 4, 22, 15, 6, 0);
    vmime::datetime d6(2005, 4, 22, 14, 6, 0);

    VASSERT_EQ("3.1", false, d5 == d6);
    VASSERT_EQ("3.2", true,  d5 != d6);
    VASSERT_EQ("3.3", false, d5 <= d6);
    VASSERT_EQ("3.4", false, d5 <  d6);
    VASSERT_EQ("3.5", true,  d5 >= d6);
    VASSERT_EQ("3.6", true,  d5 >  d6);
}
Beispiel #4
0
TEST(ArrayTest, getNumCols) {
	TwoDArray<int> i5(10, 5, 42);
	TwoDArray<double> d5(2, 9, 9.9);
	TwoDArray<std::string> s5(6, 8, "e");
  EXPECT_EQ(5, i5.access(8,2));
  EXPECT_EQ(9, d5.access(0,0));
  EXPECT_EQ(8, s5.access(5,7));

}
Beispiel #5
0
int  main() {
  LinearGenerator linearGen(0,20,2);
  RandomGenerator randomGen(10);
  FibonacciGenerator fibGen(10);
  // MOCK 1
  std::vector<double> myVector;
  myVector.push_back(15);
  myVector.push_back(20);
  myVector.push_back(35);
  myVector.push_back(40);
  myVector.push_back(50);
  MockGenerator mockGen(myVector);
  // MOCK 2
  std::vector<double> myVector2;
  myVector2.push_back(1);
  myVector2.push_back(10);
  myVector2.push_back(50);
  MockGenerator mockGen2(myVector2);

  LinearInterpolationCalculator linInterCalc;
  NearestRankCalculator nearestRankCalc;

  DistributionTester mock0(&mockGen, &nearestRankCalc);
  DistributionTester mock1(&mockGen, &linInterCalc);
  DistributionTester mock2(&mockGen2, &linInterCalc);

  DistributionTester d1(&linearGen, &linInterCalc);
  DistributionTester d2(&linearGen, &nearestRankCalc);
  DistributionTester d3(&randomGen, &linInterCalc);
  DistributionTester d4(&randomGen, &nearestRankCalc);
  DistributionTester d5(&fibGen, &linInterCalc);
  DistributionTester d6(&fibGen, &nearestRankCalc);

  std::cout << "d1: " << d1.getPercentile(50) << std::endl;
  std::cout << "d2: " << d2.getPercentile(50) << std::endl;

  std::cout << "mock0: " << mock0.getPercentile(30) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(40) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(50) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(100) << std::endl;

  std::cout << "mock1: " << mock1.getPercentile(10) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(30) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(40) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(90) << std::endl;

  std::cout << "mock2: " << mock2.getPercentile(10) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(20) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(30) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(40) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(50) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(60) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(70) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(80) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(90) << std::endl;
}
Beispiel #6
0
int main()
{
    Sales_data d1("CppPrimer"), d2("JavaCore"), d3("PythonCookBook"),
        d4("CppCore"), d5("AwesomeCPP");
    std::vector<Sales_data> v{d1, d2, d3, d4, d5};

    //! @note   the elements the iterators pointing to
    //!         must match the parameters of the predicate.
    std::sort(v.begin(), v.end(), compareIsbn);

    for (const auto& element : v) std::cout << element.isbn() << " ";
    std::cout << std::endl;
}
TEST(Decimal128Test, TestDecimal128IsNegative) {
    Decimal128 d1("NaN");
    Decimal128 d2("-NaN");
    Decimal128 d3("10.5");
    Decimal128 d4("-10.5");
    Decimal128 d5("Inf");
    Decimal128 d6("-Inf");
    ASSERT_FALSE(d1.isNegative());
    ASSERT_FALSE(d3.isNegative());
    ASSERT_FALSE(d5.isNegative());
    ASSERT_TRUE(d2.isNegative());
    ASSERT_TRUE(d4.isNegative());
    ASSERT_TRUE(d6.isNegative());
}
Beispiel #8
0
int main()
{
    wy_Sales_data d1("aa"), d2("aaaa"), d3("aaa"), d4("z"), d5("aaaaz");
    std::vector<wy_Sales_data> v = {d1,d2,d3,d4,d5};

    //! @note   the elements the iterators pointing to
    //!         must match the parameters of the predicate.
    std::sort(v.begin(), v.end(), compareIsbn);

    for(const auto &element : v)
        std::cout << element.isbn() << " ";
    std::cout <<"\n";

    return 0;
}
Beispiel #9
0
int main()
{
    Sales_data d1("aa"), d2("aaa"), d3("aaa"), d4("z"), d5("aaaz");
    std::vector<Sales_data> v{ d1, d2, d3, d4, d5 };

    std::sort(v.begin(), v.end(), [](const Sales_data &sd1, const Sales_data &sd2)
            {return sd1.isbn().size() < sd2.isbn().size();});

    for (auto &element : v)
        std::cout << element.isbn() << " ";
    std::cout << std::endl;

    return 0;

}
Beispiel #10
0
void ChessGameStateTest::test_en_passant() {
  m_state->move(ChessMove(Point(4, 6), Point(4, 4))); // e4
  m_state->move(ChessMove(Point(7, 1), Point(7, 2))); // h6
  m_state->move(ChessMove(Point(4, 4), Point(4, 3))); // e5
  
  ChessMove d5(Point(3, 1), Point(3, 3));
  d5.setType(ChessMove::EN_PASSANT_TRIGGER);
  m_state->move(d5);
  
  CPPUNIT_ASSERT(m_state->enPassant() == Point(3, 2));
  
  ChessMove exd6(Point(4, 3), Point(3, 2));
  exd6.setType(ChessMove::EN_PASSANT_CAPTURE);
  m_state->move(exd6);
  
  CPPUNIT_ASSERT(m_state->board().get(Point(3, 3)) == ChessPiece());
}
TEST(test_drone_lo_basico, igualdad_drone_funciona_ok) {
    Drone d1(1, algunos_productos());
    Drone d2(1, algunos_productos_pero_en_otro_orden());
    EXPECT_TRUE(d1 == d2);

    Drone d3(2, algunos_productos());
    EXPECT_FALSE(d1 == d3);

    Drone d4(1, otros_productos());
    EXPECT_FALSE(d1 == d4);

    Posicion p = d1.posicionActual();
    p.x++;
    p.y++;
    Drone d5(1, algunos_productos());
    d5.cambiarPosicionActual(p);
    EXPECT_FALSE(d1 == d5);
}
Beispiel #12
0
static void test1() {
    WCValSList<String>  list;
    WCValSList<String>  list2;
    String              d1("svstr#1");
    String              d2("svstr#2");
    String              d3("svstr#3");
    String              d4("svstr#4");
    String              d5("srover:1#1");
    String              d6("srover:1#2");

    list.append( d1 );
    list.append( d2 );
    list.append( d3 );
    list.append( d4 );
    list2.append( d3 );
    list2.append( d2 );
    list2.append( d1 );
    WCValSListIter<String> liter(list);
    String data;
    for(;;) {
        if( !liter() ) break;
        data = liter.current();
        cout << "[" << data << "]\n";
    };
    cout << "\ndo a reset\n\n";
    liter.reset();
    if( liter() ) {
        cout << "[" << liter.current() << "]\n";
    }
    if( liter() ) {
        cout << "[" << liter.current() << "]\n";
    }
    cout << "\ndo a reset to list 2\n\n";
    liter.reset( list2 );
    for(;;) {
        if( !liter() ) break;
        data = liter.current();
        cout << "[" << data << "]\n";
    };
    cout << "\n";
    cout.flush();
}
Beispiel #13
0
void ChessLegalityTest::test_en_passant() {
  m_state->move(ChessMove(Point(4, 6), Point(4, 4)));
  m_state->move(ChessMove(Point(7, 1), Point(7, 2)));
  m_state->move(ChessMove(Point(4, 4), Point(4, 3)));
  
  ChessMove d5(Point(3, 1), Point(3, 3));
  CPPUNIT_ASSERT(m_legality_check->legal(d5));
  CPPUNIT_ASSERT(d5.enPassantTrigger() == Point(3, 2));
  m_state->move(d5);
  
  ChessMove exd6(Point(4, 3), Point(3, 2));
  CPPUNIT_ASSERT(m_legality_check->legal(exd6));
  CPPUNIT_ASSERT(exd6.captureSquare() == Point(3, 3));
  
  m_state->move(ChessMove(Point(7, 6), Point(7, 5)));
  m_state->move(ChessMove(Point(7, 2), Point(7, 3)));
  
  ChessMove tmp(Point(4, 3), Point(3, 2));
  CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp));
}
int main()
{











//        E X T E N D I D O . . .



assert (        mtk::fnExt(mtk::fnDec(5), mtk::fnInc(5)   )
                !=
                mtk::fnExt(mtk::fnDec(2), mtk::fnInc(5)    )
    );

assert (        mtk::fnExt(mtk::fnDec(2), mtk::fnInc(10)   )
                !=
                mtk::fnExt(mtk::fnDec(1), mtk::fnInc(1)    )
    );




//---------------------------------------------------------------------------

//              f n D o u b l e

//---------------------------------------------------------------------------

//  the same..
mtk::fnDouble d1 (3.4);
mtk::fnDouble d2 (3.4, mtk::fnRoundArithmetic   );

mtk::fnDouble d3 (3.4, mtk::fnRoundFloor        );
mtk::fnDouble d4 (3.4, mtk::fnRoundCeil         );
mtk::fnDouble d5 (3.4, mtk::fnRoundNotAllowed   );








//---------------------------------------------------------------------------

//              F i x e d N u m b e r

//---------------------------------------------------------------------------


    //  CONSTRUCTORES   ____________________________________________________


//  double
assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535          ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )
    );

assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )

        );

//  integer
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )

        );



        //  error en tiempo de ejecución
        //  redondeo por defecto para enteros...   notallowed
        /*
            mtk::FixedNumber(
                mtk::fnIntCode  (31416              ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (5                  )
            );
      */

assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31415                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (5                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnIntCode   (31416                  ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (5                      )
            )

        );






//  fnExt
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnExt (
                            mtk::fnDec      (4         ),
                            mtk::fnInc      (1         )
                           )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnExt (
                            mtk::fnDec      (4          ),
                            mtk::fnInc      (1          )
                           )
            )

        );






    //  Métodos de acceso  ________________________________________________

    //  lectura
    assert  (
                mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
                .GetDouble()
                > 3.14
                //  == 3.15
            );


    {
    mtk::FixedNumber fn1 (mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5));

    assert (    fn1.GetExt().GetDec()       ==  2              );
    assert (    fn1.GetDouble()             >   3.14           );
    assert (    fn1.d()                     >   3.14           );
    assert (    fn1.GetExt().GetFormat()    ==  mtk::fnFNormal );



        //  escritura
    fn1.SetDouble(3.11);
    assert (    fn1.GetIntCode()            ==  310 );
    assert (    fn1.GetDouble ()            <   3.11);

    fn1.SetIntCode(39);
    assert (    fn1.GetIntCode()            ==  40 );
    assert (    fn1.GetDouble ()            >   0.39);


    mtk::FixedNumber  fn2 =  fn1;
    assert (    fn1.SetDouble(3.10)         ==  fn2.SetIntCode(310)  );


    assert  (
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31415)
                ==
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31416, mtk::fnRoundArithmetic )

            );


            //  error en tiempo de ejecución,
            //  default round for integers, not allowed
        /*
                mtk::FixedNumber fnp = mtk::FixedNumber(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    ).SetIntCode (31416);

                mtk::FixedNumber fnp2(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    );
                fnp2.SetIntCode (31416);
          */
    }









    //  OPERADORES      ____________________________________________________

        //  relacionales
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            !=
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            <
            mtk::FixedNumber(mtk::fnDouble(20.0) , mtk::fnDec(2), mtk::fnInc(5))
        );


            //  error en tiempo de ejecución, no son comparables
/*
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(1), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
*/





        //  aritméticos

mtk::FixedNumber fna (mtk::fnDouble(3.20), mtk::fnDec(2), mtk::fnInc(1));
assert  (
            ++mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))
            ==
            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))

            &&

            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)
            ==
            (fna-=mtk::fnTicks(5))
        );






{
    mtk::FixedNumber         fn1(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn1.SetDouble(3.14);
    mtk::FixedNumber         fn2(mtk::fnDouble(3.14), mtk::fnDec(3), mtk::fnInc(5) );
    mtk::FixedNumber         fn3(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn3.SetIntCode(3140);

    assert          (fn1 == fn2    &&    fn2 == fn3);
    assert          (   fn3
                        ==
                        mtk::FixedNumber(
                                mtk::fnIntCode(0),
                                mtk::fnDec(3),
                                mtk::fnInc(5)
                               ).SetIntCode(3140)
                    );
}





    #include "support/release_on_exit.hpp"
    return 0;
}
Beispiel #15
0
void analyze(Int_t step){

  // TOF propagation factors (TOF efficiencies)
  fEfficiencyPiTOF = new TF1("fEfficiencyPiTOF","(x > 0.3)*0.7",0,10);
  fEfficiencyKaTOF = new TF1("fEfficiencyKaTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);
  fEfficiencyPrTOF = new TF1("fEfficiencyPrTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);

  // teoretical separation (perfect if equal to the one simualted in sim.C)
  fseparation = new TF1("f","[0]+[1]/x",0,100);
  fseparation->SetParameter(0,0.);
  fseparation->SetParameter(1,7.);
 
  fseparationPiKa = new TF1("fPiKa","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationPiKa->SetParameter(0,2.34);
  fseparationPiKa->SetParameter(1,10);

  fseparationKaPr = new TF1("fKaPr","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationKaPr->SetParameter(0,1);
  fseparationKaPr->SetParameter(1,56);

  // x=p, y=pt/p (normalized at the number of sigma assuming 80 ps resolution)
  fTOFpi = new TF2("fTOFpi","3.7/y*(sqrt(x*x+0.0193210)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFka = new TF2("fTOFka","3.7/y*(sqrt(x*x+0.243049)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFpr = new TF2("fTOFpr","3.7/y*(sqrt(x*x+0.879844)/x-1)*37.47405725",0.3,10,0.5,1);


  // x=p, already normalized in number of sigma (sigma assumed 3.5=7% of the MIP)
  fTPCpi = new TF1("fTPCpi",BetheBlochAleph,0,10,6);
  fTPCpi->SetParameter(0,fKp1);
  fTPCpi->SetParameter(1,fKp2);
  fTPCpi->SetParameter(2,fKp3);
  fTPCpi->SetParameter(3,fKp4);
  fTPCpi->SetParameter(4,fKp5);
  fTPCpi->SetParameter(5,0.139);
  fTPCka = new TF1("fTPCka",BetheBlochAleph,0,10,6);
  fTPCka->SetParameter(0,fKp1);
  fTPCka->SetParameter(1,fKp2);
  fTPCka->SetParameter(2,fKp3);
  fTPCka->SetParameter(3,fKp4);
  fTPCka->SetParameter(4,fKp5);
  fTPCka->SetParameter(5,0.493);
  fTPCpr = new TF1("fTPCpr",BetheBlochAleph,0,10,6);
  fTPCpr->SetParameter(0,fKp1);
  fTPCpr->SetParameter(1,fKp2);
  fTPCpr->SetParameter(2,fKp3);
  fTPCpr->SetParameter(3,fKp4);
  fTPCpr->SetParameter(4,fKp5);
  fTPCpr->SetParameter(5,0.938);

  Float_t width = 1.0;
  addshift =0;

  invwidth = 1./width;

  Float_t widthTOF = 1.0;
  addshiftTOF =0;

  invwidthTOF = 1./widthTOF;

  TH1D *priorsPt[6];
  TH1D *newpriorsPt[6];
  TH1D *truePt[6];
  TH1D *allPtPos = new TH1D("allPtP","All positive;p_{T} (GeV/#it{c});N",100,0,10);
  TH1D *allPtNeg = new TH1D("allPtN","All negative;p_{T} (GeV/#it{c});N",100,0,10);

  TH3D *priorsKs[3][3];
  TH3D *newpriorsKs[3][3];
  TH3D *truePidKs[3][3];
  TH3D *trueKs;

  TH2D *priorsPhi[3][3];
  TH2D *newpriorsPhi[3][3];
  TH2D *truePidPhi[3][3];
  TH2D *truePhi;

  TH3D *priorsLc[3][3][3];
  TH3D *newpriorsLc[3][3][3];
  TH3D *truePidLc[3][3][3];
  TH3D *trueLc,*mypidLc;

  TH3D *priorsLcbar[3][3][3];
  TH3D *newpriorsLcbar[3][3][3];
  TH3D *truePidLcbar[3][3][3];
  TH3D *trueLcbar,*mypidLcbar;

  Int_t nbinPtFrKa = 8;
  Int_t nbinPtFrPi = 8;
  Int_t nbinY = 1;
  Int_t nbinpol=nbinPtFrKa*nbinPtFrPi*nbinY;
  Double_t normbin = 1./nbinpol;
  Int_t nbinmlc = 100;
  Int_t nbinptlc = 10;

  const char *spec[3] = {"Pi","Ka","Pr"};

  if(step==0){
    priorsPt[0] = new TH1D("oldpriorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    for(Int_t i=1;i<=100;i++)
      priorsPt[0]->SetBinContent(i,1);
    priorsPt[1] = new TH1D("oldpriorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[2] = new TH1D("oldpriorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[3] = new TH1D("oldpriorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[4] = new TH1D("oldpriorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[5] = new TH1D("oldpriorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[1]->Add(priorsPt[0]);
    priorsPt[2]->Add(priorsPt[0]);
    priorsPt[3]->Add(priorsPt[0]);
    priorsPt[4]->Add(priorsPt[0]);
    priorsPt[5]->Add(priorsPt[0]);

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  new TH3D(Form("oldpriorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
	priorsPhi[i][j] =  new TH2D(Form("oldpriorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);


	if(i==0 && j==0){
	  for(Int_t ibx=1;ibx<=200;ibx++)
	    for(Int_t iby=1;iby<=40;iby++){
	      for(Int_t ibz=1;ibz <= nbinpol;ibz++)
		priorsKs[i][j]->SetBinContent(ibx,iby,ibz,1);
	      priorsPhi[i][j]->SetBinContent(ibx,iby,1);
	    }
	}
	else{
	  priorsKs[i][j]->Add(priorsKs[0][0]);
	  priorsPhi[i][j]->Add(priorsPhi[0][0]);
	}

	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  new TH3D(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  priorsLcbar[i][j][k] =  new TH3D(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  if(i==0 && j==0 && k==0){
	    for(Int_t ibx=1;ibx<=nbinmlc;ibx++)
	      for(Int_t iby=1;iby<=nbinptlc;iby++){
		for(Int_t ibz=1;ibz <= nbinpol;ibz++){
		  priorsLc[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		  priorsLcbar[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		}
	      }
	  }
	  else{
	    priorsLc[i][j][k]->Add(priorsLc[0][0][0]);
	    priorsLcbar[i][j][k]->Add(priorsLc[0][0][0]);
	  }
	}
      }
    }
  }
  else{
    TFile *fin = new TFile(Form("step%i.root",step));
    priorsPt[0] = (TH1D *) fin->Get("priorsPtPiP"); 
    priorsPt[0]->SetName("oldpriorsPtPiP");
    priorsPt[1] = (TH1D *) fin->Get("priorsPtKaP"); 
    priorsPt[1]->SetName("oldpriorsPtPiP");
    priorsPt[2] = (TH1D *) fin->Get("priorsPtPrP"); 
    priorsPt[2]->SetName("oldpriorsPtPiP");
    priorsPt[3] = (TH1D *) fin->Get("priorsPtPiM"); 
    priorsPt[3]->SetName("oldpriorsPtPiM");
    priorsPt[4] = (TH1D *) fin->Get("priorsPtKaM"); 
    priorsPt[4]->SetName("oldpriorsPtKaM");
    priorsPt[5] = (TH1D *) fin->Get("priorsPtPrM"); 
    priorsPt[5]->SetName("oldpriorsPtPrM");

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  (TH3D *) fin->Get(Form("priorsKs%s%s",spec[i],spec[j]));
	priorsKs[i][j]->SetName(Form("oldpriorsKs%s%s",spec[i],spec[j]));
	priorsPhi[i][j] =  (TH2D *) fin->Get(Form("priorsPhi%s%s",spec[i],spec[j]));
	priorsPhi[i][j]->SetName(Form("oldpriorsPhi%s%s",spec[i],spec[j]));
	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  (TH3D *) fin->Get(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLc[i][j][k]->SetName(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k] =  (TH3D *) fin->Get(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k]->SetName(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	}
      }
    }
  }
  
  newpriorsPt[0] = new TH1D("priorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[1] = new TH1D("priorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[2] = new TH1D("priorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[3] = new TH1D("priorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[4] = new TH1D("priorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[5] = new TH1D("priorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi priors distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      newpriorsKs[i][j] =  new TH3D(Form("priorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      newpriorsPhi[i][j] =  new TH2D(Form("priorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);
      for(Int_t k=0; k< 3;k++){
	newpriorsLc[i][j][k] =  new TH3D(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	newpriorsLcbar[i][j][k] =  new TH3D(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }
    }
  }
  
  truePt[0]  = new TH1D("truePtPiP","Pion (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[1]  = new TH1D("truePtKaP","Kaon (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[2]  = new TH1D("truePtPrP","Proton (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[3]  = new TH1D("truePtPiM","Pion (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[4]  = new TH1D("truePtKaM","Kaon (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[5]  = new TH1D("truePtPrM","Proton (-) truth;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi truePid distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      truePidKs[i][j] =  new TH3D(Form("truePidKs%s%s",spec[i],spec[j]),Form("K^{0*} truePid for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      truePidPhi[i][j] =  new TH2D(Form("truePidPhi%s%s",spec[i],spec[j]),Form("#phi truePid for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);

      for(Int_t k=0; k< 3;k++){
	truePidLc[i][j][k] =  new TH3D(Form("truePidLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	truePidLcbar[i][j][k] =  new TH3D(Form("truePidLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }

    }
  }

  trueKs =  new TH3D(Form("trueKs"),Form("K^{0*} true;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
  truePhi =  new TH2D(Form("truePhi"),Form("#phi true;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),100,0.98,1.05,40,0,10);

  trueLc =  new TH3D(Form("trueLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  trueLcbar =  new TH3D(Form("trueLcbar"),Form("#overline{#Lambda}_{c}^{-} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1);

  mypidLc =  new TH3D(Form("mypidLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  mypidLcbar =  new TH3D(Form("mypidLcbar"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);

  // define particle types (particle type array)
  particle::AddParticleType("pi+",0.139,1); // 0
  particle::AddParticleType("pi-",0.139,-1); // 1
  particle::AddParticleType("K+",0.493,1); // 2 
  particle::AddParticleType("K-",0.493,-1); // 3
  particle::AddParticleType("p+",0.938,1); // 4 
  particle::AddParticleType("p-",0.938,-1); // 5
  particle::AddParticleType("K0*",0.896,0,5.05e-02); // 6
  particle::AddParticleType("K0bar*",0.896,0,5.05e-02); // 7
  particle::AddParticleType("Phi",1.02,0,0.00426); // 8
  particle::AddParticleType("Delta++",1.232,2,0.118); // 9 
  particle::AddParticleType("Delta--",1.232,-2,0.118);  // 10
  particle::AddParticleType("Lambdac+",2.28646,1,0.008); // 11
  particle::AddParticleType("Lambdacbar-",2.28646,-1,0.008); // 12
  particle::AddParticleType("Lambda1520",1.5195,-1,0.0000156); // 12

  particle d1("pi+");
  particle d2("K+");
  particle d3("p+");
  particle d4("pi-");
  particle d5("K-");
  particle d6("p-");

  particle prong1;
  particle prong2;
  particle prong3;

  particle polarKs("K0*");
  particle polarLc("Lambdac+");

  Int_t charge[] = {1,-1,1,-1,1,-1,0,0,0,2,-2,1,-1};

  particle ppos[20000];
  particle pneg[20000];

  Float_t weightsPos[20000][3];
  Float_t weightsNeg[20000][3];
  Int_t passMyPIDPos[20000][3];
  Int_t passMyPIDNeg[20000][3];

  Int_t npos=0;
  Int_t nneg=0;

  Float_t signal,signalTOF,signalTPC,pt,pz,phi,ptComb,ptComb3prong,invmass;
  Float_t ptd,pzd,phid;

  Float_t priors[3],prob[3];
  Float_t priors2[3][3],prob2[3][3];
  Float_t priors3[3][3][3],prob3[3][3][3];
      
  Int_t iev=-1,id,mother;
  Int_t cev;
  
  TFile *fout = new TFile(Form("step%i.root",step+1),"RECREATE");
  // TTree *treeKs = new TTree("treeKs","treeKs");
  // Float_t ptPair,massPair,ptD1,ptD2,weightD1[3],weightD2[3],weightFill;
  // Int_t isTrue,isTruePid;
  // treeKs->Branch("ptPair",&ptPair,"ptPair/F");
  // treeKs->Branch("massPair",&massPair,"massPair/F");
  // treeKs->Branch("ptPi",&ptD1,"ptPi/F");
  // treeKs->Branch("ptKa",&ptD2,"ptKa/F");
  // treeKs->Branch("weightPi",weightD1,"wightPi[3]/F");
  // treeKs->Branch("weightKa",weightD2,"wightKa[3]/F");
  // treeKs->Branch("weightFill",&weightFill,"wightFill/F");
  // treeKs->Branch("isTruePid",&isTruePid,"isTruePid/I");
  // treeKs->Branch("isTrue",&isTrue,"isTrue/I");
  TH1F *hcentr = new TH1F("hcentr","",100,0,100);

  FILE *flist = fopen("lista","r");
  char namefile[100];
  Float_t weight1[3],weight2[3],weight3[3];
  Float_t ptPi,ptKa,ptPr;

  TH1F *htemp;

  while(fscanf(flist,"%s",namefile)==1){
    TFile *fin = new TFile(namefile);
    printf("file = %s\n",namefile);
    TList *l = (TList *) fin->Get("TOFpid");
    htemp = (TH1F *) l->At(0);
    if(!hcentr) hcentr = new TH1F(*htemp);
    else hcentr->Add(htemp);
    TTree *t = (TTree *) l->At(1);
    Int_t n = t->GetEntries();
    
    for(Int_t i=0;i < n;i++){
      t->GetEvent(i);

      ptPi = t->GetLeaf("ptPi")->GetValue();
      ptKa = t->GetLeaf("ptPi")->GetValue();
      ptPr = t->GetLeaf("ptPi")->GetValue();
      pt = t->GetLeaf("pt")->GetValue();
      invmass = t->GetLeaf("mass")->GetValue();
      weight1[0] = t->GetLeaf("weightPi")->GetValue(0);
      weight1[1] = t->GetLeaf("weightPi")->GetValue(1);
      weight1[2] = t->GetLeaf("weightPi")->GetValue(2);
      weight2[0] = t->GetLeaf("weightKa")->GetValue(0);
      weight2[1] = t->GetLeaf("weightKa")->GetValue(1);
      weight2[2] = t->GetLeaf("weightKa")->GetValue(2);
      weight3[0] = t->GetLeaf("weightPr")->GetValue(0);
      weight3[1] = t->GetLeaf("weightPr")->GetValue(1);
      weight3[2] = t->GetLeaf("weightPr")->GetValue(2);

      Float_t pt1 = Int_t(ptPi/(ptPi+ptKa+ptPr)*nbinPtFrPi);
      Float_t pt2 = Int_t(ptKa/(ptPi+ptKa+ptPr)*nbinPtFrKa);
      Float_t polar = 0;//TMath::Abs(polarLc.GetY());//ptComb3prong/ptot;//(pt2*nbinpol + pt1)*invpollc;
      polar = ((pt1*nbinPtFrKa + pt2 + polar)*nbinY)*normbin;

      Int_t ibinx = priorsLc[0][0][0]->GetXaxis()->FindBin(invmass);
      Int_t ibiny = priorsLc[0][0][0]->GetYaxis()->FindBin(pt);
      Int_t ibinz = priorsLc[0][0][0]->GetZaxis()->FindBin(polar);
      
      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++)
	    priors3[ipr][jpr][kpr] = priorsLc[ipr][jpr][kpr]->GetBinContent(ibinx,ibiny,ibinz);
      
      GetProb3(weight1,weight2,weight3,priors3,prob3);

      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++){
	    newpriorsLc[ipr][jpr][kpr]->Fill(invmass,pt,polar,prob3[ipr][jpr][kpr]);
	  }
    }
    t->Delete();
    fin->Close();

  }



  printf("Write output\n");
  fout->cd();
  hcentr->Write();
  //if(step==0) treeKs->Write();
  for(Int_t i=0;i<6;i++){
    newpriorsPt[i]->Write();
    truePt[i]->Write();
  }
  for(Int_t i=0;i<3;i++){
    for(Int_t j=0;j<3;j++){
      priorsPhi[i][j]->Write();
      newpriorsKs[i][j]->Write();
      newpriorsPhi[i][j]->Write();
      truePidKs[i][j]->Write();
      truePidPhi[i][j]->Write();
      for(Int_t k=0;k<3;k++){
       	newpriorsLc[i][j][k]->Write();
	truePidLc[i][j][k]->Write();
	newpriorsLcbar[i][j][k]->Write();
	truePidLcbar[i][j][k]->Write();
      }
    }
  }
  trueKs->Write();
  truePhi->Write();
  trueLc->Write();
  trueLcbar->Write();
  mypidLc->Write();
  mypidLcbar->Write();
  fout->Close();
}
/* Call functions through pointers and and check against expected results.  */
void
test (void)
{

  CHECK_VOID_RESULT (v0 (), 1.0);
  CHECK_VOID_RESULT (v1 (1.0), 2.0);
  CHECK_VOID_RESULT (v5 (5.0, 6.0), 12.0);
  CHECK_VOID_RESULT (v9 (9.0, 10.0), 20.0);
  CHECK_VOID_RESULT (v2 (2.0), 3.0);
  CHECK_VOID_RESULT (v6 (6.0, 7.0), 14.0);
  CHECK_VOID_RESULT (v10 (10.0, 11.0), 22.0);

  CHECK_RESULT (f0 (), 1.0);
  CHECK_RESULT (f1 (1.0), 2.0);
  CHECK_RESULT (f5 (5.0, 6.0), 12.0);
  CHECK_RESULT (f9 (9.0, 10.0), 20.0);
  CHECK_RESULT (f2 (2.0), 3.0);
  CHECK_RESULT (f6 (6.0, 7.0), 14.0);
  CHECK_RESULT (f10 (10.0, 11.0), 22.0);

  CHECK_RESULT (d0 (), 1.0);
  CHECK_RESULT (d1 (1.0), 2.0);
  CHECK_RESULT (d5 (5.0, 6.0), 12.0);
  CHECK_RESULT (d9 (9.0, 10.0), 20.0);
  CHECK_RESULT (d2 (2.0), 3.0);
  CHECK_RESULT (d6 (6.0, 7.0), 14.0);
  CHECK_RESULT (d10 (10.0, 11.0), 22.0);

  CHECK_RESULT (cf0 (), 1.0 + 0.0i);
  CHECK_RESULT (cf1 (1.0), 2.0 + 1.0i);
  CHECK_RESULT (cf5 (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT (cf9 (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT (cf2 (2.0), 3.0 + 2.0i);
  CHECK_RESULT (cf6 (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT (cf10 (10.0, 11.0), 22.0 + 10.0i);

  CHECK_RESULT (cd0 (), 1.0 + 0.0i);
  CHECK_RESULT (cd1 (1.0), 2.0 + 1.0i);
  CHECK_RESULT (cd5 (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT (cd9 (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT (cd2 (2.0), 3.0 + 2.0i);
  CHECK_RESULT (cd6 (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT (cd10 (10.0, 11.0), 22.0 + 10.0i);

  CHECK_VOID_RESULT ((*pv0) (), 1.0);
  CHECK_VOID_RESULT ((*pv1) (1.0), 2.0);
  CHECK_VOID_RESULT ((*pv5) (5.0, 6.0), 12.0);
  CHECK_VOID_RESULT ((*pv9) (9.0, 10.0), 20.0);
  CHECK_VOID_RESULT ((*pv2) (2.0), 3.0);
  CHECK_VOID_RESULT ((*pv6) (6.0, 7.0), 14.0);
  CHECK_VOID_RESULT ((*pv10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pf0) (), 1.0);
  CHECK_RESULT ((*pf1) (1.0), 2.0);
  CHECK_RESULT ((*pf5) (5.0, 6.0), 12.0);
  CHECK_RESULT ((*pf9) (9.0, 10.0), 20.0);
  CHECK_RESULT ((*pf2) (2.0), 3.0);
  CHECK_RESULT ((*pf6) (6.0, 7.0), 14.0);
  CHECK_RESULT ((*pf10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pd0) (), 1.0);
  CHECK_RESULT ((*pd1) (1.0), 2.0);
  CHECK_RESULT ((*pd5) (5.0, 6.0), 12.0);
  CHECK_RESULT ((*pd9) (9.0, 10.0), 20.0);
  CHECK_RESULT ((*pd2) (2.0), 3.0);
  CHECK_RESULT ((*pd6) (6.0, 7.0), 14.0);
  CHECK_RESULT ((*pd10) (10.0, 11.0), 22.0);

  CHECK_RESULT ((*pcf0) (), 1.0 + 0.0i);
  CHECK_RESULT ((*pcf1) (1.0), 2.0 + 1.0i);
  CHECK_RESULT ((*pcf5) (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT ((*pcf9) (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT ((*pcf2) (2.0), 3.0 + 2.0i);
  CHECK_RESULT ((*pcf6) (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT ((*pcf10) (10.0, 11.0), 22.0 + 10.0i);

  CHECK_RESULT ((*pcd0) (), 1.0 + 0.0i);
  CHECK_RESULT ((*pcd1) (1.0), 2.0 + 1.0i);
  CHECK_RESULT ((*pcd5) (5.0, 6.0), 12.0 + 5.0i);
  CHECK_RESULT ((*pcd9) (9.0, 10.0), 20.0 + 9.0i);
  CHECK_RESULT ((*pcd2) (2.0), 3.0 + 2.0i);
  CHECK_RESULT ((*pcd6) (6.0, 7.0), 14.0 + 6.0i);
  CHECK_RESULT ((*pcd10) (10.0, 11.0), 22.0 + 10.0i);
}
Beispiel #17
0
int main(void)
{
   struct tm *newtime;
   time_t ltime; 
   time(&ltime);                 /* Get the time in seconds */
   newtime = localtime(&ltime);  /* Convert it to the structure tm */
   char * st;            // gen purpose string for bcd's
   st = new char[35];   // 32 digits + sign + decimal pt + '\0'
 ofstream dout("bcdrun.log");
   bcd numa("1234567890987654.123");  // fraction will be dropped
   bcd numb(4321.6789);               // ditto - we are using integer rules
   bcd numc(-24681357L);
   bcd numd = numa + numb;
   bcd e(0.0);
   bcd f(0L);
   bcd g(-0.0);
   bcd h(-0L);
   bcd w(1L);
   bcd x(-1.0);
   bcd y("-2.0");
   bcd z("300.");
   bcd aa("99999999999999999999999999999999");
   bcd bb("1");
   bcd cc("10000000000000000");
   bcd dd(".00000000000000001");
   bcd m1(12L);
   bcd m2(2L);
   bcd m3(123456789L);
   bcd m4(4096L);
   bcd m5(748345987654321.0);
   bcd m6(288834570200345.0);
   bcd m7("8599238847786248452455563809");
   bcd d1("8765432109876");
   bcd d2(24687L);
   bcd d3(75237L);
   bcd d4(45263L);
   bcd d5 ("92732081006447");
   bcd s1("1234567890987654");

   dout << "                 Regression Log for " << asctime(newtime) << endl;

   dout << "significant digits test: 1 = " << w.sigD() << ", 3 = " << z.sigD()
        << ", 32 = " << aa.sigD() << ", 0 = " << dd.sigD() << "\n" << endl;

   int rc = numa.bcdToString(st); // convert numa to string no decimal point
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890987654" << endl;
   rc = numa.bcdToString(st,1);   // numa to str with 1 psn to right of dec pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +123456789098765.4" << endl;
   rc = numa.bcdToString(st,6);   // numa to str with 6 psns to rt of decimal pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890.987654" << "\n" << endl;

   rc = m3.bcdToString(st); // convert m3 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123456789" << endl;
   rc = m3.bcdToString(st,1);   // m3 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +12345678.9" << endl;
   rc = m3.bcdToString(st,6);   // m3 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123.456789" << "\n" << endl;

   rc = h.bcdToString(st); // convert h to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0" << endl;
   rc = h.bcdToString(st,1);   // convert h to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << endl;
   rc = h.bcdToString(st,6);   // h to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << "\n" << endl;

   rc = m2.bcdToString(st); // convert m2 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +2" << endl;
   rc = m2.bcdToString(st,1);   // m2 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.2" << endl;
   rc = m2.bcdToString(st,6);   // m2 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.000002" << "\n" << endl;

   s1.shl(1);
   dout << "shift test 1234567890987654 shifted left 1 = " << s1 
        << "   expected                                = +00000000000000012345678909876540 cc: 0\n" << endl;
   s1.shl(2);
   dout << "shift test 1234567890987654 shifted left 2 = " << s1 
        << "   expected                                = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shl(3);
   dout << "shift test 1234567890987654 shifted left 3 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 0\n" << endl;
   s1.shl(13);
   dout << "shift test 1234567890987654 shfted left 13 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 16\n" << endl;
   s1.shr(1);
   dout << "shift test 1234567890987654 shifted rt 1 = " << s1 
        << "   expected                              = +00000000000123456789098765400000 cc: 0\n" << endl;
   s1.shr(2);
   dout << "shift test 1234567890987654 shifted rt 2 = " << s1 
        << "   expected                              = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shr(5);
   dout << "shift test 1234567890987654 shifted rt 5 = " << s1 
        << "   expected                              = +00000000000000000012345678909876 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000001234567891 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000123457 cc: 0\n" << endl;
   s1.shrRnd(5);
   dout << "shift test 12345678909876 sh rt 5 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000000001 cc: 0\n" << endl;
   s1.shl(31);
   dout << "shift test 12345678909876 sh lt 31       = " << s1
        << "   expected                              = +10000000000000000000000000000000 cc: 0\n" << endl;

   bcd s2("1234567890987654321");
   s2.shrCpld(s1,6);               // odd shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000654321 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000001234567890987 cc: 0\n" << endl;
   s2.shrCpld(s1,5);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000090987 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000012345678 cc: 0\n" << endl;
   s2.shrCpld(s1,4);               // even shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000005678 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000001234 cc: 0\n" << endl;
   s2.shrCpld(s1,3);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000000234 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000000001 cc: 0\n" << endl;

   dout << "logical test 1 < 2   = " << int(bb<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 2   = " << int(bb>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 2   = " << int(bb==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < 1   = " << int(m2<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 > 1   = " << int(m2>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = 1   = " << int(m2==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 < 12  = " << int(bb<m1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 12  = " << int(bb>m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 12  = " << int(bb==m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 < 1  = " << int(m1<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 > 1  = " << int(m1>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 12 = 1  = " << int(m1==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 < 2  = " << int(x<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -1 > 2  = " << int(x>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 = 2  = " << int(x==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < -1  = " << int(m2<x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 != 2  = " << int(x!=m2) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != -1  = " << int(m2!=x) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != 2   = " << int(m2!=m2) << "\n"
        << "expected              = 0 \n" << endl;
   dout << "logical test 2 > -1  = " << int(m2>x) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = -1  = " << int(m2==x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test d1 = d1 = " << int(d1==d1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = -0  = " << int(f==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = 0  = " << int(h==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = 0   = " << int(f==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = -0 = " << int(h==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "divide test 8765432109876/24687 = " << d1/d2
        << "expected                        = +00000000000000000000000355062669 cc: 0\n" << endl;
   dout << "divide tst 92732081006447/45263 = " << d5/d4
        << "expected                        = +00000000000000000000002048739169 cc: 0\n" << endl;
   dout << "divide test 8765432109876/75237 = " << d1/d3
        << "expected                        = +00000000000000000000000116504274 cc: 0\n" << endl;
   dout << "divide test 1/24687             = " << bb/d2
        << "expected                        = +00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "   test 10000000000000000/24687 = " << cc/d2
        << "expected                        = +00000000000000000000405071495118 cc: 0\n" << endl;
   dout << "   test 10000000000000000/3     = " << cc/3L
        << "expected                        = +00000000000000003333333333333333 cc: 0\n" << endl;
   dout << "   test 10000000000000000/6     = " << cc/6L
        << "expected                        = +00000000000000001666666666666666 cc: 0\n" << endl;
   dout << "   test 10000000000000000/7     = " << cc/7L
        << "expected                        = +00000000000000001428571428571428 cc: 0\n" << endl;
   dout << " div test 22000000000000000/7   = " << (cc*22L)/7L
        << "expected                        = +00000000000000031428571428571428 cc: 0\n" << endl;
   dout << "modulus test 24687%1000         = " << d2%1000L
        << "expected                        = +00000000000000000000000000000687 cc: 0\n" << endl;
   dout << "divide by zero test 75237/0     = " << d3/0L
        << "expected                        = +00000000000000000000000000075237 cc: 16\n" << endl;
   dout << "divide d1/d1 test               = " << d1/d1
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "re-subtract test: 12345 - 12346 = " << bcd(12345L) - 12346L
        << "expected                        = -00000000000000000000000000000001 cc: 0\n"
        << " reverse opnds:   12346 - 12345 = " << bcd(12346L) - 12345L
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "8599238847786248452455563809*45263       = " << m7 * d4
        << "                               expected:   +00008599238847786248452455563809 cc: 15\n" << endl;
   dout << "748345987654321 x 288834570200345        = " << m5 * m6
        << "                               expected:   +00216148191705288491573574940745 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 10   = " << m5 * m6 * 10.0
        << "                               expected:   +02161481917052884915735749407450 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 100  = " << m5 * m6 * 100.0
        << "                               expected:   +21614819170528849157357494074500 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 1000 = " << m5 * m6 * 1000.0
        << "                               expected:   +00216148191705288491573574940745 cc: 16\n" << endl;
   dout << "123456789 x 123456789 x 123456789        = " << m3 * m3 * m3
        << "                               expected:   +00000001881676371789154860897069 cc: 0\n" << endl;
   dout << "123456789 x 123456789 x 123456789 x 123456789 = " << m3 * m3 * m3 * m3
        << "                                    expected:   +00000001881676371789154860897069 cc: 16\n" << endl;
   dout << "                                        2 x 2 = " << m2*m2
        << "                                    expected:   +00000000000000000000000000000004 cc: 0\n" << endl;
   dout << "                                       2 x 12 = " << m2*m1
        << "                                    expected:   +00000000000000000000000000000024 cc: 0\n" << endl;
   dout << "                                2 x 123456789 = " << m2 * m3
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << "                                123456789 x 2 = " << m3 * m2
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << " 4096 x 2 = " << m4 * m2
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 4096 = " << m2 * m4
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 12 x 4096 = " << m2 * m1 * m4
        << "expected:        +00000000000000000000000000098304 cc: 0\n" << endl;
   dout << "    aa = " << aa
        << "    bb = " << bb
        << " aa-bb = " << aa-bb
        << "expected:+99999999999999999999999999999998 cc: 0\n"
        << " aa+bb = " << aa+bb 
        << "expected:+00000000000000000000000000000000 cc: 1\n" << endl;
   dout << "     e = " << e
        << "     f = " << f
        << " e + f = " << e+f
        << "expected:+00000000000000000000000000000000 cc: 0\n" 
        << " e - f = " << e-f 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     g = " << g
        << "     h = " << h
        << " g + h = " << g+h
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " g - h = " << g-h 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     w = " << w
        << "     x = " << x
        << " w + x = " << w+x
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " w - x = " << w-x 
        << "expected:+00000000000000000000000000000002 cc: 0\n" << endl;
   dout << "     y = " << y
        << "     z = " << z
        << " y + z = " << y+z
        << "expected:+00000000000000000000000000000298 cc: 0\n"
        << " y - z = " << y-z 
        << "expected:-00000000000000000000000000000302 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa+numb = " << numd
        << "expected:   +00000000000000001234567890991975 cc: 0\n"
        << "numb+numa = " << numb+numa 
        << "expected:   +00000000000000001234567890991975 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa+numc = " << numa+numc 
        << "expected:   +00000000000000001234567866306297 cc: 0\n"
        << "numc+numa = " << numc+numa
        << "expected:   +00000000000000001234567866306297 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb+numc = " << numb+numc 
        << "expected:   -00000000000000000000000024677036 cc: 0\n"
        << "numc+numb = " << numc+numb 
        << "expected:   -00000000000000000000000024677036 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa-numb = " << numa-numb 
        << "expected:   +00000000000000001234567890983333 cc: 0\n" 
        << "numb-numa = " << numb-numa 
        << "expected:   -00000000000000001234567890983333 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa-numc = " << numa-numc 
        << "expected:   +00000000000000001234567915669011 cc: 0\n"
        << "numc-numa = " << numc-numa 
        << "expected:   -00000000000000001234567915669011 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb-numc = " << numb-numc 
        << "expected:   +00000000000000000000000024685678 cc: 0\n"
        << "numc-numb = " << numc-numb
        << "expected:   -00000000000000000000000024685678 cc: 0\n" << endl;
   dout.close();
   delete st;
   return 0;
}
Beispiel #18
0
void dpps::Pattern_random::generate () {
    // We have do declare them all. We cannot do a switch of if,
    // because distributions would get out of scope.
    // The only other possibility would be to place the switch inside
    // the loop, but it would be very inefficient to call the constructor
    // everytime.
    // So we have to pay for overhead and initialize them all in te beginning.
    // It's probably a negligible amount of time and memory as compared to the
    // loop.

    // signification of parametres depends on the engine. Some engines
    // need only one parametre.
    // For all user-changeable values (p1 and p2), 1.0 would have been the
    // default if we had not specified it, so it is an acceptable value for the
    // user as well.
    const double p1 {pattern_settings. p1} ;
    const double p2 {pattern_settings. p2} ;

    std::uniform_real_distribution<double> d0 (-p1, p1) ; // min, max
    // Normal-type
    std::normal_distribution<double> d1 (0.0, p1) ;    // average = 0, sigma
    std::lognormal_distribution<double> d2 (0.0, p1) ; // average = 0, m
    std::chi_squared_distribution<double> d3 (p1) ;    // n
    std::cauchy_distribution<double> d4 (p1, p2) ;     // a, b
    std::fisher_f_distribution<double> d5 (p1, p2) ;   // m, n
    std::student_t_distribution<double> d6 (p1) ;      // n
    // Poisson-type
    std::exponential_distribution<double> d7 (p1) ;    // lambda
    std::gamma_distribution<double> d8 (p1, p2) ;      // alpha, beta
    std::weibull_distribution<double> d9 (p1, p2) ;    // a, b

    Polyline p ;
    p. closed = true ;
    double x {0.0}, y {0.0} ;
    long_unsigned_int i {0}, attempts {0} ;
    //const double s {pattern_settings. side / 2.0} ;
    if (pattern_settings. max_attempts < pattern_settings. number)
        pattern_settings. max_attempts =
            std::numeric_limits<long_unsigned_int>::max () ;
    //std::cout << "hello" << i << " " << pattern_settings. number << " " <<  attempts << " " << pattern_settings. max_attempts << std::endl ;
    while ((i < pattern_settings. number) &&
           (attempts < pattern_settings. max_attempts)) {
        bool overlap = false ;
        switch (pattern_settings. type) {
            case type_uniform_real_distribution: // 0
                x = d0 (pseudorandom_generator) ;
                y = d0 (pseudorandom_generator) ;
                //std::cout << "alea 0 : " << x << " " << y << std::endl ;
                break ;
            case type_normal_distribution: // 1
                x = d1 (pseudorandom_generator) ;
                y = d1 (pseudorandom_generator) ;
                break ;
            case type_lognormal_distribution: // 2
                x = d2 (pseudorandom_generator) ;
                y = d2 (pseudorandom_generator) ;
                break ;
            case type_chi_squared_distribution: // 3
                x = d3 (pseudorandom_generator) ;
                y = d3 (pseudorandom_generator) ;
                break ;
            case type_cauchy_distribution: // 4
                x = d4 (pseudorandom_generator) ;
                y = d4 (pseudorandom_generator) ;
                break ;
            case type_fisher_f_distribution: // 5
                x = d5 (pseudorandom_generator) ;
                y = d5 (pseudorandom_generator) ;
                break ;
            case type_student_t_distribution: // 6
                x = d6 (pseudorandom_generator) ;
                y = d6 (pseudorandom_generator) ;
                break ;
            case type_exponential_distribution: // 7
                x = d7 (pseudorandom_generator) ;
                y = d7 (pseudorandom_generator) ;
                break ;
            case type_gamma_distribution: // 8
                x = d8 (pseudorandom_generator) ;
                y = d8 (pseudorandom_generator) ;
                break ;
            case type_weibull_distribution: // 9
                x = d9 (pseudorandom_generator) ;
                y = d9 (pseudorandom_generator) ;
                break ;
            default:
                break ;
        }
        if (pattern_settings. avoid_overlap) {
            for (long_unsigned_int j = 0 ; j < polylines. size () ; j++) {
                if ((polylines[j]. vertices[0] - Vertex(x, y)).norm2_square() <
                    pattern_settings. diametre*pattern_settings. diametre) {
                    overlap = true ;
                    break ;
                 }
            }
        }

        bool within_limits =
            (((fabs (x - pattern_settings. x0) < pattern_settings. lx / 2.0) ||
             (pattern_settings. lx <= 0)) &&
            ((fabs (y - pattern_settings. y0) < pattern_settings. ly / 2.0) ||
             (pattern_settings. ly <= 0))) ;

        // Either we are inside lx, or user set it to negative to disable it.
        if  (within_limits && !overlap) {
            p. push_back (Vertex (x, y)) ;
            p. dose = pattern_settings. diametre ;
            polylines. push_back (p) ;
            p. vertices. clear () ; // does not change that p. closed == true ;
            i++ ;
        }
        attempts++ ;
    }
}
Beispiel #19
0
FCOLLADA_EXPORT void TrickLinker2()
{
	{
		// Exercise ALL the functions of the string builders in order to force their templatizations.
		fm::string s = "1";
		fstring fs = FC("2");
		FUSStringBuilder b1, b2(s), b3(s.c_str()), b4('c', 3), b5(333);
		FUStringBuilder d1, d2(fs), d3(fs.c_str()), d4('c', 4), d5(333);

		b1.clear(); d1.clear(); b1.length(); d1.length();
		b1.append(s); d1.append(fs);
		b1.append('c'); d1.append((fchar) 'c');
		b1.append(b2); d1.append(d2);
		b1.append((int)1); d1.append((int)1);
		b1.append(s.c_str(), 1); d1.append(fs.c_str(), 1);
		b3.append((uint32) 8); d3.append((uint32) 8);
		b4.append((uint64) 8); d4.append((uint64) 8);
		b4.append((int32) -2); d4.append((int32) -2);
		b5.append(1.0f); d5.append(-1.0f);
		b5.append(1.0); d5.append(-1.0);
		b5.append(FMVector2::Zero); d5.append(FMVector2::Zero);
		b5.append(FMVector3::Zero); d5.append(FMVector3::Zero);
		b5.append(FMVector4::Zero); d5.append(FMVector4::Zero);
		b5.back(); d5.back();
		b1.appendLine("Test"); d1.appendLine(FC("Test"));
		b1.appendHex((uint8) 4); d1.appendHex((uint8) 4);
		b1.remove(0); d1.remove(0);
		b2.remove(0, 2); d2.remove(0, 2);
		b3.ToCharPtr(); d3.ToCharPtr();
		b4.index('c'); d4.index('c');
		b4.rindex('c'); d4.rindex('c');
	}

	{
		// Similarly for fm::stringT.
		fm::string a, b(a), c("a"), d("ab", 1), e(3, 'C');
		fstring r, s(r), t(FC("S")), u(FC("SSS"), 1), v(3, 'S');

		size_t x = a.length(), y = r.length();
		a = c.substr(x, y); r = u.substr(x, y);
		a.append("TEST"); r.append(FC("TEST"));
		a.append(d); r.append(v);
		e = a.c_str(); v = u.c_str();
		x = a.find('C', y); y = v.find('S', x);
		x = a.find(d, y); y = u.find(r, x);
		x = a.find("X", y); y = v.find(FC("A"), x);
		x = a.rfind('C', y); y = v.rfind('S', x);
		x = a.rfind(d, y); y = u.rfind(r, x);
		x = a.rfind("X", y); y = v.rfind(FC("A"), x);
		x = a.find_first_of("XSA", y); y = r.find_first_of(FC("DNA"), x);
		x = a.find_last_of("XSA", y); y = r.find_last_of(FC("DNA"), x);
		a.insert(x, "XX"); r.insert(y, FC("XX"));
		a.insert(y, c); r.insert(x, v);
		a.erase(0, fm::string::npos); t.erase(1, fstring::npos);
		a.append('c'); v.append('w');
	}

	extern void TrickLinkerFUUniqueStringMap();
	TrickLinkerFUUniqueStringMap();
	extern void TrickLinkerFUStringConversion();
	TrickLinkerFUStringConversion();
}
Beispiel #20
0
int main()
{
    Samoyed::Scheduler scheduler(8);

    AlarmDriver d1(scheduler, 1, 1, 1),
                d2(scheduler, 2, 2, 2),
                d3(scheduler, 3, 3, 3),
                d4(scheduler, 4, 4, 4),
                d5(scheduler, 5, 5, 5);
    boost::system_time t = boost::get_system_time();
    printf("Alarm 1 runs 10 times\n");
    d1.run(10, false);
    printf("Scheduler starts 3 threads\n");
    scheduler.size_controller().resize(3);
    printf("Alarm 2 runs 1 more time\n");
    d2.run(1, true);
    t += boost::posix_time::seconds(5);
    boost::thread::sleep(t);
    printf("Alarm 1 runs 1 time\n");
    d1.run(1, false);
    printf("Alarm 2 runs 2 more times\n");
    d2.run(2, true);
    printf("Alarm 3 runs 1 more time\n");
    d3.run(1, true);
    printf("Alarm 4 runs 7 more times\n");
    d4.run(7, true);
    printf("Alarm 5 runs 5 more times\n");
    d5.run(5, true);
    t += boost::posix_time::seconds(7);
    boost::thread::sleep(t);
    printf("Scheduler resizes to 2 threads\n");
    scheduler.size_controller().resize(2);
    printf("Alarm 1 runs 1 time\n");
    d1.run(1, false);
    printf("Alarm 2 runs 7 more times\n");
    d2.run(7, true);
    printf("Alarm 3 runs 11 more times\n");
    d3.run(11, true);
    printf("Alarm 4 runs 5 more times\n");
    d4.run(5, true);
    printf("Alarm 5 runs 7 times\n");
    d5.run(7, false);

    scheduler.wait();

    GMainContext *ctx = g_main_context_default();
    while (g_main_context_pending(ctx))
        g_main_context_iteration(ctx, TRUE);

    boost::shared_ptr<Alarm> a1(new Alarm(scheduler, 1, 1, 1, 1)),
                             a2(new Alarm(scheduler, 2, 2, 2, 2)),
                             a3(new Alarm(scheduler, 3, 3, 3, 3)),
                             a4(new Alarm(scheduler, 4, 4, 4, 4)),
                             a5(new Alarm(scheduler, 5, 5, 5, 5));
    a2->addDependency(a1);
    a3->addDependency(a1);
    a4->addDependency(a2);
    a4->addDependency(a3);
    a5->addDependency(a1);
    a5->addDependency(a2);
    a5->addDependency(a3);

    printf("Submit all\n");
    a5->submit(a5);
    a4->submit(a4);
    a3->submit(a3);
    a2->submit(a2);
    a1->submit(a1);

    a1.reset();
    a2.reset();
    a3.reset();
    a4.reset();

    t = boost::get_system_time() + boost::posix_time::seconds(5);
    boost::thread::sleep(t);
    printf("Cancel alarm 5\n");
    a5->cancel(a5);
    a5.reset();

    scheduler.wait();

    while (g_main_context_pending(ctx))
        g_main_context_iteration(ctx, TRUE);
    return 0;
}
Beispiel #21
0
int main(){
	
	Scalar a("a",STRING,"Hello");
	Scalar b("b",STRING,"World");
	std::cout << " a                      : " << a << std::endl;
	std::cout << " b                      : " << b << std::endl; 
	Scalar c("c",STRING,"Hello");
	std::cout << " c                      : " << c << std::endl;
	std::cout << " a == b                 : " << (a == b) << std::endl;
	std::cout << " a == c                 : " << (a == c) << std::endl;
	std::cout << " a  < b                 : " << (a < b) << std::endl;
	std::cout << " c  < a                 : " << (c < a) << std::endl;
	std::cout << " b  < a                 : " << (b < a) << std::endl; 
	Scalar ga("ga",BOOLEAN,"M");
	Scalar gb("gb",BOOLEAN,"F");
	Scalar gc("gc",BOOLEAN,"F");
	Scalar d("d",STRING,"M");
	std::cout << " ga                     : " << ga << std::endl;
	std::cout << " gb                     : " << gb << std::endl;
	std::cout << " gc                     : " << gc << std::endl;
	std::cout << " d                      : " << d << std::endl;
	std::cout << " (ga == gb)             : " << (ga == gb) << std::endl;
	std::cout << " (gb == gc)             : " << (gb == gc) << std::endl;
	std::cout << " (ga == d)              : " << (ga == d) << std::endl;
	std::cout << " (gb < gc)              : " << (gb < gc) << std::endl;
	std::cout << " (ga < gc)              : " << (ga < gc) << std::endl;
	std::cout << " (gc < ga)              : " << (gc < ga) << std::endl;
	std::cout << " (ga < a)               : " << (ga < a) << std::endl;
	std::cout << " (b < gb)               : " << (b < gb) << std::endl;
	std::cout << "Testing Assignment and Copy operators" << std::endl;
	Scalar copy1(ga);
	std::cout << " copy1 of ga            : " << copy1 << std::endl;  
	std::cout << " name and type          : " << copy1.getName() << " = " << copy1.getValueType() << std::endl;
	Scalar e("e",STRING,"Namaste");
	std::cout << " e                      : " << e << std::endl;
	e=ga;
	std::cout << " e=ga                   : " << e << std::endl;
	std::cout << " name and type          : " << e.getName() << " = " << e.getValueType() << std::endl;
	e=a;
	std::cout << " e=a                    : " << e << std::endl;
	std::cout << " name and type          : " << e.getName() << " = " << e.getValueType() << std::endl;
	ga=a;
	std::cout << " ga=a                   : " << ga << std::endl;
	std::cout << " name and type          : " << ga.getName() << " = " << ga.getValueType() << std::endl;
	std::cout << "Testing Scalar variables of type ANY" << std::endl;
	Scalar anyVar("anyVar");
	std::cout << " name and type          : " << anyVar.getName() << " = " << anyVar.getValueType() << std::endl;
	std::cout << " anyVar                 : " << anyVar << std::endl;
	std::cout << " anyVar < ga            : " << (anyVar < ga) << std::endl;
	std::cout << " a < anyVar             : " << (a < anyVar) << std::endl;
	std::cout << " a == anyVar            : " << (a == anyVar) << std::endl;
	anyVar.set(STRING,"Wow");
	std::cout << " anyVar=Wow             : " << anyVar << std::endl;
	Scalar anyVar1("anyVar1");
	std::cout << " anyVar1                : " << anyVar1 << std::endl;
	std::cout << " name and type          : " << anyVar1.getName() << " = " << anyVar1.getValueType() << std::endl;
	anyVar1 = anyVar;
	std::cout << " anyVar1=anyVar         : " << anyVar1 << std::endl;
	std::cout << " name and type          : " << anyVar1.getName() << " = " << anyVar1.getValueType() << std::endl;
	Scalar anyVar2("anyVar2");
	std::cout << " anyVar2                : " << anyVar2 << std::endl;
	std::cout << " name and type          : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	anyVar = anyVar2;
	std::cout << " anyVar=anyVar2         : " << anyVar << std::endl;
	std::cout << " anyVar name and type   : " << anyVar.getName() << " = " << anyVar.getValueType() << std::endl;
	std::cout << " anyVar2 name and type  : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	Scalar anyType("anyType",ANY,"Testing Any");
	std::cout << " anyType                : " << anyType << std::endl;
	std::cout << " name and type          : " << anyType.getName() << " = " << anyType.getValueType() << std::endl;
	std::cout << " anyVar2 < anyType      : " << (anyVar2 < anyType) << std::endl;
	std::cout << " anyVar2 == anyType     : " << (anyVar2 == anyType) << std::endl;
	Scalar g1("g1",GENOTYPE,"120/120");
	Scalar g2("g2",GENOTYPE,"120/120");
	Scalar g3("g3",GENOTYPE,"112/118");
	Scalar g4("g4",GENOTYPE,"C/T");
	Scalar g5("g5",GENOTYPE,"A/A");
	std::cout << " g1                     : " << g1 << std::endl;
	std::cout << " name and type          : " << g1.getName() << " = " << g1.getValueType() << std::endl;
	anyVar2 = g1;
	std::cout << " anyVar2=g1             : " << anyVar2 << std::endl;
	std::cout << " name and type          : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	std::cout << " g2                     : " << g2 << std::endl;
	std::cout << " g3                     : " << g3 << std::endl;
	std::cout << " g4                     : " << g4 << std::endl;
	std::cout << " g5                     : " << g5 << std::endl;
	std::cout << " name and type          : " << g5.getName() << " = " << g5.getValueType() << std::endl;
	std::cout << " g1 < g2                : " << (g1 < g2) << std::endl;
	std::cout << " g2 == g1               : " << (g2 == g1) << std::endl;
	std::cout << " g5 < g4                : " << (g5 < g4) << std::endl;
	std::cout << " g2 < g4                : " << (g2 < g4) << std::endl;
	std::cout << " g2 < e                 : " << (g2 < e) << std::endl;
	std::cout << " ga == g2               : " << (ga == g2) << std::endl;
	Scalar f("f",STRING,"123/125");
	Scalar g6Any("g6Any");
	std::cout << " g6Any                  : " << g6Any << std::endl;
	std::cout << " name and type          : " << g6Any.getName() << " = " << g6Any.getValueType() << std::endl;
	g6Any = f;
	std::cout << " g6Any=f                : " << g6Any << std::endl;
	std::cout << " name and type          : " << g6Any.getName() << " = " << g6Any.getValueType() << std::endl;
	g3 = g6Any;
	std::cout << " g3=g6Any               : " << g3 << std::endl;
	std::cout << " name and type          : " << g3.getName() << " = " << g3.getValueType() << std::endl;
	Scalar g7Inv("g7Inv");
	g7Inv.set(GENOTYPE,"0/0");
	std::cout << " g7Inv                  : " << g7Inv << std::endl;
	std::cout << " name and type          : " << g7Inv.getName() << " = " << g7Inv.getValueType() << std::endl;
	Scalar d1("d1",DATE,"1987-08-23");
	Scalar d2("d2",DATE,"1987-08");
	Scalar d3("d3",DATE,"[1987-1990]");
	Scalar d4("d4",DATE,"~2000-02-13");
	Scalar d5("d5",DATE,"1948");
	Scalar d6Any("d6Any");
	std::cout << " d1                     : " << d1 << std::endl;
	std::cout << " name and type          : " << d1.getName() << " = " << d1.getValueType() << std::endl;
	std::cout << " d6Any                  : " << d6Any << std::endl;
	std::cout << " name and type          : " << d6Any.getName() << " = " << d6Any.getValueType() << std::endl;
	d6Any = d1;
	std::cout << " d6Any=d1               : " << d6Any << std::endl;
	std::cout << " name and type          : " << d6Any.getName() << " = " << d6Any.getValueType() << std::endl;
	std::cout << " d2                     : " << d2 << std::endl;
	std::cout << " d3                     : " << d3 << std::endl;
	std::cout << " d4                     : " << d4 << std::endl;
	std::cout << " d5                     : " << d5 << std::endl;
	Scalar d7Inv("d7Inv");
	d7Inv.set(DATE,"2003-[03-04-12");
	std::cout << " d7Inv                  : " << d7Inv << std::endl;
	std::cout << " name and type          : " << d7Inv.getName() << " = " << d7Inv.getValueType() << std::endl;
	std::cout << " d1 < d2                : " << (d1 < d2) << std::endl;
	std::cout << " d2 == d1               : " << (d2 == d1) << std::endl;
	std::cout << " d2 == d3               : " << (d2 == d3) << std::endl;
	std::cout << " d3 < d2                : " << (d3 < d2) << std::endl;
	std::cout << " d5 < d4                : " << (d5 < d4) << std::endl;
	std::cout << " d2 < d4                : " << (d2 < d4) << std::endl;
	std::cout << " d2 < e                 : " << (d2 < e) << std::endl;
	std::cout << " ga == d2               : " << (ga == d2) << std::endl;
	Scalar d8Copy(d4);
	std::cout << " Copy of d4             : " << d8Copy << std::endl;
	std::cout << " name and type          : " << d8Copy.getName() << " = " << d8Copy.getValueType() << std::endl;
	std::cout << " d4 == d8Copy           : " << (d4 == d8Copy) << std::endl;
	
	Scalar n1("n1",NUMBER,"19-23");
	Scalar n2("n2",NUMBER,"18-38");
	Scalar n3("n3",NUMBER,"17");
	Scalar n4("n4",NUMBER,"~20");
	Scalar n5("n5",NUMBER,"48");
	Scalar n6Any("n6Any");
	std::cout << " n1                     : " << n1 << std::endl;
	std::cout << " name and type          : " << n1.getName() << " = " << n1.getValueType() << std::endl;
	std::cout << " n6Any                  : " << n6Any << std::endl;
	std::cout << " name and type          : " << n6Any.getName() << " = " << n6Any.getValueType() << std::endl;
	n6Any = n1;
	std::cout << " n6Any=n1               : " << n6Any << std::endl;
	std::cout << " name and type          : " << n6Any.getName() << " = " << n6Any.getValueType() << std::endl;
	std::cout << " n2                     : " << n2 << std::endl;
	std::cout << " n3                     : " << n3 << std::endl;
	std::cout << " n4                     : " << n4 << std::endl;
	std::cout << " n5                     : " << n5 << std::endl;
	Scalar n7Inv("n7Inv");
	n7Inv.set(NUMBER,"2003-[");
	std::cout << " n7Inv                  : " << n7Inv << std::endl;
	std::cout << " name and type          : " << n7Inv.getName() << " = " << n7Inv.getValueType() << std::endl;
	std::cout << " n1 < n2                : " << (n1 < n2) << std::endl;
	std::cout << " n2 == n1               : " << (n2 == n1) << std::endl;
	std::cout << " n2 == n3               : " << (n2 == n3) << std::endl;
	std::cout << " n3 < n2                : " << (n3 < n2) << std::endl;
	std::cout << " n5 < n4                : " << (n5 < n4) << std::endl;
	std::cout << " n2 < n4                : " << (n2 < n4) << std::endl;
	std::cout << " n2 < e                 : " << (n2 < e) << std::endl;
	std::cout << " ga == n2               : " << (ga == n2) << std::endl;
	Scalar n8Copy(n4);
	std::cout << " Copy of n4             : " << n8Copy << std::endl;
	std::cout << " name and type          : " << n8Copy.getName() << " = " << n8Copy.getValueType() << std::endl;
	std::cout << " n4 == n8Copy           : " << (n4 == n8Copy) << std::endl;
	Number::addNumberMissingValue("99");
	std::cout << "Added 99 as Number missing value" << std::endl;
	Scalar n8("n8",NUMBER,"99");
	std::cout << " n8=99                  : " << n8 << std::endl;
	return 0;
	
} 
Beispiel #22
0
void drive_operation()
{

    // Uint64 tests

    CQLValue a1(Uint64(10));
    CQLValue a2(Uint64(15));
    CQLValue a3(Uint64(25));
    CQLValue a4(Uint64(30));
    CQLValue a5(Uint64(150));

    PEGASUS_TEST_ASSERT(a1 != a2);
    PEGASUS_TEST_ASSERT(a5 == a5);
    PEGASUS_TEST_ASSERT(a1 < a2);
    PEGASUS_TEST_ASSERT(a2 >= a1);
    PEGASUS_TEST_ASSERT(a1 <= a2);
    PEGASUS_TEST_ASSERT(a2 > a1);

    // Sint64 tests

    CQLValue b1(Sint64(10));
    CQLValue b2(Sint64(15));
    CQLValue b3(Sint64(25));
    CQLValue b4(Sint64(30));
    CQLValue b5(Sint64(150));

    PEGASUS_TEST_ASSERT(b1 != b2);
    PEGASUS_TEST_ASSERT(b5 == b5);
    PEGASUS_TEST_ASSERT(b1 < b2);
    PEGASUS_TEST_ASSERT(b2 >= b1);
    PEGASUS_TEST_ASSERT(b1 <= b2);
    PEGASUS_TEST_ASSERT(b2 > b1);

    // Real64 tests

    CQLValue c1(Real64(10.00));
    CQLValue c2(Real64(15.00));
    CQLValue c3(Real64(25.00));
    CQLValue c4(Real64(30.00));
    CQLValue c5(Real64(150.00));

    PEGASUS_TEST_ASSERT(c1 != c2);
    PEGASUS_TEST_ASSERT(c5 == c5);
    PEGASUS_TEST_ASSERT(c1 < c2);
    PEGASUS_TEST_ASSERT(c2 >= c1);
    PEGASUS_TEST_ASSERT(c1 <= c2);
    PEGASUS_TEST_ASSERT(c2 > c1);

    // Misc
    PEGASUS_TEST_ASSERT(a1 == b1);
    PEGASUS_TEST_ASSERT(a1 == c1);
    PEGASUS_TEST_ASSERT(b1 == a1);
    PEGASUS_TEST_ASSERT(b1 == c1);
    PEGASUS_TEST_ASSERT(c1 == a1);
    PEGASUS_TEST_ASSERT(c1 == b1);

    PEGASUS_TEST_ASSERT(a2 != b1);
    PEGASUS_TEST_ASSERT(a2 != c1);
    PEGASUS_TEST_ASSERT(b2 != a1);
    PEGASUS_TEST_ASSERT(b2 != c1);
    PEGASUS_TEST_ASSERT(c2 != a1);
    PEGASUS_TEST_ASSERT(c2 != b1);

    PEGASUS_TEST_ASSERT(a2 >= b1);
    PEGASUS_TEST_ASSERT(a2 >= c1);
    PEGASUS_TEST_ASSERT(b2 >= a1);
    PEGASUS_TEST_ASSERT(b2 >= c1);
    PEGASUS_TEST_ASSERT(c2 >= a1);
    PEGASUS_TEST_ASSERT(c2 >= b1);

    PEGASUS_TEST_ASSERT(a2 <= b3);
    PEGASUS_TEST_ASSERT(a2 <= c3);
    PEGASUS_TEST_ASSERT(b2 <= a3);
    PEGASUS_TEST_ASSERT(b2 <= c3);
    PEGASUS_TEST_ASSERT(c2 <= a3);
    PEGASUS_TEST_ASSERT(c2 <= b3);

    PEGASUS_TEST_ASSERT(a2 > b1);
    PEGASUS_TEST_ASSERT(a2 > c1);
    PEGASUS_TEST_ASSERT(b2 > a1);
    PEGASUS_TEST_ASSERT(b2 > c1);
    PEGASUS_TEST_ASSERT(c2 > a1);
    PEGASUS_TEST_ASSERT(c2 > b1);

    PEGASUS_TEST_ASSERT(a2 < b3);
    PEGASUS_TEST_ASSERT(a2 < c3);
    PEGASUS_TEST_ASSERT(b2 < a3);
    PEGASUS_TEST_ASSERT(b2 < c3);
    PEGASUS_TEST_ASSERT(c2 < a3);
    PEGASUS_TEST_ASSERT(c2 < b3);

    //Overflow testing
    CQLValue real1(Real64(0.00000001));
    CQLValue sint1(Sint64(-1));
    CQLValue uint1(Sint64(1));
    CQLValue uint2(Uint64(0));

    PEGASUS_TEST_ASSERT(uint1 > sint1);
    PEGASUS_TEST_ASSERT(real1 > sint1);
    PEGASUS_TEST_ASSERT(uint2 > sint1);
    PEGASUS_TEST_ASSERT(real1 > uint2);

    CQLValue real2(Real64(25.00000000000001));
    CQLValue real3(Real64(24.99999999999999));
    CQLValue sint2(Sint64(25));
    CQLValue uint3(Uint64(25));

    PEGASUS_TEST_ASSERT(real2 > real3);
    PEGASUS_TEST_ASSERT(real2 > sint2);
    PEGASUS_TEST_ASSERT(real2 > uint3);
    PEGASUS_TEST_ASSERT(real3 < sint2);
    PEGASUS_TEST_ASSERT(real3 < uint3);

    // String tests

    CQLValue d1(String("HELLO"));
    CQLValue d2(String("HEL"));
    CQLValue d3(String("LO"));
    CQLValue d4(String("AHELLO"));
    CQLValue d5(String("ZHELLO"));

    PEGASUS_TEST_ASSERT(d1 == d2 + d3);
    PEGASUS_TEST_ASSERT(d1 != d2 + d4);

    PEGASUS_TEST_ASSERT(d1 <= d5);
    PEGASUS_TEST_ASSERT(d1 <  d5);

    PEGASUS_TEST_ASSERT(d1 >= d4);
    PEGASUS_TEST_ASSERT(d1 >  d4);

    String str1("0x10");
    String str2("10");
    String str3("10B");
    String str4("10.10");


    CQLValue e1( str1, CQLValue::Hex);
    CQLValue e2( str2, CQLValue::Decimal);
    CQLValue e3( str3, CQLValue::Binary);
    CQLValue e4( str4, CQLValue::Real);

    CQLValue e5(Uint64(16));
    CQLValue e6(Uint64(10));
    CQLValue e7(Uint64(2));
    CQLValue e8(Real64(10.10));

    PEGASUS_TEST_ASSERT(e1 == e5);
    PEGASUS_TEST_ASSERT(e2 == e6);
    PEGASUS_TEST_ASSERT(e3 == e7);
    PEGASUS_TEST_ASSERT(e4 == e8);

    Array<Uint64> array1;

    array1.append(1);
    array1.append(2);
    array1.append(3);
    array1.append(4);
    array1.append(5);
    array1.append(6);
    array1.append(7);
    array1.append(8);
    array1.append(9);
    array1.append(10);

    Array<Sint64> array2;

    array2.append(1);
    array2.append(2);
    array2.append(3);
    array2.append(4);
    array2.append(5);
    array2.append(6);
    array2.append(7);
    array2.append(8);
    array2.append(9);
    array2.append(10);
    array2.append(3);

    Array<Real64> array3;

    array3.append(1.00);
    array3.append(2.00);
    array3.append(3.00);
    array3.append(9.00);
    array3.append(10.00);
    array3.append(3.00);
    array3.append(4.00);
    array3.append(5.00);
    array3.append(6.00);
    array3.append(7.00);
    array3.append(8.00);

    Array<Uint64> array4;

    array4.append(1);
    array4.append(23);
    array4.append(3);
    array4.append(4);
    array4.append(5);
    array4.append(6);
    array4.append(7);
    array4.append(88);
    array4.append(9);
    array4.append(10);

    Array<Sint64> array5;

    array5.append(-1);
    array5.append(2);
    array5.append(3);
    array5.append(4);
    array5.append(5);
    array5.append(-6);
    array5.append(7);
    array5.append(8);
    array5.append(9);
    array5.append(10);
    array5.append(-3);

    Array<Real64> array6;

    array6.append(1.23);
    array6.append(2.00);
    array6.append(3.00);
    array6.append(9.00);
    array6.append(10.00);
    array6.append(3.00);
    array6.append(4.14);
    array6.append(5.00);
    array6.append(6.00);
    array6.append(7.00);
    array6.append(8.00);

    CIMValue cv1(array1);
    CIMValue cv2(array2);
    CIMValue cv3(array3);
    CIMValue cv4(array4);
    CIMValue cv5(array5);
    CIMValue cv6(array6);

    CQLValue vr1(cv1);
    CQLValue vr2(cv1);
    CQLValue vr3(cv2);
    CQLValue vr4(cv3);
    CQLValue vr5(cv4);
    CQLValue vr6(cv5);
    CQLValue vr7(cv6);

    PEGASUS_TEST_ASSERT(vr1 == vr2);
    PEGASUS_TEST_ASSERT(vr1 == vr3);
    PEGASUS_TEST_ASSERT(vr1 == vr4);
    PEGASUS_TEST_ASSERT(vr4 == vr3);

    PEGASUS_TEST_ASSERT(vr1 != vr5);
    PEGASUS_TEST_ASSERT(vr3 != vr6);
    PEGASUS_TEST_ASSERT(vr4 != vr7);

    const CIMName _cimName(String("CIM_OperatingSystem"));

    CIMInstance _i1(_cimName);
    CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
    CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i1.addProperty(_p1);
    _i1.addProperty(_p2);
    _i1.addProperty(_p3);
    _i1.addProperty(_p4);

    CIMInstance _i2(_cimName);
    CIMProperty _p5(CIMName("Description"),
                    CIMValue(String("Dave Rules Everything")));
    CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p8(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i2.addProperty(_p5);
    _i2.addProperty(_p6);
    _i2.addProperty(_p7);
    _i2.addProperty(_p8);

    CQLValue cql1(_i1);
    CQLValue cql2(_i1);
    CQLValue cql3(_i2);
    CQLValue cql4(_i2);

    //PEGASUS_TEST_ASSERT(cql1 == cql1);

    return;
}
Beispiel #23
0
main(int argc, char* argv) 
{
	config();
	bool do_socks = false;

	if( argc > 1 ) {
		do_socks = true;
	}

	dprintf( dflag, "\nExternal interface (local daemon)\n\n" );
	testAPI( NULL, do_socks );

	dprintf( dflag, "\nExternal interface (bad hostname)\n\n" );
	testAPI( "bazzle", do_socks );

	dprintf( dflag, "\nLocal daemons\n\n" );
	makeAndDisplayCM( NULL, NULL );
	makeAndDisplayRegular( NULL, NULL );

	dprintf( dflag, "\nRemote daemons we should find\n\n" );
	makeAndDisplayCM( "condor", "condor" );
	makeAndDisplayRegular( "puck.cs.wisc.edu", "condor" );

	dprintf( dflag, "\nWe should find the startd, but not the others\n\n" );
	makeAndDisplayRegular( "*****@*****.**", NULL );

	dprintf( dflag, "\nUsing a bogus sinful string\n\n" );
	Daemon d( DT_NEGOTIATOR, "<128.105.232.240:23232>" );
	if( d.locate() ) {
		dprintf( dflag, "Found %s\n", d.idStr() );
		d.display( dflag );
	} else {
		dprintf( dflag, "%s\n", d.error() );
	}

	dprintf( dflag, "\nMake a local STARTD w/ explicit name\n\n" );
	Daemon d2( DT_STARTD, get_local_fqdn().Value() );
	if( d2.locate() ) {
		d2.display( dflag );
	} else {
		dprintf( dflag, "%s\n", d2.error() );
	}

	dprintf( dflag, "\nMake a local COLLECTOR w/ explicit name\n\n" );
	Daemon d3( DT_COLLECTOR, "turkey.cs.wisc.edu" );
	if( d3.locate() ) {
		d3.display( dflag );
	} else {
		dprintf( dflag, "%s\n", d3.error() );
	}

	dprintf( dflag, "\nUse idStr for a remote STARTD\n\n" );
	Daemon d4( DT_STARTD, "puck.cs.wisc.edu" );
	if( d4.locate() ) {
		dprintf( dflag, "Found %s\n", d4.idStr() );
	} else {
		dprintf( dflag, "%s\n", d4.error() );
	}

	dprintf( dflag, "\nTest socks on a valid Daemon that isn't up\n\n" );
	Daemon d5( DT_SCHEDD, "cabernet.cs.wisc.edu" );
	testSocks( &d5 );

	dprintf( dflag, "\nCM where you specify pool and not name\n\n" );	
	Daemon d6( DT_COLLECTOR, NULL, "condor" );
	if( d6.locate() ) {
		d6.display( dflag );
	} else {
		dprintf( dflag, "%s\n", d6.error() );
	}
	
	dprintf( dflag, "\nUsing sinful string for the collector\n\n" );
	Daemon d7( DT_COLLECTOR, "<128.105.143.16:9618>" );
	if( d7.locate() ) {
		dprintf( dflag, "Found %s\n", d7.idStr() );
		d7.display( dflag );
	} else {
		dprintf( dflag, "%s\n", d7.error() );
	}

	dprintf( dflag, "\nRemote daemons we should NOT find\n\n" );
	makeAndDisplayRegular( "bazzle.cs.wisc.edu", "condor" );
	makeAndDisplayCM( "bazzle", "bazzle" );
}