Skip to content

Commit

Permalink
[2_2] add blackbox_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanmxc committed Aug 10, 2023
1 parent fb5b3dc commit d93c060
Showing 1 changed file with 55 additions and 32 deletions.
87 changes: 55 additions & 32 deletions tests/Kernel/Abstractions/blackbox_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
#include "string.hpp"

blackbox b0;
blackbox b1 = close_box<SI> (-2147483648); // int
blackbox b2 = close_box<SN> (2147483647); // unsigned int
blackbox b3 = close_box<HI> (-32768); // short
blackbox b4 = close_box<HN> (32767); // unsiened short
blackbox b5 = close_box<QI> ('`'); // char
blackbox b6 = close_box<QN> (255); // unsigned char
blackbox b7 = close_box<DI> (LLONG_MAX); // long long
blackbox b8 = close_box<DN> (ULLONG_MAX); // unsigned long long
blackbox b9 = close_box<pointer> (0); // void*
blackbox b1 = close_box<SI> (-2147483648); // int
blackbox b2 = close_box<SN> (2147483647); // unsigned int
blackbox b3 = close_box<HI> (-32768); // short
blackbox b4 = close_box<HN> (32767); // unsiened short
blackbox b5 = close_box<QI> ('`'); // char
blackbox b6 = close_box<QN> (255); // unsigned char
blackbox b7 = close_box<DI> (LLONG_MAX); // long long
blackbox b8 = close_box<DN> (ULLONG_MAX); // unsigned long long
blackbox b9 = close_box<pointer> (nullptr); // void*
blackbox b10= close_box<float> (3.14);
blackbox b11= close_box<double> (3.14159265);
blackbox b12= close_box<long double> (3.1415926535);

blackbox t0;
blackbox t1 = close_box<SI> (0); // int
blackbox t2 = close_box<SN> (0); // unsigned int
blackbox t3 = close_box<HI> (0); // short
blackbox t4 = close_box<HN> (0); // unsiened short
blackbox t5 = close_box<QI> (0); // char
blackbox t6 = close_box<QN> (0); // unsigned char
blackbox t7 = close_box<DI> (0); // long long
blackbox t8 = close_box<DN> (0); // unsigned long long
blackbox t9 = close_box<pointer> (0); // void*
blackbox t10= close_box<float> (0);
blackbox t11= close_box<double> (0);
blackbox t12= close_box<long double> (0);
blackbox t1 = close_box<SI> (1234); // int
blackbox t2 = close_box<SN> (5678); // unsigned int
blackbox t3 = close_box<HI> (123); // short
blackbox t4 = close_box<HN> (234); // unsiened short
blackbox t5 = close_box<QI> ('t'); // char
blackbox t6 = close_box<QN> (23); // unsigned char
blackbox t7 = close_box<DI> (5678); // long long
blackbox t8 = close_box<DN> (0); // unsigned long long
blackbox t9 = close_box<pointer> (nullptr); // void*
blackbox t10= close_box<float> (0.0);
blackbox t11= close_box<double> (8.567);
blackbox t12= close_box<long double> (7.345);

blackbox t[13] = {t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12};
blackbox b[13] = {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12};
Expand Down Expand Up @@ -68,22 +68,45 @@ string tout[13]= {"",
"3.14159265",
"3.1415926535"};

TEST_CASE ("test for get_type()") {
for (int i= 1; i < 13; i++) {
CHECK_EQ (b[i]->get_type () == -13 + i, true);
CHECK_EQ (t[i]->get_type () == -13 + i, true);
}
TEST_CASE ("test for get_type() and open_box()") {
CHECK (open_box<SI> (b1) == -2147483648);
CHECK (open_box<SN> (b2) == 2147483647);
CHECK (open_box<HI> (b3) == -32768);
CHECK (open_box<HN> (b4) == 32767);
CHECK (open_box<QI> (b5) == '`');
CHECK (open_box<QN> (b6) == 255);
CHECK (open_box<DI> (b7) == LLONG_MAX);
CHECK (open_box<DN> (b8) == ULLONG_MAX);
CHECK (open_box<pointer> (b9) == nullptr);
CHECK (open_box<float> (b10) == (float) 3.14);
CHECK (open_box<double> (b11) == 3.14159265);
CHECK (open_box<long double> (b12) == 3.1415926535);

CHECK (open_box<SI> (t1) == 1234);
CHECK (open_box<SN> (t2) == 5678);
CHECK (open_box<HI> (t3) == 123);
CHECK (open_box<HN> (t4) == 234);
CHECK (open_box<QI> (t5) == 't');
CHECK (open_box<QN> (t6) == 23);
CHECK (open_box<DI> (t7) == 5678);
CHECK (open_box<DN> (t8) == 0);
CHECK (open_box<pointer> (t9) == nullptr);
CHECK (open_box<float> (t10) == 0.0);
CHECK (open_box<double> (t11) == 8.567);
CHECK (open_box<long double> (t12) == 7.345);
// If the incoming template type does not match, an exception will be thrown.
}

TEST_CASE ("test for equal(), operator== and operator!=") {
SUBCASE ("test for operator==") {
for (int i= 0; i < 13; i++) {
CHECK_EQ (b[i] == b[i], true);
if (i == 0 || i == 9) CHECK_EQ (b[i] == t[i], true);
else CHECK_EQ (b[i] != t[i], true);
for (int j= 0; j < 13; j++) {
if (i != j) CHECK_EQ (b[i] != b[j], true);
}
CHECK_EQ (t[i] == t[i], true);
}
}

SUBCASE ("test for operator!=") {
for (int i= 0; i < 13; i++) {
if (i != 0 && i != 9) CHECK_EQ (b[i] != t[i], true);
}
}
}
Expand Down

0 comments on commit d93c060

Please sign in to comment.