ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/gtest.cpp
Revision: 310
Committed: Fri Mar 22 20:06:27 2013 UTC (6 years, 1 month ago) by gpertea
File size: 3863 byte(s)
Log Message:
sync with igm repo

Line File contents
1 #include "GBase.h"
2 #include "GArgs.h"
3 #include "GStr.h"
4 #include "GBitVec.h"
5 #include "GList.hh"
6 #include "GHash.hh"
7
8 #define USAGE "Usage:\n\
9 gtest [--bit-test|-g|--genomic-fasta <genomic_seqs_fasta>] [-c|COV=<cov%>] \n\
10 [-s|--seq <seq_info.fsize>] [-o|--out <outfile.gff>] [--disable-flag] [-t|--test <string>]\n\
11 [-p|PID=<pid%>] file1 [file2 file3 ..]\n\
12 "
13 enum {
14 OPT_HELP=1,
15 OPT_GENOMIC,
16 OPT_COV,
17 OPT_SEQ,
18 OPT_OUTFILE,
19 OPT_DISABLE_FLAG,
20 OPT_TEST,
21 OPT_PID,
22 OPT_BITVEC
23 };
24
25 GArgsDef opts[] = {
26 {"help", 'h', 0, OPT_HELP},
27 {"genomic-fasta", 'g', 1, OPT_GENOMIC},
28 {"COV", 'c', 1, OPT_COV},
29 {"seq", 's', 1, OPT_SEQ},
30 {"out", 'o', 1, OPT_OUTFILE},
31 {"disable-flag", 0, 0, OPT_DISABLE_FLAG},
32 {"test", 't', 1, OPT_TEST},
33 {"PID", 'p', 1, OPT_PID},
34 {"bit-test", 'B', 0, OPT_BITVEC},
35 {0,0,0,0}
36 };
37
38 void bitError(int idx) {
39 GError("Error bit checking (index %d)!\n", idx);
40 }
41
42 struct Gint {
43 int v;
44 Gint(int vv=0):v(vv) {}
45 int val() { return v; }
46 ~Gint() {
47 GMessage("Gint with val %d getting destroyed\n", v);
48 }
49 };
50
51 int cmpGint(pointer p1, pointer p2) {
52 int v1=((Gint*)p1)->v;
53 int v2=((Gint*)p2)->v;
54 if (v1<v2) return -1;
55 return (v1>v2)? 1 : 0;
56 }
57
58 void testGPVec() {
59 GPVec<Gint> vecs[3];
60 vecs[1].Add(new Gint(2));
61 vecs[2].Add(new Gint(3));
62 GMessage("Added to vecs[1]:%d\n", vecs[1][0]->val());
63 GMessage("Added to vecs[2]:%d\n", vecs[2][0]->val());
64 }
65
66 int main(int argc, char * const argv[]) {
67 //GArgs args(argc, argv, "hg:c:s:t:o:p:help;genomic-fasta=COV=PID=seq=out=disable-flag;test=");
68 GArgs args(argc, argv, opts);
69 fprintf(stderr, "Command line was:\n");
70 args.printCmdLine(stderr);
71 args.printError(USAGE, true);
72 //if (args.getOpt('h') || args.getOpt("help"))
73 if (args.getOpt(OPT_HELP))
74 {
75 GMessage("%s\n", USAGE);
76 exit(1);
77 }
78 //---
79 GHash<GVec<int> > ends;
80
81 /*
82 testGPVec();
83 //exit(0);
84
85 //uint pos=3;
86 //GStr spos((int)pos);
87 //GVec<int> *ev=ends[spos.chars()];
88
89 GPVec<Gint> v;
90 int r(5);
91 int rr=v.Add(new Gint(3));
92 //if (rr<0) {
93 // GMessage("Error adding 0! (code %d)\n",rr);
94 // }
95 v.Add(new Gint(r));
96 v.Add(new Gint(2));
97 v.Add(new Gint(1));
98 v.Add(new Gint(4));
99 rr=v.Add(new Gint(0));
100 v[rr]->v=-1;
101 v.Sort(cmpGint);
102 GMessage("collection has %d elements:\n",v.Count());
103 for (int i=0;i<v.Count();i++) {
104 GMessage("v[%d]=%d;\n",i,v[i]->v);
105 }
106 exit(0);
107 */
108 //---
109
110 int numopts=args.startOpt();
111 if (numopts)
112 GMessage("#### Recognized %d option arguments:\n", numopts);
113 int optcode=0;
114 while ((optcode=args.nextCode())) {
115 char* r=args.getOpt(optcode);
116 GMessage("%14s\t= %s\n", args.getOptName(optcode), (r[0]==0)?"True":r);
117 }
118 int numargs=args.startNonOpt();
119 if (numargs>0) {
120 GMessage("\n#### Found %d non-option arguments given:\n", numargs);
121 char* a=NULL;
122 while ((a=args.nextNonOpt())) {
123 GMessage("%s\n",a);
124 }
125 }
126 GStr s=args.getOpt('t');
127 if (!s.is_empty()) {
128 GStr token;
129 GMessage("Tokens in \"%s\" :\n",s.chars());
130 s.startTokenize(";,: \t");
131 int c=1;
132 while (s.nextToken(token)) {
133 GMessage("token %2d : \"%s\"\n",c,token.chars());
134 c++;
135 }
136 }
137 if (args.getOpt(OPT_BITVEC)) {
138 GBitVec bits(2044);
139 GMessage(">>> -- Start BitVec Test -- \n");
140 if (bits[1092]) bitError(1092);
141 bits.resize(2049);
142 if (bits[2048]) bitError(2048);
143 bits[2048]=true;
144 if (!bits[2048]) bitError(2048);
145 bits.resize(4097);
146 if (!bits[2048]) bitError(2048);
147 if (bits[4096]) bitError(4096);
148 bits[4096]=true;
149 if (!bits[4096]) bitError(4096);
150 GBitVec bits2(64);
151 Gswap(bits, bits2);
152 if (!bits2[2048]) bitError(2048);
153 if (!bits2[4096]) bitError(4096);
154
155 GMessage("<<< -- End BitVec Test (size: %d, count: %d, bits2 size=%d, count=%d) --\n",
156 bits.size(), bits.count(), bits2.size(), bits2.count());
157 }
158 }