<commit_before>#include "shg/matrix.h"
#include <iomanip>
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include "shg/utils.h"

namespace SHG::BTesting {

BOOST_AUTO_TEST_SUITE(matrix_test)

const std::ios_base::openmode binary_io_mode =
     std::ios_base::out | std::ios_base::in | std::ios_base::binary;

BOOST_AUTO_TEST_CASE(matrix_constructor_test) {
     {
          const Matint a;
          BOOST_CHECK(a.nrows() == 0 && a.ncols() == 0);
     }
     {
          const Matint a(3, 4);
          BOOST_CHECK(a.nrows() == 3 && a.ncols() == 4);
     }
     {
          const Matint a(3, 4, 11);
          BOOST_CHECK(a.nrows() == 3 && a.ncols() == 4);
          for (Matint::size_type i = 0; i < a.nrows(); i++)
               for (Matint::size_type j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == 11);
     }
     {
          const int b[] = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5,
                           2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
          const Matint a(4, 5, b);
          for (Matint::size_type i = 0; i < a.nrows(); i++)
               for (Matint::size_type j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == narrow_cast<int>(i + j));
     }
     {
          const std::size_t m = 4;
          const std::size_t n = 5;
          int** p = alloc_c_matrix<int>(m, n);
          for (std::size_t i = 0; i < m; i++)
               for (std::size_t j = 0; j < n; j++)
                    p[i][j] = i + j;
          Matint a(m, n, p);
          BOOST_CHECK(a.nrows() == m && a.ncols() == n);
          for (size_t i = 0; i < a.nrows(); i++)
               for (size_t j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == p[i][j]);
          free_c_matrix(p);
     }
     {
          const Vecint v(12, 13);
          const Matint a(3, 4, v);
          BOOST_CHECK(equal(v, Vecint(12, 13)) &&
                      equal(a, Matint(3, 4, 13)));
     }
     {
          const Vecint v(11, 13);
          BOOST_CHECK_THROW(Matint(3, 4, v), std::invalid_argument);
     }
     {
          Vecint v(12, 13);
          Matint a(3, 4, std::move(v));
          BOOST_CHECK(v.size() == 0 && equal(a, Matint(3, 4, 13)));<commit_msg>size_t --> std::size_t.<commit_after>#include "shg/matrix.h"
#include <iomanip>
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include "shg/utils.h"

namespace SHG::BTesting {

BOOST_AUTO_TEST_SUITE(matrix_test)

const std::ios_base::openmode binary_io_mode =
     std::ios_base::out | std::ios_base::in | std::ios_base::binary;

BOOST_AUTO_TEST_CASE(matrix_constructor_test) {
     {
          const Matint a;
          BOOST_CHECK(a.nrows() == 0 && a.ncols() == 0);
     }
     {
          const Matint a(3, 4);
          BOOST_CHECK(a.nrows() == 3 && a.ncols() == 4);
     }
     {
          const Matint a(3, 4, 11);
          BOOST_CHECK(a.nrows() == 3 && a.ncols() == 4);
          for (Matint::size_type i = 0; i < a.nrows(); i++)
               for (Matint::size_type j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == 11);
     }
     {
          const int b[] = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5,
                           2, 3, 4, 5, 6, 3, 4, 5, 6, 7};
          const Matint a(4, 5, b);
          for (Matint::size_type i = 0; i < a.nrows(); i++)
               for (Matint::size_type j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == narrow_cast<int>(i + j));
     }
     {
          const std::size_t m = 4;
          const std::size_t n = 5;
          int** p = alloc_c_matrix<int>(m, n);
          for (std::size_t i = 0; i < m; i++)
               for (std::size_t j = 0; j < n; j++)
                    p[i][j] = i + j;
          Matint a(m, n, p);
          BOOST_CHECK(a.nrows() == m && a.ncols() == n);
          for (std::size_t i = 0; i < a.nrows(); i++)
               for (std::size_t j = 0; j < a.ncols(); j++)
                    BOOST_CHECK(a[i][j] == p[i][j]);
          free_c_matrix(p);
     }
     {
          const Vecint v(12, 13);
          const Matint a(3, 4, v);
          BOOST_CHECK(equal(v, Vecint(12, 13)) &&
                      equal(a, Matint(3, 4, 13)));
     }
     {
          const Vecint v(11, 13);
          BOOST_CHECK_THROW(Matint(3, 4, v), std::invalid_argument);
     }
     {
          Vecint v(12, 13);
          Matint a(3, 4, std::move(v));
          BOOST_CHECK(v.size() == 0 && equal(a, Matint(3, 4, 13)));
{'fraction_non_alphanumeric': 0.1842696629213483, 'fraction_numerical': 0.03460674157303371, 'mean_word_length': 1.7206601466992666, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6503284', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1670, 'n_words': 392}