Lolly 1.4.27
Loading...
Searching...
No Matches
blackbox_test.cpp
Go to the documentation of this file.
1/** \file blackbox_test.cpp
2 * \copyright GPLv3
3 * \details A unitest for blackbox.
4 * \author YuanYe
5 * \date 2023
6 */
7#include "a_lolly_test.hpp"
8#include "blackbox.hpp"
9#include "string.hpp"
10#include <climits>
11
13blackbox b1 = close_box<SI> (-2147483648); // int
14blackbox b2 = close_box<SN> (2147483647); // unsigned int
15blackbox b3 = close_box<HI> (-32768); // short
16blackbox b4 = close_box<HN> (32767); // unsiened short
17blackbox b5 = close_box<QI> ('`'); // char
18blackbox b6 = close_box<QN> (255); // unsigned char
20blackbox b8 = close_box<DN> (ULLONG_MAX); // unsigned long long
21blackbox b9 = close_box<pointer> (nullptr); // void*
25
27blackbox t1 = close_box<SI> (1234); // int
28blackbox t2 = close_box<SN> (5678); // unsigned int
29blackbox t3 = close_box<HI> (123); // short
30blackbox t4 = close_box<HN> (234); // unsiened short
31blackbox t5 = close_box<QI> ('t'); // char
32blackbox t6 = close_box<QN> (23); // unsigned char
33blackbox t7 = close_box<DI> (5678); // long long
34blackbox t8 = close_box<DN> (0); // unsigned long long
35blackbox t9 = close_box<pointer> (nullptr); // void*
39
40blackbox t[13] = {t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12};
41blackbox b[13] = {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12};
42string bout[13]= {"",
43 "-2147483648\0",
44 "2147483647",
45 "-32768\0",
46 "32767",
47 "`",
48 "255",
49 "9223372036854775807",
50 "18446744073709551615",
51 "false",
52 "3.14",
53 "3.14159",
54 "3.14159"};
55string tout[13]= {"",
56 "-2147483648\n",
57 "2147483647\t",
58 "-327680",
59 "32767 ",
60 "`\n",
61 "0",
62 "9223372036854775807\n",
63 "18446744073709551615 ",
64 "0",
65 "3.1415926",
66 "3.14159265",
67 "3.1415926535"};
68
69TEST_CASE ("test for get_type() and open_box()") {
70 CHECK (open_box<SI> (b1) == -2147483648);
71 CHECK (open_box<SN> (b2) == 2147483647);
72 CHECK (open_box<HI> (b3) == -32768);
73 CHECK (open_box<HN> (b4) == 32767);
74 CHECK (open_box<QI> (b5) == '`');
75 CHECK (open_box<QN> (b6) == 255);
78 CHECK (open_box<pointer> (b9) == nullptr);
79 CHECK (open_box<float> (b10) == (float) 3.14);
80 CHECK (open_box<double> (b11) == 3.14159265);
81 CHECK (open_box<long double> (b12) == 3.1415926535);
82
83 CHECK (open_box<SI> (t1) == 1234);
84 CHECK (open_box<SN> (t2) == 5678);
85 CHECK (open_box<HI> (t3) == 123);
86 CHECK (open_box<HN> (t4) == 234);
87 CHECK (open_box<QI> (t5) == 't');
88 CHECK (open_box<QN> (t6) == 23);
89 CHECK (open_box<DI> (t7) == 5678);
90 CHECK (open_box<DN> (t8) == 0);
91 CHECK (open_box<pointer> (t9) == nullptr);
92 CHECK (open_box<float> (t10) == 0.0);
93 CHECK (open_box<double> (t11) == 8.567);
94 CHECK (open_box<long double> (t12) == 7.345);
95 // If the incoming template type does not match, an exception will be thrown.
96}
97
98TEST_CASE ("test for equal(), operator== and operator!=") {
99 SUBCASE ("test for operator==") {
100 for (int i= 0; i < 13; i++) {
101 CHECK_EQ (t[i] == t[i], true);
102 }
103 }
104
105 SUBCASE ("test for operator!=") {
106 for (int i= 0; i < 13; i++) {
107 if (i != 0 && i != 9) CHECK_EQ (b[i] != t[i], true);
108 }
109 }
110}
111
112TEST_CASE ("Test fot display() and operator<<") {
113 tm_ostream out;
114 string str;
115 for (int i= 0; i < 13; i++) {
116 out.buffer ();
117 out << b[i];
118 str= out.unbuffer ();
119 CHECK_EQ (str != tout[i], true);
120 if (i != 0) CHECK_EQ (str == bout[i], true);
121 else CHECK_EQ (str != bout[i], true);
122 }
123}
blackbox b12
blackbox t1
blackbox t5
blackbox b1
blackbox t3
blackbox b4
blackbox b0
blackbox t9
blackbox t8
blackbox b9
blackbox t7
string bout[13]
blackbox t2
blackbox t11
blackbox b10
blackbox t6
blackbox t10
blackbox t12
blackbox b2
blackbox b5
blackbox b[13]
string tout[13]
blackbox t4
blackbox b3
blackbox b11
blackbox t[13]
blackbox t0
blackbox b8
blackbox b7
blackbox b6
The list class represents a linked list.
Definition list.hpp:48
string unbuffer()
void buffer()
TEST_CASE("test for operator+= and advance()")