Exemplo n.º 1
0
Arquivo: struct.c Projeto: 4ker/8cc
void testmain() {
    print("struct");
    t1();
    t2();
    t3();
    t4();
    t5();
    t6();
    t7();
    t8();
    t9();
    t10();
    t11();
    t12();
    t13();
    t14();
    unnamed();
    assign();
    arrow();
    incomplete();
    bitfield_basic();
    bitfield_mix();
    bitfield_union();
    bitfield_unnamed();
    bitfield_initializer();
    test_offsetof();
    flexible_member();
    empty_struct();
}
Exemplo n.º 2
0
void testMemory ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);

  BTree<int> *tmp = new BTree<int> (t7);

  assert (tmp->member (90));
  assert (tmp->member (7));
  assert (*tmp == t7);

  delete tmp;
  assert (t7.member (90));
  assert (t7.member (7));

  t90 = t7;
  assert (t90 == t7);
  t7 = t7;
  assert (t90 == t7);
  assert (t7 == t7);

}
Exemplo n.º 3
0
void testSerialize ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);


  std::ofstream f ("tree.txt");

  f << t7;

  f.close ();

  BTree<int> newTree;
  std::ifstream fin ("tree.txt");

  newTree.read (fin);

  //assert (t7==newTree);

  std::cout << std::endl << newTree;
}
Exemplo n.º 4
0
void testPrintWithStack ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);


  t7.printWithStack(std::cout);

  std::stringstream str;
  t7.printWithStack(str);

  int x, y, z;
  str >> x >> y >> z;
  assert (x == 30);
  assert (y == 90);
  assert (z == 12);

  //или
  assert (str.str() == "30 90 12 7 50 5 ");

}
Exemplo n.º 5
0
void tst_QSize::scale()
{
    QSize t1( 10, 12 );
    t1.scale( 60, 60, Qt::IgnoreAspectRatio );
    QCOMPARE( t1, QSize(60, 60) );

    QSize t2( 10, 12 );
    t2.scale( 60, 60, Qt::KeepAspectRatio );
    QCOMPARE( t2, QSize(50, 60) );

    QSize t3( 10, 12 );
    t3.scale( 60, 60, Qt::KeepAspectRatioByExpanding );
    QCOMPARE( t3, QSize(60, 72) );

    QSize t4( 12, 10 );
    t4.scale( 60, 60, Qt::KeepAspectRatio );
    QCOMPARE( t4, QSize(60, 50) );

    QSize t5( 12, 10 );
    t5.scale( 60, 60, Qt::KeepAspectRatioByExpanding );
    QCOMPARE( t5, QSize(72, 60) );

    // test potential int overflow
    QSize t6(88473, 88473);
    t6.scale(141817, 141817, Qt::KeepAspectRatio);
    QCOMPARE(t6, QSize(141817, 141817));

    QSize t7(800, 600);
    t7.scale(400, INT_MAX, Qt::KeepAspectRatio);
    QCOMPARE(t7, QSize(400, 300));

    QSize t8(800, 600);
    t8.scale(INT_MAX, 150, Qt::KeepAspectRatio);
    QCOMPARE(t8, QSize(200, 150));

    QSize t9(600, 800);
    t9.scale(300, INT_MAX, Qt::KeepAspectRatio);
    QCOMPARE(t9, QSize(300, 400));

    QSize t10(600, 800);
    t10.scale(INT_MAX, 200, Qt::KeepAspectRatio);
    QCOMPARE(t10, QSize(150, 200));

    QSize t11(0, 0);
    t11.scale(240, 200, Qt::IgnoreAspectRatio);
    QCOMPARE(t11, QSize(240, 200));

    QSize t12(0, 0);
    t12.scale(240, 200, Qt::KeepAspectRatio);
    QCOMPARE(t12, QSize(240, 200));

    QSize t13(0, 0);
    t13.scale(240, 200, Qt::KeepAspectRatioByExpanding);
    QCOMPARE(t13, QSize(240, 200));
}
Exemplo n.º 6
0
void testBFS ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);

  t7.levelsPrint(std::cout);
}
Exemplo n.º 7
0
void testBuild ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);


  t7.insertElement ("RR",100);
  std::cout << t7;

}
Exemplo n.º 8
0
void testIterator ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);

  LRoRTreeIterator<int> it = t7.begin ();

  while (it != t7.end())
  {
    std::cout << *it << " ";
    it++;
  }
}
Exemplo n.º 9
0
int main(){
	t1();
	t2();
	t3();
	t4();
	t5();
	t6();
	t7();
	t8();
	t9();
	t10();
	t11();
	t12();
	t13();
	t14();
	t15();
	t16();
	t17();
	return 0;
}
Exemplo n.º 10
0
void testFill ()
{
  BTree<int> empty;
  BTree<int> t90 (90,empty,empty),
             t12 (12,t90,empty),
             t30 (30,empty,t12),
             t50 (50,empty,empty),
             t5  (5,t50, empty),
             t7  (7,t30,t5);



 std::ofstream f1 ("before.dot");
 t7.printDotty (f1);

 t7.fillGaps (0,5);

 std::ofstream f2 ("after.dot");
 t7.printDotty (f2);
}
Exemplo n.º 11
0
int main(void){

	printf("Running unit tests...\n");
	initArrays();
	t1();
	t2();
	t3();
	t4();
	t5();
	t6();
	t7();
	t8();
	t9();
	t10();
	t11();
	t12();
	t13();
	t14();

	return 1;
}
Exemplo n.º 12
0
TEST(KVEngineTestHarness, AllCommittedTimestamp) {
    unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
    KVEngine* engine = helper->getEngine();
    if (!engine->supportsDocLocking())
        return;

    unique_ptr<RecordStore> rs;
    {
        MyOperationContext opCtx(engine);
        WriteUnitOfWork uow(&opCtx);
        CollectionOptions options;
        options.capped = true;
        options.cappedSize = 10240;
        options.cappedMaxDocs = -1;

        NamespaceString oplogNss("local.oplog.rs");
        ASSERT_OK(engine->createRecordStore(&opCtx, oplogNss.ns(), "ident", options));
        rs = engine->getRecordStore(&opCtx, oplogNss.ns(), "ident", options);
        ASSERT(rs);
    }
    {
        Timestamp t11(1, 1);
        Timestamp t12(1, 2);
        Timestamp t21(2, 1);

        auto t11Doc = BSON("ts" << t11);
        auto t12Doc = BSON("ts" << t12);
        auto t21Doc = BSON("ts" << t21);

        Timestamp allCommitted = engine->getAllCommittedTimestamp();
        MyOperationContext opCtx1(engine);
        WriteUnitOfWork uow1(&opCtx1);
        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx1, t11Doc.objdata(), t11Doc.objsize(), Timestamp::min())),
                  RecordId(1, 1));

        Timestamp lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        MyOperationContext opCtx2(engine);
        WriteUnitOfWork uow2(&opCtx2);
        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx2, t21Doc.objdata(), t21Doc.objsize(), Timestamp::min())),
                  RecordId(2, 1));
        uow2.commit();

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx1, t12Doc.objdata(), t12Doc.objsize(), Timestamp::min())),
                  RecordId(1, 2));

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        uow1.commit();

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LTE(allCommitted, t21);
    }
}
Exemplo n.º 13
0
//Define vertices and triangles
void CTitanic::init(float aScale)
	{
	this->clearMesh();

	TVector3 v0(-4,2,2);
	this->iVertices.push_back(v0*aScale);

	TVector3 v1(-3,1,0);
	this->iVertices.push_back(v1*aScale);

	TVector3 v2(-3,-1,0);
	this->iVertices.push_back(v2*aScale);

	TVector3 v3(-4,-2,2);
	this->iVertices.push_back(v3*aScale);

	TVector3 v4(3,2,2);
	this->iVertices.push_back(v4*aScale);

	TVector3 v5(3,1,0);
	this->iVertices.push_back(v5*aScale);

	TVector3 v6(3,-1,0);
	this->iVertices.push_back(v6*aScale);

	TVector3 v7(3,-2,2);
	this->iVertices.push_back(v7*aScale);

	TVector3 v8(5,0,2);
	this->iVertices.push_back(v8*aScale);

/*
	TTriangle t0(0,2,1);
	this->iTriangles.push_back(t0);


	TTriangle t1(0,3,2);
	this->iTriangles.push_back(t1);


	TTriangle t2(0,1,4);
	this->iTriangles.push_back(t2);


	TTriangle t3(1,5,4);
	this->iTriangles.push_back(t3);


	TTriangle t4(1,6,5);
	this->iTriangles.push_back(t4);


	TTriangle t5(1,2,6);
	this->iTriangles.push_back(t5);


	TTriangle t6(2,3,6);
	this->iTriangles.push_back(t6);


	TTriangle t7(3,7,6);
	this->iTriangles.push_back(t7);


	TTriangle t8(4,5,8);
	this->iTriangles.push_back(t8);


	TTriangle t9(5,6,8);
	this->iTriangles.push_back(t9);


	TTriangle t10(6,7,8);
	this->iTriangles.push_back(t10);


	TTriangle t11(0,4,3);
	this->iTriangles.push_back(t11);


	TTriangle t12(3,4,7);
	this->iTriangles.push_back(t12);


	TTriangle t13(4,8,7);
	this->iTriangles.push_back(t13);

*/

	TTriangle t0(0,1,2);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,2,3);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,4,1);
	this->iTriangles.push_back(t2);

	TTriangle t3(1,4,5);
	this->iTriangles.push_back(t3);

	TTriangle t4(1,5,6);
	this->iTriangles.push_back(t4);

	TTriangle t5(1,6,2);
	this->iTriangles.push_back(t5);

	TTriangle t6(2,6,3);
	this->iTriangles.push_back(t6);

	TTriangle t7(3,6,7);
	this->iTriangles.push_back(t7);

	TTriangle t8(4,8,5);
	this->iTriangles.push_back(t8);

	TTriangle t9(5,8,6);
	this->iTriangles.push_back(t9);

	TTriangle t10(6,8,7);
	this->iTriangles.push_back(t10);

	TTriangle t11(0,3,4);
	this->iTriangles.push_back(t11);

	TTriangle t12(3,7,4);
	this->iTriangles.push_back(t12);

	TTriangle t13(4,7,8);
	this->iTriangles.push_back(t13);
	}
Exemplo n.º 14
0
void
poisson_blend(mve::FloatImage::ConstPtr src, mve::ByteImage::ConstPtr mask,
    mve::FloatImage::Ptr dest, float alpha) {

    assert(src->width() == mask->width() && mask->width() == dest->width());
    assert(src->height() == mask->height() && mask->height() == dest->height());
    assert(src->channels() == 3 && dest->channels() == 3);
    assert(mask->channels() == 1);
    assert(valid_mask(mask));

    const int n = dest->get_pixel_amount();
    const int width = dest->width();
    const int height = dest->height();
    const int channels = dest->channels();

    mve::Image<int>::Ptr indices = mve::Image<int>::create(width, height, 1);
    indices->fill(-1);
    int index = 0;
    for (int i = 0; i < n; ++i) {
        if (mask->at(i) != 0) {
            indices->at(i) = index;
            index++;
        }
    }
    const int nnz = index;

    std::vector<math::Vec3f> coefficients_b;
    coefficients_b.resize(nnz);

    std::vector<Eigen::Triplet<float, int> > coefficients_A;
    coefficients_A.reserve(nnz); //TODO better estimate...

    for (int i = 0; i < n; ++i) {
        const int row = indices->at(i);
        if (mask->at(i) == 126 || mask->at(i) == 128) {
            Eigen::Triplet<float, int> t(row, row, 1.0f);
            coefficients_A.push_back(t);

            coefficients_b[row] = math::Vec3f(&dest->at(i, 0));
        }

        if (mask->at(i) == 255) {
            const int i01 = indices->at(i - width);
            const int i10 = indices->at(i - 1);
            const int i11 = indices->at(i);
            const int i12 = indices->at(i + 1);
            const int i21 = indices->at(i + width);

            /* All neighbours should be eighter border conditions or part of the optimization. */
            assert(i01 != -1 && i10 != -1 && i11 != -1 && i12 != -1 && i21 != -1);

            Eigen::Triplet<float, int> t01(row, i01, 1.0f);

            Eigen::Triplet<float, int> t10(row, i10, 1.0f);
            Eigen::Triplet<float, int> t11(row, i11, -4.0f);
            Eigen::Triplet<float, int> t12(row, i12, 1.0f);

            Eigen::Triplet<float, int> t21(row, i21, 1.0f);

            Eigen::Triplet<float, int> triplets[] = {t01, t10, t11, t12, t21};

            coefficients_A.insert(coefficients_A.end(), triplets, triplets + 5);

            math::Vec3f l_d = simple_laplacian(i, dest);
            math::Vec3f l_s = simple_laplacian(i, src);

            coefficients_b[row] = (alpha * l_s + (1.0f - alpha) * l_d);
        }
    }

    SpMat A(nnz, nnz);
    A.setFromTriplets(coefficients_A.begin(), coefficients_A.end());

    Eigen::SparseLU<SpMat, Eigen::COLAMDOrdering<int> > solver;
    solver.compute(A);

    for (int channel = 0; channel < channels; ++channel) {
        Eigen::VectorXf b(nnz);
        for (std::size_t i = 0; i < coefficients_b.size(); ++i)
            b[i] = coefficients_b[i][channel];

        Eigen::VectorXf x(n);
        x = solver.solve(b);

        for (int i = 0; i < n; ++i) {
            int index = indices->at(i);
            if (index != -1) dest->at(i, channel) = x[index];
        }
    }
}
Exemplo n.º 15
0
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}