-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_num.cpp
More file actions
40 lines (35 loc) · 849 Bytes
/
test_num.cpp
File metadata and controls
40 lines (35 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include "my_num.h"
int main(int argc, char* argv[]) {
std::string filename = "test_nums.txt";
std::ofstream out_str(filename.c_str());
s_t num1 = pow(2,39)-1;
MyNum n1(num1);
n1.write(out_str);
MyNum n2(pow(2,39));
n2.write(out_str);
out_str.close();
assert(n2<=n1);
std::cout<<"Reading those back in\n";
std::ifstream in_str(filename.c_str());
while (n1.read(in_str)) {
std::cout<<"NUM:\n";
std::cout<<n1.size()<<' '<<n1.getNum()<<'\n';
}
if (argc>1) {
std::ifstream in_str(argv[1]);
s_t past=0;
while (n1.read(in_str)) {
if (n1.getNum()<past) {
std::cout<<n1.getNum()<<" Out of order\n";
return 0;
}
else
past = n1.getNum();
}
std::cout<<"Rest is in order\n";
}
}