forked from an146/iv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.cpp
82 lines (79 loc) · 1.77 KB
/
test1.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include "list.h"
// simple stream editor using iv::string as text container
struct f1_type
{
iv::list<char> text;
void operator ()(char c)
{
if (std::isalpha(c))
text.push_back(c);
}
operator std::string() const
{
std::string ret;
ret.assign(text.begin(), text.end());
return ret;
}
} f1;
struct f2_type : public std::string
{
void operator ()(char c)
{
if (std::isalpha(c))
push_back(c);
}
} f2;
int main(int argc, char **argv)
{
std::cout << "Test1" << std::endl;
{
iv::list<char> s1;
assert(s1.begin() == s1.end());
iv::list<char>::const_iterator end = s1.begin();
s1.push_back('\0');
assert(end == s1.end());
iv::list<char>::const_iterator j = s1.begin();
assert(j != s1.end());
assert(j == s1.root());
assert(!j.left());
assert(!j.right());
++j;
assert(j == end);
//assert(!s1.begin().expired());
//assert(!j.expired());
s1.push_back('\001');
iv::list<char>::const_iterator k = s1.begin();
//if (k != end)
//std::cerr << (int)*k << " " << k.lock() << std::endl;
++k;
//if (k != end)
//std::cerr << (int)*k << " " << k.lock() << std::endl;
assert(k != end);
++k;
//if (k != end)
//std::cerr << (int)*k << " " << k.lock() << std::endl;
assert(k == s1.end());
}
std::ifstream random("/dev/urandom", std::ios::binary);
char c;
int i = 0;
while (random.get(c)) {
if (i % 1000 == 0)
std::cout << i << std::endl;
f1(c);
f2(c);
if (i++ >= std::atoi(argv[1]))
break;
}
if (static_cast<std::string>(f1) != f2) {
std::cerr << "mismatch: char " << c << " (" << (int)c << ") pos " << i << " ";
std::cerr << "\"" << static_cast<std::string>(f1) << "\" != \"" << f2 << "\"" << std::endl;
return 1;
}
return 0;
}