Exemplo n.º 1
0
Arquivo: test.c Projeto: esheldon/misc
void test_point() {
    int ndim = 5;
    int i;
    double diff;

    int retval = 0;

    printf("\nTesting points\n");
    struct Point* p1 = PointAlloc(ndim);
    struct Point* p2 = PointAlloc(ndim);
    struct Point* p3;

    for (i=0; i<p1->x->size; i++) {
        p1->x->data[i] = (double) i;
        p2->x->data[i] = (double) 2*i;

        printf("p1->x->data[%d]: %lf\n", i, p1->x->data[i]);
        printf("p2->x->data[%d]: %lf\n", i, p2->x->data[i]);
    }

    if (PointEqual(p1,p2)) {
        printf("Points are equal\n");
    } else {
        printf("Points differ\n");
    }

    diff = PointDist(p1,p2);

    if (diff < 0.0) {
        retval = 1;
    } else {
        printf("diff: %lf\n", diff);
    }

    printf("copying Points\n");
    PointCopy(p2,p1);

    if (PointEqual(p1,p2)) {
        printf("Points are equal\n");
    } else {
        printf("Points differ\n");
    }

    // this would fail
    //PointEqual(p1,p3);

    PointFree(p1);
    PointFree(p2);

}
Exemplo n.º 2
0
int main(int argc, const char * argv[])
{
	char *filePath = NULL;
	PathInit(argv[0]);
    PathForFile("w256-001.gp", &filePath);
    
	assert(filePath != NULL);
    CurveRef curve = CurveCreateFromFile(filePath);
	assert(curve != NULL);
	
	PointRef g = curve->g;
	mpz_t m;
	mpz_init_set_str(m, "888493310283202167031085660111238327945443791805939712000426466539273165903", 10);
	
	PointRef g2 = PointCreateMultiple(g, m, curve);
	
	mpz_t xr, yr;
	mpz_init_set_str(xr, "5441683091496050436439782524673611468679503009264125966279940185557193452058", 10);
	mpz_init_set_str(yr, "126373273530397135676109694298926901726086297191360274402845796485476517565", 10);
	
	assert(mpz_cmp(g2->x, xr) == 0);
	assert(mpz_cmp(g2->y, yr) == 0);
	
	mpz_set_si(m, 0);
	PointRef g3 = PointCreateMultiple(g, m, curve);
	assert(PointIsTeta(g3));
	
	mpz_set_si(m, 1);
	PointRef g4 = PointCreateMultiple(g, m, curve);
	assert(PointEqual(g4, g));
	
    return 0;
}