int is_magic_square(Matrix *A){
    //Case that rows and columns not the same
    //Not a Square grid, so cannot be square
    if (A->rows != A->cols){
        printf("Not a square matrix\n");
        return 0;
    }

    //Getting sum of rows
    double *allRowSum = row_sum(A);
    //Get sum of columns
    double *allColSum = col_sum(A);
    //Get sum of diagnols
    double *allDiag = diag_sum(A);
    //Get total of first row - all others should be the same either way
    double magic = allRowSum[0];    

    if (test_rows(allRowSum, A->rows, magic)){
        if (test_cols(allColSum, A->cols, magic)){
            if (test_diag(allDiag, magic)){
                //If rows, cols, and diags are the same
                //We have a magic square!
                return 1;
            }
        }
    }

    return 0;
}
Beispiel #2
0
static void
test_cvtf(const char *name, double fin)
{
    fp80_t v80 = fp80_cvfd(fin);
    double v64 = fp80_cvtd(v80);

    test_diag("Conversion '%e' -> fp80 -> double: %e", fin, v64);

    printf("# ");
    fp80_debug_dump(stdout, v80);
    if (v64 == fin ||
        (isnan(fin) && isnan(v64) && signbit(fin) == signbit(v64))) {
        test_ok(name);
    } else {
        test_diag("MISMATCH: %e != %e", fin, v64);
        test_fail(name);
    }
}
Beispiel #3
0
void test_post_mixed_param() {
	CURL_INIT_POST

	curl_easy_setopt(curl, CURLOPT_URL, "http://0.0.0.0:2000/multi/something/static/other");
	res = curl_easy_perform(curl);

	if(CURLE_OK == res) {
		long status;
		res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);

		test_diag("Test multi param POST status");
		test_cond(status == 200);

		test_diag("Test multi param POST content");
		test_cond(strcmp(chunk.memory, "The params are something and other, the body is Username") == 0);
	}

	free(chunk.memory);
	curl_easy_cleanup(curl);
}
Beispiel #4
0
void test_post_err_404() {
	CURL_INIT_POST

	curl_easy_setopt(curl, CURLOPT_URL, "http://0.0.0.0:2000/invalid");
	res = curl_easy_perform(curl);

	if(CURLE_OK == res) {
		long status;
		res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);

		test_diag("Test POST error 404 status");
		test_cond(status == 404);

		test_diag("Test POST error 404 content");
		test_cond(strcmp(chunk.memory, "Error 404!") == 0);
	}

	free(chunk.memory);
	curl_easy_cleanup(curl);
}
Beispiel #5
0
void test_status_simple() {
	CURL_INIT

	curl_easy_setopt(curl, CURLOPT_URL, "http://0.0.0.0:2000/coffe");
	res = curl_easy_perform(curl);

	if(CURLE_OK == res) {
		long status;
		res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);

		test_diag("Test GET status");
		test_cond(status == 418);

		test_diag("Test GET content");
		test_cond(strcmp(chunk.memory, "Just a teapot!") == 0);
	}

	free(chunk.memory);
	curl_easy_cleanup(curl);
}
Beispiel #6
0
void test_post_simple() {
	CURL_INIT_POST

	curl_easy_setopt(curl, CURLOPT_URL, "http://0.0.0.0:2000/simple");

	res = curl_easy_perform(curl);

	if(CURLE_OK == res) {
		long status;
		res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);

		test_diag("Test simple POST status");
		test_cond(status == 200);

		test_diag("Test simple POST content");
		test_cond(strcmp(chunk.memory, "Hello Username!") == 0);
	}

	free(chunk.memory);
	curl_easy_cleanup(curl);
}
Beispiel #7
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	See file prologue.
 *
 * Return:	Success:
 *
 *		Failure:
 *
 * Programmer:	Robb Matzke
 *              Thursday, May 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main (void)
{
    size_t	io_size;
    double	effic, io_percent;
    FILE	*f, *d;
    size_t	cache_size;
    double	w0;

    /*
     * Create a global file access property list.
     */
    fapl_g = H5Pcreate (H5P_FILE_ACCESS);
    H5Pget_cache (fapl_g, NULL, NULL, NULL, &w0);

    /* Create the file */
    create_dataset ();
    f = fopen ("x-gnuplot", "w");

    printf("Test      %8s %8s %8s\n", "CacheSz", "ChunkSz",  "Effic");
    printf("--------- -------- -------- --------\n");

#if 1
    /*
     * Test row-major reading of the dataset with various sizes of request
     * windows.
     */
    if (RM_CACHE_STRT==RM_CACHE_END) {
	fprintf (f, "set yrange [0:1.2]\n");
	fprintf (f, "set ytics 0, 0.1, 1\n");
	fprintf (f, "set xlabel \"%s\"\n",
		 "Request size as a fraction of chunk size");
	fprintf (f, "set ylabel \"Efficiency\"\n");
	fprintf (f, "set title \"Cache %d chunks, w0=%g, "
		 "Size=(total=%d, chunk=%d)\"\n",
		 RM_CACHE_STRT, w0, DS_SIZE*CH_SIZE, CH_SIZE);
    } else {
	fprintf (f, "set autoscale\n");
	fprintf (f, "set hidden3d\n");
    }

    fprintf (f, "set terminal postscript\nset output \"x-rowmaj-rd.ps\"\n");
    fprintf (f, "%s \"x-rowmaj-rd.dat\" title \"RowMaj-Read\" with %s\n",
	     RM_CACHE_STRT==RM_CACHE_END?"plot":"splot",
	     LINESPOINTS);
    fprintf (f, "set terminal x11\nreplot\n");
    d = fopen ("x-rowmaj-rd.dat", "w");
    for (cache_size=RM_CACHE_STRT;
	 cache_size<=RM_CACHE_END;
	 cache_size+=RM_CACHE_DELT) {
	for (io_percent=RM_START; io_percent<=RM_END; io_percent+=RM_DELTA) {
	    io_size = MAX (1, (size_t)(CH_SIZE*io_percent));
	    printf ("Rowmaj-rd %8d %8.2f", (int)cache_size, io_percent);
	    fflush (stdout);
	    effic = test_rowmaj (READ, cache_size, io_size);
	    printf (" %8.2f\n", effic);
	    if (RM_CACHE_STRT==RM_CACHE_END) {
		fprintf (d, "%g %g\n", io_percent, effic);
	    } else {
		fprintf (d, "%g\n", effic);
	    }
	}
	fprintf (d, "\n");
    }
    fclose (d);
    fprintf (f, "pause -1\n");
#endif

#if 1
    /*
     * Test row-major writing of the dataset with various sizes of request
     * windows.
     */
    if (RM_CACHE_STRT==RM_CACHE_END) {
	fprintf (f, "set yrange [0:1.2]\n");
	fprintf (f, "set ytics 0, 0.1, 1\n");
	fprintf (f, "set xlabel \"%s\"\n",
		 "Request size as a fraction of chunk size");
	fprintf (f, "set ylabel \"Efficiency\"\n");
	fprintf (f, "set title \"Cache %d chunks,w0=%g, "
		 "Size=(total=%d, chunk=%d)\"\n",
		 RM_CACHE_STRT, w0, DS_SIZE*CH_SIZE, CH_SIZE);
    } else {
	fprintf (f, "set autoscale\n");
	fprintf (f, "set hidden3d\n");
    }

    fprintf (f, "set terminal postscript\nset output \"x-rowmaj-wr.ps\"\n");
    fprintf (f, "%s \"x-rowmaj-wr.dat\" title \"RowMaj-Write\" with %s\n",
	     RM_CACHE_STRT==RM_CACHE_END?"plot":"splot",
	     LINESPOINTS);
    fprintf (f, "set terminal x11\nreplot\n");
    d = fopen ("x-rowmaj-wr.dat", "w");
    for (cache_size=RM_CACHE_STRT;
	 cache_size<=RM_CACHE_END;
	 cache_size+=RM_CACHE_DELT) {
	for (io_percent=RM_START; io_percent<=RM_END; io_percent+=RM_DELTA) {
	    io_size = MAX (1, (size_t)(CH_SIZE*io_percent));
	    printf ("Rowmaj-wr %8d %8.2f", (int)cache_size, io_percent);
	    fflush (stdout);
	    effic = test_rowmaj (WRITE, cache_size, io_size);
	    printf (" %8.2f\n", effic);
	    if (RM_CACHE_STRT==RM_CACHE_END) {
		fprintf (d, "%g %g\n", io_percent, effic);
	    } else {
		fprintf (d, "%g\n", effic);
	    }
	}
	fprintf (d, "\n");
    }
    fclose (d);
    fprintf (f, "pause -1\n");
#endif

#if 1
    /*
     * Test diagonal read
     */
    if (DIAG_CACHE_STRT==DIAG_CACHE_END) {
	fprintf (f, "set yrange [0:1.2]\n");
	fprintf (f, "set ytics 0, 0.1, 1\n");
	fprintf (f, "set xlabel \"%s\"\n",
		 "Request size as a fraction of chunk size");
	fprintf (f, "set ylabel \"Efficiency\"\n");
	fprintf (f, "set title \"Cache %d chunks,w0=%g, "
		 "Size=(total=%d, chunk=%d)\"\n",
		 DIAG_CACHE_STRT, w0, DS_SIZE*CH_SIZE, CH_SIZE);
    } else {
	fprintf (f, "set autoscale\n");
	fprintf (f, "set hidden3d\n");
    }
    fprintf (f, "set terminal postscript\nset output \"x-diag-rd.ps\"\n");
    fprintf (f, "%s \"x-diag-rd.dat\" title \"Diag-Read\" with %s\n",
	     DIAG_CACHE_STRT==DIAG_CACHE_END?"plot":"splot", LINESPOINTS);
    fprintf (f, "set terminal x11\nreplot\n");
    d = fopen ("x-diag-rd.dat", "w");
    for (cache_size=DIAG_CACHE_STRT;
	 cache_size<=DIAG_CACHE_END;
	 cache_size+=DIAG_CACHE_DELT) {
	for (io_percent=DIAG_START;
	     io_percent<=DIAG_END;
	     io_percent+=DIAG_DELTA) {
	    io_size = MAX (1, (size_t)(CH_SIZE*io_percent));
	    printf ("Diag-rd   %8d %8.2f", (int)cache_size, io_percent);
	    fflush (stdout);
	    effic = test_diag (READ, cache_size, io_size, MAX (1, io_size/2));
	    printf (" %8.2f\n", effic);
	    if (DIAG_CACHE_STRT==DIAG_CACHE_END) {
		fprintf (d, "%g %g\n", io_percent, effic);
	    } else {
		fprintf (d, "%g\n", effic);
	    }
	}
	fprintf (d, "\n");
    }
    fclose (d);
    fprintf (f, "pause -1\n");
#endif

#if 1
    /*
     * Test diagonal write
     */
    if (DIAG_CACHE_STRT==DIAG_CACHE_END) {
	fprintf (f, "set yrange [0:1.2]\n");
	fprintf (f, "set ytics 0, 0.1, 1\n");
	fprintf (f, "set xlabel \"%s\"\n",
		 "Request size as a fraction of chunk size");
	fprintf (f, "set ylabel \"Efficiency\"\n");
	fprintf (f, "set title \"Cache %d chunks, w0=%g, "
		 "Size=(total=%d, chunk=%d)\"\n",
		 DIAG_CACHE_STRT, w0, DS_SIZE*CH_SIZE, CH_SIZE);
    } else {
	fprintf (f, "set autoscale\n");
	fprintf (f, "set hidden3d\n");
    }
    fprintf (f, "set terminal postscript\nset output \"x-diag-wr.ps\"\n");
    fprintf (f, "%s \"x-diag-wr.dat\" title \"Diag-Write\" with %s\n",
	     DIAG_CACHE_STRT==DIAG_CACHE_END?"plot":"splot", LINESPOINTS);
    fprintf (f, "set terminal x11\nreplot\n");
    d = fopen ("x-diag-wr.dat", "w");
    for (cache_size=DIAG_CACHE_STRT;
	 cache_size<=DIAG_CACHE_END;
	 cache_size+=DIAG_CACHE_DELT) {
	for (io_percent=DIAG_START;
	     io_percent<=DIAG_END;
	     io_percent+=DIAG_DELTA) {
	    io_size = MAX (1, (size_t)(CH_SIZE*io_percent));
	    printf ("Diag-wr   %8d %8.2f", (int)cache_size, io_percent);
	    fflush (stdout);
	    effic = test_diag (WRITE, cache_size, io_size, MAX (1, io_size/2));
	    printf (" %8.2f\n", effic);
	    if (DIAG_CACHE_STRT==DIAG_CACHE_END) {
		fprintf (d, "%g %g\n", io_percent, effic);
	    } else {
		fprintf (d, "%g\n", effic);
	    }
	}
	fprintf (d, "\n");
    }
    fclose (d);
    fprintf (f, "pause -1\n");
#endif


    H5Pclose (fapl_g);
    fclose (f);
    return 0;
}