Hide
Need a quick chart or graph for your blog? Try our reStructured Text renderer. Join Siafoo Now or Learn More

LCS C++ template TEST Atom Feed 0

In Brief Test program for LCSTemplate.h class.
# 's
  1#include <string>
2#include <vector>
3#include <iostream>
4#include "LCSTemplate.h"
5
6/**
7 Author: Michael Case
8 Date Started: ~ 4/13/2011
9
10 Modification notes:
11 2011-04-26:
12 lcs1.1 : cleaned up a bit.
13 lcs5 : removed clear() requirement;
14 lcs5 : implemented char* specialization for *.
15 requires a null-terminated string still... or crashes.
16 lcs6 : allow L_ not to be square.
17 lcs7 : printDiff()
18 **/
19
20// The following specializations and the fact that we HAVE an asize() method
21// for the template is so that char* can use the same template.
22template < >
23size_t LCS< char* >::asize() {
24 size_t sz(0);//what happens if a_ is empty? how do I know it is empty?
25 for (size_t i = 0; a_[i] != '\0'; ++i) {
26 sz++;
27 }
28 return sz;
29}
30
31template < >
32size_t LCS< char* >::bsize() {
33 size_t sz(0);//what happens if b_ is empty? how do I know it is empty?
34 for (size_t i = 0; b_[i] != '\0'; ++i) {
35 sz++;
36 }
37 return sz;
38}
39
40int main () {
41
42 LCS<char*> chrcmpr;
43 LCS<std::string> strcmpr;
44 LCS<std::vector<double> > dblcmpr;
45 char a[6]={'H','U','M','A','N', '\0'};
46 char b[11]={'C','H','I','M','P','A','N','Z','E','E', '\0'};
47
48 chrcmpr(a, b);
49 chrcmpr.printDiff();
50 std::cout << std::string(40,'=') << std::endl;
51 chrcmpr(b,a);
52 chrcmpr.printDiff();
53 std::cout << std::string(40,'=') << std::endl;
54 std::string stra = "HUMAN";
55 std::string strb = "CHIMPANZEE";
56 strcmpr(stra, strb);
57 strcmpr.printDiff();
58 std::cout << std::string(40,'=') << std::endl;
59 strcmpr(strb, stra);
60 strcmpr.printDiff();
61
62 std::vector<double> dbla;
63 dbla.push_back(0.56);
64 dbla.push_back(0.68);
65 dbla.push_back(0.79);
66 dbla.push_back(0.90);
67 dbla.push_back(1.1);
68 dbla.push_back(1.2);
69 dbla.push_back(1.5);
70 std::vector<double> dblb;
71 dblb.push_back(0.68);
72 dblb.push_back(0.78);
73 dblb.push_back(0.90);
74 dblb.push_back(1.5);
75 dblb.push_back(1.8);
76 std::cout << std::string(40,'=') << std::endl;
77 dblcmpr(dbla, dblb);
78 dblcmpr.printDiff();
79 std::cout << std::string(40,'=') << std::endl;
80 dblcmpr(dblb, dbla);
81 dblcmpr.printDiff();
82
83 std::vector<std::string> vecstra, vecstrb;
84 LCS<std::vector<std::string> > cmprstrvec;
85 vecstra.push_back("Now is the time");
86 vecstra.push_back("for all good men");
87 vecstra.push_back("to come to the aid");
88 vecstra.push_back("of their country.");
89 vecstra.push_back("");
90 vecstra.push_back("If Peter Piper picked a peck");
91 vecstra.push_back("of pickled peppers,");
92 vecstra.push_back("how many pickled peppers");
93 vecstra.push_back("did Peter Piper pick?");
94 vecstra.push_back("");
95 vecstra.push_back("Eenie, meenie, miney, moe");
96 vecstra.push_back("Catch a leopard by the toe");
97 vecstra.push_back("If he hollers let him go");
98
99 vecstrb.push_back("My silly rhyming messing around");
100 vecstrb.push_back("");
101 vecstrb.push_back("Now is the time");
102 vecstrb.push_back("for all good men and women");
103 vecstrb.push_back("to come to the aid");
104 vecstrb.push_back("of their country.");
105 vecstrb.push_back("");
106 /* Peter Piper picked a peck of pickled peppers,
107 A peck of pickled peppers Peter Piper picked;
108 If Peter Piper picked a peck of pickled peppers,
109 Where's the peck of pickled peppers Peter Piper picked?*/
110 vecstrb.push_back("Peter Piper picked a peck");
111 vecstrb.push_back("of pickled peppers,");
112 vecstrb.push_back("A peck of pickled peppers");
113 vecstrb.push_back("Peter Piper picked;");
114 vecstrb.push_back("If Peter Piper picked a peck");
115 vecstrb.push_back("of pickled peppers,");
116 vecstrb.push_back("Where's the peck of pickled peppers");
117 vecstrb.push_back("Peter Piper picked?");
118 vecstrb.push_back("");
119 vecstrb.push_back("Note that above, there are two lines");
120 vecstrb.push_back("'of pickled peppers,' which could be");
121 vecstrb.push_back("part of the longest sub-sequence. So");
122 vecstrb.push_back("the result is 'a' longest sub-sequence");
123 vecstrb.push_back("not 'the' longest sub-sequence");
124 vecstrb.push_back("");
125 vecstrb.push_back("Eenie, meenie, miney, moe");
126 vecstrb.push_back("Catch a leopard by the toe");
127 vecstrb.push_back("If he hollers let him go");
128 vecstrb.push_back("");
129 vecstrb.push_back("Here endeth the lesson.");
130 std::cout << std::string(40,'=') << std::endl;
131 cmprstrvec(vecstrb, vecstra);
132 cmprstrvec.printDiff();
133 std::cout << std::string(40,'=') << std::endl;
134 cmprstrvec(vecstra, vecstrb);
135 cmprstrvec.printDiff();
136}

Test program for LCSTemplate.h class.