Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
dynmat_test.cc File Reference

Comprehensive test suite for DynMatrix<T> More...

#include <gtest/gtest.h>
#include <string>
#include <memory>
#include <vector>
#include <stdexcept>
#include <cmath>
#include <tpl_dynMat.H>
#include <ahFunctional.H>
Include dependency graph for dynmat_test.cc:

Go to the source code of this file.

Classes

struct  SmallIntMatrix
 Fixture with a small integer matrix. More...
 
struct  FilledMatrix
 Fixture with a pre-filled matrix. More...
 
struct  SquareMatrix
 Fixture with a square matrix. More...
 
struct  Counted
 Type that counts constructions/destructions. More...
 

Functions

 TEST (DynMatrix, default_constructor_creates_empty_matrix)
 
 TEST (DynMatrix, parametrized_constructor_creates_correct_dimensions)
 
 TEST (DynMatrix, parametrized_constructor_with_custom_default_value)
 
 TEST (DynMatrix, constructor_throws_on_zero_dimensions)
 
 TEST (DynMatrix, constructor_with_various_types)
 
 TEST_F (FilledMatrix, copy_constructor_creates_independent_copy)
 
 TEST (DynMatrix, copy_constructor_empty_matrix)
 
 TEST_F (SmallIntMatrix, copy_constructor_sparse_matrix)
 
 TEST_F (FilledMatrix, move_constructor_transfers_ownership)
 
 TEST (DynMatrix, move_constructor_empty_matrix)
 
 TEST (DynMatrix, move_constructor_is_noexcept)
 
 TEST_F (FilledMatrix, copy_assignment_replaces_contents)
 
 TEST_F (FilledMatrix, copy_assignment_self_assignment_is_safe)
 
 TEST (DynMatrix, copy_assignment_different_dimensions)
 
 TEST_F (FilledMatrix, move_assignment_transfers_ownership)
 
 TEST (DynMatrix, move_assignment_is_noexcept)
 
 TEST (DynMatrix, swap_exchanges_contents)
 
 TEST (DynMatrix, swap_with_empty_matrix)
 
 TEST (DynMatrix, swap_is_noexcept)
 
 TEST_F (SmallIntMatrix, rows_returns_correct_value)
 
 TEST_F (SmallIntMatrix, cols_returns_correct_value)
 
 TEST_F (SmallIntMatrix, size_returns_product_of_dimensions)
 
 TEST (DynMatrix, is_square_true_for_square_matrix)
 
 TEST (DynMatrix, is_square_false_for_non_square_matrix)
 
 TEST (DynMatrix, is_empty_true_for_default_constructed)
 
 TEST_F (SmallIntMatrix, is_empty_false_for_initialized_matrix)
 
 TEST_F (SmallIntMatrix, write_and_read_single_entry)
 
 TEST_F (SmallIntMatrix, read_unwritten_entry_returns_default)
 
 TEST_F (SmallIntMatrix, write_returns_reference_to_entry)
 
 TEST_F (SmallIntMatrix, read_throws_on_out_of_bounds)
 
 TEST_F (SmallIntMatrix, write_throws_on_out_of_bounds)
 
 TEST_F (SmallIntMatrix, read_ne_no_bounds_check)
 
 TEST (DynMatrix, write_with_move_semantics)
 
 TEST_F (SmallIntMatrix, access_after_allocate)
 
 TEST_F (SmallIntMatrix, access_const_version)
 
 TEST_F (FilledMatrix, operator_parens_read_write)
 
 TEST_F (SmallIntMatrix, fill_sets_all_entries)
 
 TEST (DynMatrix, fill_overwrites_existing_values)
 
 TEST_F (FilledMatrix, transpose_swaps_dimensions)
 
 TEST_F (FilledMatrix, transpose_swaps_values)
 
 TEST_F (SquareMatrix, transpose_diagonal_unchanged)
 
 TEST (DynMatrix, transpose_sparse_matrix)
 
 TEST_F (FilledMatrix, set_dimension_clears_data)
 
 TEST_F (SmallIntMatrix, set_dimension_preserves_default_value)
 
 TEST_F (SmallIntMatrix, set_default_initial_value)
 
 TEST (DynMatrix, default_value_affects_unwritten_reads)
 
 TEST (DynMatrix, changing_default_affects_future_reads)
 
 TEST (DynMatrix, equality_same_matrices)
 
 TEST (DynMatrix, equality_different_dimensions)
 
 TEST (DynMatrix, equality_different_values)
 
 TEST_F (FilledMatrix, equality_with_copy)
 
 TEST_F (SmallIntMatrix, iterator_basic_traversal)
 
 TEST_F (FilledMatrix, iterator_visits_in_row_major_order)
 
 TEST_F (SmallIntMatrix, iterator_get_curr_throws_when_exhausted)
 
 TEST_F (SmallIntMatrix, iterator_next_throws_when_exhausted)
 
 TEST_F (SmallIntMatrix, iterator_reset)
 
 TEST_F (FilledMatrix, traverse_visits_all_elements)
 
 TEST_F (FilledMatrix, traverse_can_stop_early)
 
 TEST_F (SmallIntMatrix, traverse_on_sparse_matrix)
 
 TEST_F (SmallIntMatrix, traverse_allocated_visits_allocated_blocks)
 
 TEST_F (FilledMatrix, for_each_visits_all)
 
 TEST_F (FilledMatrix, all_returns_true_when_all_match)
 
 TEST_F (FilledMatrix, all_returns_false_when_any_fails)
 
 TEST_F (FilledMatrix, exists_returns_true_when_found)
 
 TEST_F (FilledMatrix, exists_returns_false_when_not_found)
 
 TEST_F (FilledMatrix, foldl_accumulates)
 
 TEST (DynMatrix, type_aliases_are_correct)
 
 TEST (DynMatrix, destructor_frees_all_memory)
 
 TEST (DynMatrix, allocate_reserves_all_entries)
 
 TEST (DynMatrix, single_element_matrix)
 
 TEST (DynMatrix, single_row_matrix)
 
 TEST (DynMatrix, single_column_matrix)
 
 TEST (DynMatrix, very_sparse_matrix)
 
 TEST (DynMatrix, stress_large_matrix)
 
 TEST (DynMatrix, stress_copy_large_matrix)
 
 TEST (DynMatrix, floating_point_matrix)
 
 TEST (DynMatrix, string_matrix)
 
 TEST (DynMatrix, regression_equality_different_shaped_same_size)
 
 TEST (DynMatrix, regression_move_assignment_returns_reference)
 
int main (int argc, char **argv)
 

Variables

constexpr size_t SMALL_N = 3
 
constexpr size_t SMALL_M = 4
 
constexpr size_t MEDIUM_N = 10
 
constexpr size_t MEDIUM_M = 15
 
constexpr size_t LARGE_N = 100
 

Detailed Description

Comprehensive test suite for DynMatrix<T>

This test file provides exhaustive coverage of DynMatrix functionality:

  • Basic operations (read, write, access)
  • Constructors (default, parametrized, copy, move)
  • Assignment operators (copy, move)
  • Dimension queries (rows, cols, size, is_square, is_empty)
  • Iterator functionality
  • Functional methods (traverse, maps, filter, foldl, etc.)
  • Sparse storage behavior
  • Edge cases and boundary conditions

Definition in file dynmat_test.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1058 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [1/37]

TEST ( DynMatrix  ,
allocate_reserves_all_entries   
)

Definition at line 895 of file dynmat_test.cc.

References Aleph::DynMatrix< T >::allocate(), and Aleph::maps().

◆ TEST() [2/37]

TEST ( DynMatrix  ,
changing_default_affects_future_reads   
)

◆ TEST() [3/37]

TEST ( DynMatrix  ,
constructor_throws_on_zero_dimensions   
)

Definition at line 190 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [4/37]

TEST ( DynMatrix  ,
constructor_with_various_types   
)

Definition at line 197 of file dynmat_test.cc.

References Aleph::DynList< T >::empty(), and Aleph::maps().

◆ TEST() [5/37]

TEST ( DynMatrix  ,
copy_assignment_different_dimensions   
)

Definition at line 306 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [6/37]

TEST ( DynMatrix  ,
copy_constructor_empty_matrix   
)

Definition at line 230 of file dynmat_test.cc.

References Aleph::copy(), and Aleph::maps().

◆ TEST() [7/37]

TEST ( DynMatrix  ,
default_constructor_creates_empty_matrix   
)

◆ TEST() [8/37]

TEST ( DynMatrix  ,
default_value_affects_unwritten_reads   
)

Definition at line 609 of file dynmat_test.cc.

References Aleph::maps(), and Aleph::DynMatrix< T >::read().

◆ TEST() [9/37]

◆ TEST() [10/37]

TEST ( DynMatrix  ,
equality_different_dimensions   
)

Definition at line 642 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [11/37]

TEST ( DynMatrix  ,
equality_different_values   
)

Definition at line 651 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [12/37]

TEST ( DynMatrix  ,
equality_same_matrices   
)

Definition at line 633 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [13/37]

TEST ( DynMatrix  ,
fill_overwrites_existing_values   
)

◆ TEST() [14/37]

TEST ( DynMatrix  ,
floating_point_matrix   
)

◆ TEST() [15/37]

TEST ( DynMatrix  ,
is_empty_true_for_default_constructed   
)

Definition at line 409 of file dynmat_test.cc.

References Aleph::DynMatrix< T >::is_empty(), and Aleph::maps().

◆ TEST() [16/37]

TEST ( DynMatrix  ,
is_square_false_for_non_square_matrix   
)

Definition at line 403 of file dynmat_test.cc.

References Aleph::DynMatrix< T >::is_square(), and Aleph::maps().

◆ TEST() [17/37]

TEST ( DynMatrix  ,
is_square_true_for_square_matrix   
)

Definition at line 397 of file dynmat_test.cc.

References Aleph::DynMatrix< T >::is_square(), and Aleph::maps().

◆ TEST() [18/37]

TEST ( DynMatrix  ,
move_assignment_is_noexcept   
)

Definition at line 333 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [19/37]

TEST ( DynMatrix  ,
move_constructor_empty_matrix   
)

Definition at line 269 of file dynmat_test.cc.

References Aleph::HTList::is_empty(), and Aleph::maps().

◆ TEST() [20/37]

TEST ( DynMatrix  ,
move_constructor_is_noexcept   
)

Definition at line 277 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [21/37]

TEST ( DynMatrix  ,
parametrized_constructor_creates_correct_dimensions   
)

◆ TEST() [22/37]

TEST ( DynMatrix  ,
parametrized_constructor_with_custom_default_value   
)

◆ TEST() [23/37]

TEST ( DynMatrix  ,
regression_equality_different_shaped_same_size   
)

Definition at line 1035 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [24/37]

TEST ( DynMatrix  ,
regression_move_assignment_returns_reference   
)

Definition at line 1044 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST() [25/37]

◆ TEST() [26/37]

◆ TEST() [27/37]

◆ TEST() [28/37]

TEST ( DynMatrix  ,
stress_copy_large_matrix   
)

Definition at line 986 of file dynmat_test.cc.

References Aleph::copy(), LARGE_N, and Aleph::maps().

◆ TEST() [29/37]

TEST ( DynMatrix  ,
stress_large_matrix   
)

◆ TEST() [30/37]

TEST ( DynMatrix  ,
string_matrix   
)

◆ TEST() [31/37]

TEST ( DynMatrix  ,
swap_exchanges_contents   
)

Definition at line 342 of file dynmat_test.cc.

References Aleph::maps(), and Aleph::DynList< T >::swap().

◆ TEST() [32/37]

TEST ( DynMatrix  ,
swap_is_noexcept   
)

Definition at line 372 of file dynmat_test.cc.

References Aleph::maps(), and Aleph::DynList< T >::swap().

◆ TEST() [33/37]

TEST ( DynMatrix  ,
swap_with_empty_matrix   
)

◆ TEST() [34/37]

TEST ( DynMatrix  ,
transpose_sparse_matrix   
)

◆ TEST() [35/37]

TEST ( DynMatrix  ,
type_aliases_are_correct   
)

Definition at line 866 of file dynmat_test.cc.

◆ TEST() [36/37]

TEST ( DynMatrix  ,
very_sparse_matrix   
)

◆ TEST() [37/37]

TEST ( DynMatrix  ,
write_with_move_semantics   
)

◆ TEST_F() [1/42]

TEST_F ( FilledMatrix  ,
all_returns_false_when_any_fails   
)

Definition at line 835 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [2/42]

TEST_F ( FilledMatrix  ,
all_returns_true_when_all_match   
)

Definition at line 828 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [3/42]

TEST_F ( FilledMatrix  ,
copy_assignment_replaces_contents   
)

Definition at line 286 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [4/42]

TEST_F ( FilledMatrix  ,
copy_assignment_self_assignment_is_safe   
)

Definition at line 298 of file dynmat_test.cc.

References Aleph::maps(), and SMALL_N.

◆ TEST_F() [5/42]

TEST_F ( FilledMatrix  ,
copy_constructor_creates_independent_copy   
)

Definition at line 214 of file dynmat_test.cc.

References Aleph::copy(), Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [6/42]

TEST_F ( FilledMatrix  ,
equality_with_copy   
)

Definition at line 662 of file dynmat_test.cc.

References Aleph::copy(), and Aleph::maps().

◆ TEST_F() [7/42]

TEST_F ( FilledMatrix  ,
exists_returns_false_when_not_found   
)

Definition at line 848 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [8/42]

TEST_F ( FilledMatrix  ,
exists_returns_true_when_found   
)

Definition at line 842 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [9/42]

TEST_F ( FilledMatrix  ,
foldl_accumulates   
)

Definition at line 854 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, SMALL_N, and Aleph::sum().

◆ TEST_F() [10/42]

TEST_F ( FilledMatrix  ,
for_each_visits_all   
)

Definition at line 819 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, SMALL_N, and Aleph::sum().

◆ TEST_F() [11/42]

TEST_F ( FilledMatrix  ,
iterator_visits_in_row_major_order   
)

Definition at line 690 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [12/42]

TEST_F ( FilledMatrix  ,
move_assignment_transfers_ownership   
)

Definition at line 322 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [13/42]

TEST_F ( FilledMatrix  ,
move_constructor_transfers_ownership   
)

Definition at line 255 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [14/42]

TEST_F ( FilledMatrix  ,
operator_parens_read_write   
)

Definition at line 499 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [15/42]

TEST_F ( FilledMatrix  ,
set_dimension_clears_data   
)

Definition at line 580 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [16/42]

TEST_F ( FilledMatrix  ,
transpose_swaps_dimensions   
)

Definition at line 538 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [17/42]

TEST_F ( FilledMatrix  ,
transpose_swaps_values   
)

Definition at line 546 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [18/42]

TEST_F ( FilledMatrix  ,
traverse_can_stop_early   
)

Definition at line 763 of file dynmat_test.cc.

References Aleph::count(), and Aleph::maps().

◆ TEST_F() [19/42]

TEST_F ( FilledMatrix  ,
traverse_visits_all_elements   
)

Definition at line 744 of file dynmat_test.cc.

References Aleph::count(), Aleph::maps(), SMALL_M, SMALL_N, and Aleph::sum().

◆ TEST_F() [20/42]

TEST_F ( SmallIntMatrix  ,
access_after_allocate   
)

Definition at line 481 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [21/42]

TEST_F ( SmallIntMatrix  ,
access_const_version   
)

Definition at line 490 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [22/42]

TEST_F ( SmallIntMatrix  ,
cols_returns_correct_value   
)

Definition at line 387 of file dynmat_test.cc.

References Aleph::maps(), and SMALL_M.

◆ TEST_F() [23/42]

TEST_F ( SmallIntMatrix  ,
copy_constructor_sparse_matrix   
)

Definition at line 238 of file dynmat_test.cc.

References Aleph::copy(), and Aleph::maps().

◆ TEST_F() [24/42]

TEST_F ( SmallIntMatrix  ,
fill_sets_all_entries   
)

Definition at line 514 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [25/42]

TEST_F ( SmallIntMatrix  ,
is_empty_false_for_initialized_matrix   
)

Definition at line 415 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [26/42]

TEST_F ( SmallIntMatrix  ,
iterator_basic_traversal   
)

Definition at line 673 of file dynmat_test.cc.

References Aleph::count(), and Aleph::maps().

◆ TEST_F() [27/42]

TEST_F ( SmallIntMatrix  ,
iterator_get_curr_throws_when_exhausted   
)

Definition at line 707 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [28/42]

TEST_F ( SmallIntMatrix  ,
iterator_next_throws_when_exhausted   
)

Definition at line 718 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [29/42]

TEST_F ( SmallIntMatrix  ,
iterator_reset   
)

Definition at line 728 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [30/42]

TEST_F ( SmallIntMatrix  ,
read_ne_no_bounds_check   
)

Definition at line 459 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [31/42]

TEST_F ( SmallIntMatrix  ,
read_throws_on_out_of_bounds   
)

Definition at line 446 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [32/42]

TEST_F ( SmallIntMatrix  ,
read_unwritten_entry_returns_default   
)

Definition at line 431 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [33/42]

TEST_F ( SmallIntMatrix  ,
rows_returns_correct_value   
)

Definition at line 382 of file dynmat_test.cc.

References Aleph::maps(), and SMALL_N.

◆ TEST_F() [34/42]

TEST_F ( SmallIntMatrix  ,
set_default_initial_value   
)

Definition at line 602 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [35/42]

TEST_F ( SmallIntMatrix  ,
set_dimension_preserves_default_value   
)

Definition at line 590 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [36/42]

TEST_F ( SmallIntMatrix  ,
size_returns_product_of_dimensions   
)

Definition at line 392 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [37/42]

TEST_F ( SmallIntMatrix  ,
traverse_allocated_visits_allocated_blocks   
)

Definition at line 792 of file dynmat_test.cc.

References Aleph::count(), Aleph::maps(), and Aleph::sum().

◆ TEST_F() [38/42]

TEST_F ( SmallIntMatrix  ,
traverse_on_sparse_matrix   
)

Definition at line 777 of file dynmat_test.cc.

References Aleph::maps(), and Aleph::sum().

◆ TEST_F() [39/42]

TEST_F ( SmallIntMatrix  ,
write_and_read_single_entry   
)

Definition at line 424 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [40/42]

TEST_F ( SmallIntMatrix  ,
write_returns_reference_to_entry   
)

Definition at line 437 of file dynmat_test.cc.

References Aleph::maps().

◆ TEST_F() [41/42]

TEST_F ( SmallIntMatrix  ,
write_throws_on_out_of_bounds   
)

Definition at line 453 of file dynmat_test.cc.

References Aleph::maps(), SMALL_M, and SMALL_N.

◆ TEST_F() [42/42]

TEST_F ( SquareMatrix  ,
transpose_diagonal_unchanged   
)

Definition at line 555 of file dynmat_test.cc.

References Aleph::maps().

Variable Documentation

◆ LARGE_N

constexpr size_t LARGE_N = 100
constexpr

Definition at line 71 of file dynmat_test.cc.

Referenced by TEST(), and TEST().

◆ MEDIUM_M

constexpr size_t MEDIUM_M = 15
constexpr

Definition at line 70 of file dynmat_test.cc.

◆ MEDIUM_N

constexpr size_t MEDIUM_N = 10
constexpr

Definition at line 69 of file dynmat_test.cc.

◆ SMALL_M

constexpr size_t SMALL_M = 4
constexpr

◆ SMALL_N

constexpr size_t SMALL_N = 3
constexpr