Skip to content

Commit

Permalink
[test] add more test infomations
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamPast committed Dec 21, 2024
1 parent 418d6af commit b7ca0fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test_cxx20.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
run: cmake --build ${{ github.workspace }}/build --config ${{ matrix.build_type }}
- name: test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --verbose --build-config ${{ matrix.build_type }} --parallel 8
run: ctest --verbose --output-on-failure --build-config ${{ matrix.build_type }} --parallel 8
9 changes: 9 additions & 0 deletions test/cxx20/test_cast_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void testBigString() {
}
}
void test() {
puts("---Some integers");
T_assert(BigInt("0").toString() == "0");
T_assert(BigInt("12").toString() == "12");
T_assert(BigInt("-12").toString() == "-12");
Expand All @@ -31,12 +32,14 @@ void test() {
T_assert(BigInt(i).toString() == std::to_string(i));


puts("---Print");
BigInt("12345678901234567890").print(std::cout);
fprintf(stdout, "\n");
BigInt("-12345678901234567890").print(std::cout);
fprintf(stdout, "\n");
T_assert_exception([] { BigInt("12345678901234567890").print(stdout, 0); }, ULBN_ERR_EXCEED_RANGE);

puts("---Float, Double, Long double");
T_assert(BigInt(0.0).toDouble() == 0.0);
T_assert(BigInt(-0.0).toDouble() == 0.0);
T_assert(BigInt(1.0).toDouble() == 1.0);
Expand All @@ -54,6 +57,7 @@ void test() {
T_assert(BigInt(1.0).toLongDouble() == 1.0L);
T_assert(BigInt(-1.0).toLongDouble() == -1.0L);

puts("---Fit/To slong/ulong/limb/slimb");
for(ulbn_slong_t i = -LIMIT; i <= LIMIT; ++i) {
T_assert(BigInt(i).toSlong() == i);
T_assert(BigInt(i).toUlong() == static_cast<ulbn_ulong_t>(i));
Expand All @@ -64,7 +68,10 @@ void test() {
T_assert(BigInt(i).fitSlong() == fitType<ulbn_slong_t>(i));
T_assert(BigInt(i).fitLimb() == fitType<ulbn_limb_t>(i));
T_assert(BigInt(i).fitSlimb() == fitType<ulbn_slimb_t>(i));
}

puts("---Fit/To float/double/longdouble");
for(ulbn_slong_t i = -LIMIT; i <= LIMIT; ++i) {
float fd = BigInt(i).toFloat();
T_assert(fd == static_cast<float>(i));
T_assert(BigInt(i).fitFloat() == (std::truncf(fd) == fd));
Expand All @@ -90,12 +97,14 @@ void test() {
T_assert(BigInt(static_cast<long double>(i) - 0.5L).toLongDouble() == static_cast<long double>(i));
}

puts("---Random");
for(int t = TEST_SMALL; t--;) {
BigInt x = BigInt::fromRandom(1024).asInt(1024);
auto str = x.toString();
T_assert(str == BigInt(str));
}

puts("---Random (10pow)");
for(int t = TEST_SMALL; t--;) {
BigInt x = BigInt(10).pow(BigInt::fromRandom(12));
auto str = x.toString();
Expand Down

0 comments on commit b7ca0fc

Please sign in to comment.