btrtest.cpp
Go to the documentation of this file.
1 
29 #include <gmp.h>
30 #include <gmpxx.h>
31 #include <fstream>
32 #include <cstring>
33 
34 #include "verifierutils.hpp"
35 
36 using namespace verifierUtils;
37 
38 #define PATH_TO_INPUT_FILE "./input.txt"
39 #define PATH_TO_OUTPUT_FILE "./actual_output.txt"
40 
41 
49 void test_ByteTree_parseString(std::ifstream &input,
50  std::ofstream &output)
51 {
52  ByteTree * bt;
53  std::string line;
54  while (input>>line)
55  {
56  bt = ByteTree::parseString(line);
57  output<<bt->toString()<<std::endl;
58  }
59 }
60 
61 
69 void test_ByteTree_parseFile(std::ifstream &input,
70  std::ofstream &output)
71 {
72  ByteTree * bt;
73  std::string line;
74  while (input>>line)
75  {
76  bt = ByteTree::parseFile(line);
77  output<<bt->toString()<<std::endl;
78  }
79 }
80 
81 
91 void test_Leaf_toInteger(std::ifstream &input, std::ofstream &output)
92 {
93  ByteTree * bt;
94  std::string line;
95  while (input>>line)
96  {
97  mpz_class integer(line,10);
98  bt = new Leaf(integer);
99  output<<bt->toInteger()<<std::endl;
100  }
101 }
102 
103 
115 void test_Leaf_toBoolArray(std::ifstream &input, std::ofstream &output)
116 {
117  ByteTree * bt;
118  unsigned int number;
119  while (input>>number)
120  {
121  std::vector<uint8_t> content(number);
122  for (unsigned int i=0; i<number; i++)
123  {
124  bool b;
125  input>>b;
126  if (b)
127  content[i] = 1;
128  else
129  content[i] = 0;
130  }
131  bt = new Leaf(content);
132  std::vector<bool> array = bt->toBoolArray();
133  for (unsigned int i=0; i<array.size(); i++)
134  if (array[i])
135  output<<"1";
136  else
137  output<<"0";
138  output<<std::endl;
139  }
140 }
141 
142 
147 void printHelp()
148 {
149  std::cout<<"Run ./bt_test <function to test> and it will parse the"
150  <<PATH_TO_INPUT_FILE<< "file to produce the "
151  <<PATH_TO_OUTPUT_FILE<<" file. If this is giberish to you,"
152  <<"you\nshould read the documentation ^^"<<"\n\n"
153  <<"Available functions are:"<<"\n"
154  <<" - ByteTree::parseString\n"
155  <<" - ByteTree::parseFile\n"
156  <<" - Leaf.toInteger\n"
157  <<" - Leaf.toBoolArray\n"
158  <<"\n"<<std::endl;
159 }
160 
161 
162 
163 int main(int argc, char ** argv)
164 {
165  if (argc<2)
166  printHelp();
167  else
168  {
169  std::ifstream input(PATH_TO_INPUT_FILE,
170  std::ifstream::in);
171  std::ofstream output(PATH_TO_OUTPUT_FILE);
172  if (strcmp(argv[1],"ByteTree::parseString") == 0)
173  test_ByteTree_parseString(input,output);
174  else if (strcmp(argv[1],"ByteTree::parseFile") == 0)
175  test_ByteTree_parseFile(input,output);
176  else if (strcmp(argv[1],"Leaf.toInteger") == 0)
177  test_Leaf_toInteger(input,output);
178  else if (strcmp(argv[1],"Leaf.toBoolArray") == 0)
179  test_Leaf_toBoolArray(input,output);
180  else
181  printHelp();
182  output.close();
183  }
184 
185  return 0;
186 }