Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Test test utils printing
Browse files Browse the repository at this point in the history
  • Loading branch information
gevtushenko committed Jan 7, 2023
1 parent 3cd678e commit 475f96f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions test/catch2_test_printing.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "test_util.h"

#include "catch2_test_helper.h"

template <typename T>
std::string print(T val)
{
std::stringstream ss;
ss << val;
return ss.str();
}

#if CUB_IS_INT128_ENABLED
TEST_CASE("Test utils can print __int128", "[test][utils]")
{
REQUIRE( print(__int128_t{0}) == "0" );
REQUIRE( print(__int128_t{42}) == "42" );
REQUIRE( print(__int128_t{-1}) == "-1" );
REQUIRE( print(__int128_t{-42}) == "-42" );
REQUIRE( print(__int128_t{-1} << 120) == "-1329227995784915872903807060280344576" );
}

TEST_CASE("Test utils can print __uint128", "[test][utils]")
{
REQUIRE( print(__uint128_t{0}) == "0" );
REQUIRE( print(__uint128_t{1}) == "1" );
REQUIRE( print(__uint128_t{42}) == "42" );
REQUIRE( print(__uint128_t{1} << 120) == "1329227995784915872903807060280344576" );
}
#endif

TEST_CASE("Test utils can print KeyValuePair", "[test][utils]")
{
REQUIRE( print(cub::KeyValuePair<int, int>{42, -42}) == "(42,-42)" );
}

4 changes: 2 additions & 2 deletions test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,14 @@ static std::ostream& operator<<(std::ostream& os, __uint128_t val)
{
constexpr int max_digits = 40;
char buffer[max_digits] = {};
char* digit = buffer + max_digits - 1;
char* digit = buffer + max_digits;
const char* ascii = "0123456789";

do
{
digit--;
*digit = ascii[val % 10];
val /= 10;
digit--;
}
while(val != 0);

Expand Down

0 comments on commit 475f96f

Please sign in to comment.