Repository: TheAlgorithms/C-Plus-Plus
File: hashing/sha256.cpp (C++)

Code before:
    assert(hashing::sha256::compute_padded_size(55) == 64);
    assert(hashing::sha256::compute_padded_size(56) == 128);
    assert(hashing::sha256::compute_padded_size(130) == 192);
}

static void test_extract_byte() {
    assert(hashing::sha256::extract_byte<uint32_t>(512, 0) == 0);
    assert(hashing::sha256::extract_byte<uint32_t>(512, 1) == 2);
    bool exception = false;
    try {
        hashing::sha256::extract_byte<uint32_t>(512, 5);
    } catch (const std::out_of_range) {
        exception = true;
    }
    assert(exception);
}

static void test_get_char() {
    assert(hashing::sha256::get_char("test", 3) == 't');
    assert(hashing::sha256::get_char("test", 4) == '\x80');
    assert(hashing::sha256::get_char("test", 5) == '\x00');
    assert(hashing::sha256::get_char("test", 63) == 32);
    bool exception = false;
    try {
        hashing::sha256::get_char("test", 64);
    } catch (const std::out_of_range) {
        exception = true;
    }
    assert(exception);
}

static void test_right_rotate() {
    assert(hashing::sha256::right_rotate(128, 3) == 16);
    assert(hashing::sha256::right_rotate(1, 30) == 4);
    assert(hashing::sha256::right_rotate(6, 30) == 24);
}

static void test_sha256() {
    struct TestCase {
        const std::string input;
        const std::string expected_hash;
        TestCase(std::string input, std::string expected_hash)
            : input(std::move(input)),
              expected_hash(std::move(expected_hash)) {}
    };
    const std::vector<TestCase> test_cases{
        TestCase(
            "",
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
        TestCase(
            "test",

Review comment (suggestion):
```suggestion
    } catch (const std::out_of_range &) {
```

Code after:

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test_compute_padded_size() {
    assert(hashing::sha256::compute_padded_size(55) == 64);
    assert(hashing::sha256::compute_padded_size(56) == 128);
    assert(hashing::sha256::compute_padded_size(130) == 192);
}

static void test_extract_byte() {
    assert(hashing::sha256::extract_byte<uint32_t>(512, 0) == 0);
    assert(hashing::sha256::extract_byte<uint32_t>(512, 1) == 2);
    bool exception = false;
    try {
        hashing::sha256::extract_byte<uint32_t>(512, 5);
    } catch (const std::out_of_range &) {
        exception = true;
    }
    assert(exception);
}

static void test_get_char() {
    assert(hashing::sha256::get_char("test", 3) == 't');
    assert(hashing::sha256::get_char("test", 4) == '\x80');
    assert(hashing::sha256::get_char("test", 5) == '\x00');
    assert(hashing::sha256::get_char("test", 63) == 32);
    bool exception = false;
    try {
        hashing::sha256::get_char("test", 64);
    } catch (const std::out_of_range &) {
        exception = true;
    }
    assert(exception);
}

static void test_right_rotate() {
    assert(hashing::sha256::right_rotate(128, 3) == 16);
    assert(hashing::sha256::right_rotate(1, 30) == 4);
    assert(hashing::sha256::right_rotate(6, 30) == 24);
}

static void test_sha256() {
    struct TestCase {
        const std::string input;
        const std::string expected_hash;
        TestCase(std::string input, std::string expected_hash)
            : input(std::move(input)),
              expected_hash(std::move(expected_hash)) {}
    };