ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/gtest.cpp
Revision: 144
Committed: Thu Dec 22 19:15:46 2011 UTC (7 years, 7 months ago) by gpertea
File size: 2772 byte(s)
Log Message:
added GBitVec.h; removed operator> requirement for sorted vectors; swap() is now template Gswap()

Line User Rev File contents
1 gpertea 18 #include "GBase.h"
2     #include "GArgs.h"
3     #include "GStr.h"
4 gpertea 144 #include "GBitVec.h"
5 gpertea 18
6     #define USAGE "Usage:\n\
7 gpertea 144 gtest [--bit-test|-g|--genomic-fasta <genomic_seqs_fasta>] [-c|COV=<cov%>] \n\
8 gpertea 18 [-s|--seq <seq_info.fsize>] [-o|--out <outfile.gff>] [--disable-flag] [-t|--test <string>]\n\
9     [-p|PID=<pid%>] file1 [file2 file3 ..]\n\
10     "
11     enum {
12     OPT_HELP=1,
13     OPT_GENOMIC,
14     OPT_COV,
15     OPT_SEQ,
16     OPT_OUTFILE,
17     OPT_DISABLE_FLAG,
18     OPT_TEST,
19     OPT_PID,
20 gpertea 144 OPT_BITVEC
21 gpertea 18 };
22    
23     GArgsDef opts[] = {
24     {"help", 'h', 0, OPT_HELP},
25     {"genomic-fasta", 'g', 1, OPT_GENOMIC},
26     {"COV", 'c', 1, OPT_COV},
27     {"seq", 's', 1, OPT_SEQ},
28     {"out", 'o', 1, OPT_OUTFILE},
29     {"disable-flag", 0, 0, OPT_DISABLE_FLAG},
30     {"test", 't', 1, OPT_TEST},
31     {"PID", 'p', 1, OPT_PID},
32 gpertea 144 {"bit-test", 'B', 0, OPT_BITVEC},
33 gpertea 18 {0,0,0,0}
34     };
35    
36 gpertea 144 void bitError(int idx) {
37     GError("Error bit checking (index %d)!\n", idx);
38     }
39    
40    
41 gpertea 18 int main(int argc, char * const argv[]) {
42     //GArgs args(argc, argv, "hg:c:s:t:o:p:help;genomic-fasta=COV=PID=seq=out=disable-flag;test=");
43     GArgs args(argc, argv, opts);
44     fprintf(stderr, "Command line was:\n");
45     args.printCmdLine(stderr);
46     args.printError(USAGE, true);
47     //if (args.getOpt('h') || args.getOpt("help"))
48     if (args.getOpt(OPT_HELP))
49     {
50     GMessage("%s\n", USAGE);
51     exit(1);
52     }
53     int numopts=args.startOpt();
54     if (numopts)
55     GMessage("#### Recognized %d option arguments:\n", numopts);
56     int optcode=0;
57     while ((optcode=args.nextCode())) {
58     char* r=args.getOpt(optcode);
59     GMessage("%14s\t= %s\n", args.getOptName(optcode), (r[0]==0)?"True":r);
60     }
61     int numargs=args.startNonOpt();
62     if (numargs>0) {
63     GMessage("\n#### Found %d non-option arguments given:\n", numargs);
64     char* a=NULL;
65     while ((a=args.nextNonOpt())) {
66     GMessage("%s\n",a);
67     }
68     }
69 gpertea 99 GStr s=args.getOpt('t');
70     if (!s.is_empty()) {
71     GStr token;
72     GMessage("Tokens in \"%s\" :\n",s.chars());
73     s.startTokenize(";,: \t");
74     int c=1;
75     while (s.nextToken(token)) {
76     GMessage("token %2d : \"%s\"\n",c,token.chars());
77     c++;
78     }
79     }
80 gpertea 144 if (args.getOpt(OPT_BITVEC)) {
81     GBitVec bits(2044);
82     GMessage(">>> -- Start BitVec Test -- \n");
83     if (bits[1092]) bitError(1092);
84     bits.resize(2049);
85     if (bits[2048]) bitError(2048);
86     bits[2048]=true;
87     if (!bits[2048]) bitError(2048);
88     bits.resize(4097);
89     if (!bits[2048]) bitError(2048);
90     if (bits[4096]) bitError(4096);
91     bits[4096]=true;
92     if (!bits[4096]) bitError(4096);
93     GBitVec bits2(64);
94     Gswap(bits, bits2);
95     if (!bits2[2048]) bitError(2048);
96     if (!bits2[4096]) bitError(4096);
97    
98     GMessage("<<< -- End BitVec Test (size: %d, count: %d, bits2 size=%d, count=%d) --\n",
99     bits.size(), bits.count(), bits2.size(), bits2.count());
100     }
101 gpertea 18 }