1 | // vint_test.cpp, created 11.11.2008 by Sebastian Mies
|
---|
2 | // [The FreeBSD Licence]
|
---|
3 | //
|
---|
4 | // Copyright (c) 2008
|
---|
5 | // Sebastian Mies, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
6 | // All rights reserved.
|
---|
7 | //
|
---|
8 | // Redistribution and use in source and binary forms, with or without
|
---|
9 | // modification, are permitted provided that the following conditions are
|
---|
10 | // met:
|
---|
11 | //
|
---|
12 | // * Redistributions of source code must retain the above copyright notice,
|
---|
13 | // this list of conditions and the following disclaimer.
|
---|
14 | // * Redistributions in binary form must reproduce the above copyright
|
---|
15 | // notice, this list of conditions and the following disclaimer in the
|
---|
16 | // documentation and/or other materials provided with the distribution.
|
---|
17 | // * Neither the name of the author nor the names of its contributors may be
|
---|
18 | // used to endorse or promote products derived from this software without
|
---|
19 | // specific prior written permission.
|
---|
20 | //
|
---|
21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
---|
22 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
---|
23 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
---|
28 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
---|
29 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
---|
30 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
---|
31 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
32 | //
|
---|
33 | #include <iostream>
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 | #include "vint.hpp"
|
---|
37 |
|
---|
38 | int test1() {
|
---|
39 | vint<4> u = 15;
|
---|
40 | vint<4> v = u * 2;
|
---|
41 | return v;
|
---|
42 | }
|
---|
43 |
|
---|
44 | int test2() {
|
---|
45 | vint<8> u = 255;
|
---|
46 | u *= 3;
|
---|
47 | return u;
|
---|
48 | }
|
---|
49 |
|
---|
50 | bool vint_test() {
|
---|
51 | char text[4] = { 0x12, 0x34, 0x56, 0x78 };
|
---|
52 | cout << _uint(text) << endl;
|
---|
53 | const char* num = "123456789123456789123456789123456789";
|
---|
54 |
|
---|
55 | vint<> x = 99999u;
|
---|
56 | cout << "x = " << x.to_debug_string(10,20) << " = 99999" << endl;
|
---|
57 | cout << "x == 99999 ? => " << (x == 99999) << endl;
|
---|
58 | cout << "x < 100000 ? => " << (x < 100000) << endl;
|
---|
59 | cout << "x > 100000 ? => " << (x > 100000) << endl;
|
---|
60 | cout << "x < 99998 ? => " << (x < 99998 ) << endl;
|
---|
61 | cout << "x > 99998 ? => " << (x > 99998 ) << endl;
|
---|
62 | cout << x.convert<uint16_t>() << endl;
|
---|
63 |
|
---|
64 | vint<128> i = num;
|
---|
65 | cout << "i=" << i.to_debug_string() << endl;
|
---|
66 |
|
---|
67 | vint<> j = "876543219876543219876543219876543211";
|
---|
68 | cout << "j=" << j.to_debug_string() << endl;
|
---|
69 |
|
---|
70 | vint<> k = i + j;
|
---|
71 | cout << "k=i+j=" << k.to_debug_string() << endl;
|
---|
72 |
|
---|
73 | /* j = "1000";
|
---|
74 | vint<> l = i * j;
|
---|
75 | cout << "l=i*2=" << l.to_debug_string() << endl;
|
---|
76 | cout << "l=i*2=" << l.normalized().to_debug_string() << endl;
|
---|
77 | */
|
---|
78 | vint<4> u = 15;
|
---|
79 | vint<4> v = u * 2;
|
---|
80 |
|
---|
81 | cout << "u = " << u.to_debug_string() << endl;
|
---|
82 | cout << "v = u * 2 = " << v.to_debug_string() << endl;
|
---|
83 | cout << "u < v = " << (u<v) << endl;
|
---|
84 |
|
---|
85 | vint<8> i1 = 231;
|
---|
86 | vint<8> i2 = 23;
|
---|
87 | vint<8> i3 = 255;
|
---|
88 |
|
---|
89 | cout << i3 << ".is_between_ring(231,10)=" << i3.is_between_ring(231,10) << endl;
|
---|
90 | cout << i3 << ".is_between_ring(10,231)=" << i3.is_between_ring(10,231) << endl;
|
---|
91 |
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|