source: trunk/src/mesh/test_grid1d.cc @ 253

Last change on this file since 253 was 253, checked in by cxsong, 18 years ago

moved to src/mesh dir

File size: 2.0 KB
Line 
1#include <stdio.h>
2#include "grid1d.h"
3
4#define Num_points 20
5
6static double points[20] = {
7        0.261243291268,
8        0.159055762008,
9        0.214550893827,
10        0.11741510008,
11        0.119735699467,
12        0.15196145742,
13        0.0245663797288,
14        0.128903081711,
15        0.0927746958394,
16        0.0465364541799,
17        0.531606236106,
18        0.252448742721,
19        0.348575614391,
20        0.180939456908,
21        0.0251118046222,
22        0.810354715199,
23        0.0980414196039,
24        0.392354903151,
25        0.151346474849,
26        0.368703495654
27};
28
29static double points2[20][2] = {
30        0.309504615287, 0.844069129715,
31        0.269863116215, 0.589394224151,
32        0.948725301748, 0.226146486693,
33        0.844001851438, 0.139117111982,
34        0.141301087635, 0.847379885543,
35        0.913736318664, 0.166307778641,
36        0.134835615817, 0.182195034894,
37        0.151951467689, 0.848317450773,
38        0.671395143807, 0.138181958412,
39        0.424175028887, 0.10971049923,
40        0.904360553671, 0.587825545849,
41        0.58394908746, 0.432312932998,
42        0.88346489886, 0.394555137211,
43        0.288191101648, 0.627845397977,
44        0.197603800892, 0.127081587039,
45        0.86023335618, 0.942017313532,
46        0.484988525736, 0.202152039484,
47        0.56932761081, 0.689154883236,
48        0.62612255133, 0.241720210408,
49        0.591576322723, 0.623256005171
50};
51
52int main()
53{
54        int i, j, err;
55
56        printf("Testing RpGrid1d\n");
57
58        printf("Testing constructor\n");
59        RpGrid1d grid1(20);
60
61        printf("vector size: %d\n", grid1.numPoints());
62        printf("capacity: %d\n", grid1.capacity());
63
64        printf("Testing addAllPoints\n");
65        grid1.addAllPoints(&(points[0]), 20);
66
67        printf("vector size: %d\n", grid1.numPoints());
68
69        printf("Testing print\n");
70        grid1.print();
71
72        printf("Testing serialize\n");
73
74        int nbytes;
75        char* buf = grid1.serialize(nbytes);
76        printf("nbytes=%d\n", nbytes);
77
78        FILE* fp = fopen("out.grid", "w");
79        fwrite(buf, 1, nbytes, fp);
80        fclose(fp);
81
82        printf("Testing deserialize\n");
83        grid1.deserialize(buf);
84        grid1.print();
85
86        printf("Testing instantiation from byte stream\n");
87        RpGrid1d * grid2;
88
89        grid2 = new RpGrid1d(buf);
90
91        grid2->print();
92
93        printf("Testing addPoint\n");
94
95        RpGrid1d grid3(20);
96        grid3.addPoint(points[0]);
97        grid3.addPoint(points[1]);
98        printf("size=%d\n", grid3.numPoints());
99        grid3.print();
100
101
102        return 0;
103}
Note: See TracBrowser for help on using the repository browser.