-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint-test.cpp
More file actions
105 lines (96 loc) · 2.06 KB
/
Copy pathint-test.cpp
File metadata and controls
105 lines (96 loc) · 2.06 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// g++ -c int.cpp -Wall
// g++ int.o int-test.cpp -o int-test/int-test -Wall
#include "int.h"
#include "test.h"
using namespace std;
Test tout;
void test_io()
{
Int a;
while (cin >> a)
cout << a << endl;
}
void test_arithmetic()
{
Int a, b, r; char op;
while (cin >> a >> op >> b)
{
switch (op)
{
case '<': cout << (a < b) << endl; break;
case '+': cout << a + b << endl; break;
case '-': cout << a - b << endl; break;
case '*': cout << a * b << endl; break;
case '/': cout << divmod(a, b, r) << ", ";
cout << r << endl; break;
case '^': cout << a.pow(b) << endl; break;
}
}
}
void test_factorial()
{
int n = 99;
Int prod = 1;
while (n != 0)
prod *= (n--);
tout << prod;
tout.test("933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000");
}
void test_bit()
{
Int a, b; char op;
while (cin >> a >> op >> b)
{
switch (op)
{
case '<': cout << (a << b.to_int()) << endl; break;
case '>': cout << (a >> b.to_int()) << endl; break;
case '^': cout << (a ^ b) << endl; break;
case '&': cout << (a & b) << endl; break;
case '|': cout << (a | b) << endl; break;
case '~': cout << (~a) << endl; break;
}
}
}
void test_to_int()
{
Int a;
cout << "LLONG_MAX =\n" << LLONG_MAX << '\n';
while (cin >> a)
cout << a.to_int() << endl;
}
void test_add()
{
Int a, b, dest;
while (cin >> a >> b)
{
Int::add(a.data.begin(), a.data.end(), b.data.begin(), b.data.end(), dest);
cout << dest << endl;
}
}
void help()
{
cout << "usage: int-test [option]\n"
"-i test_io\n"
"-a test_arithmetic\n"
"-f test_factorial\n"
"-b test_bit\n"
"-t test_to_int\n"
"-A test_add\n";
exit(0);
}
int main(int argc, char **argv)
{
if (argc < 2)
help();
switch (argv[1][1]) {
case 'i': test_io(); break;
case 'a': test_arithmetic(); break;
case 'f': test_factorial(); break;
case 'b': test_bit(); break;
case 't': test_to_int(); break;
case 'A': test_add(); break;
default: help();
}
return 0;
}