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

Exhaustive tests for al-matrix.H (sparse matrix with generic domains) More...

#include <gtest/gtest.h>
#include <cmath>
#include <memory>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
#include <al-domain.H>
#include <al-vector.H>
#include <al-matrix.H>
Include dependency graph for al_matrix_test.cc:

Go to the source code of this file.

Functions

 TEST (MatrixConstruction, EmptyMatrixHasZeroEntries)
 
 TEST (MatrixConstruction, InitializerListConstructor)
 
 TEST (MatrixConstruction, InitializerListWithZerosNotStored)
 
 TEST (MatrixConstruction, InitializerListRowMismatchThrows)
 
 TEST (MatrixConstruction, InitializerListColMismatchThrows)
 
 TEST (MatrixEntries, SetAndGetEntry)
 
 TEST (MatrixEntries, SetEntryToZeroRemovesIt)
 
 TEST (MatrixEntries, SetEntryWithinEpsilonIsZero)
 
 TEST (MatrixEntries, OverwriteEntry)
 
 TEST (MatrixEpsilon, GetAndSetEpsilon)
 
 TEST (MatrixEpsilon, NegativeEpsilonThrows)
 
 TEST (MatrixTranspose, TransposeSwapsRowsAndCols)
 
 TEST (MatrixTranspose, DoubleTransposeIsIdentity)
 
 TEST (MatrixExtraction, GetRowAsList)
 
 TEST (MatrixExtraction, GetColAsList)
 
 TEST (MatrixExtraction, GetRowVector)
 
 TEST (MatrixExtraction, GetColVector)
 
 TEST (MatrixExtraction, InvalidRowThrows)
 
 TEST (MatrixExtraction, InvalidColThrows)
 
 TEST (MatrixVectorMult, MatrixTimesVector)
 
 TEST (MatrixVectorMult, VectorTimesMatrix)
 
 TEST (MatrixVectorMult, SparseMultiplication)
 
 TEST (MatrixVectorMult, DotProductMethod)
 
 TEST (MatrixVectorMult, DomainMismatchThrows)
 
 TEST (MatrixAddition, AddTwoMatrices)
 
 TEST (MatrixAddition, AddInPlace)
 
 TEST (MatrixAddition, AddSparseMatrices)
 
 TEST (MatrixScalar, MultiplyByScalar)
 
 TEST (MatrixScalar, ScalarTimesMatrix)
 
 TEST (MatrixIdentity, CreateIdentity)
 
 TEST (MatrixIdentity, IdentityTimesVectorIsVector)
 
 TEST (MatrixEquality, EqualMatrices)
 
 TEST (MatrixEquality, UnequalMatrices)
 
 TEST (MatrixEquality, EqualWithinEpsilon)
 
 TEST (MatrixFactory, CreateByRows)
 
 TEST (MatrixFactory, CreateByColumns)
 
 TEST (MatrixConversion, ToRowList)
 
 TEST (MatrixConversion, ToColList)
 
 TEST (MatrixSetVector, SetVectorAsRow)
 
 TEST (MatrixSetVector, SetVectorAsCol)
 
 TEST (MatrixOuterProduct, BasicOuterProduct)
 
 TEST (MatrixGenericDomain, StringDomainMatrix)
 
 TEST (MatrixGenericDomain, StringDomainTranspose)
 
 TEST (MatrixString, ToStrDoesNotCrash)
 
 TEST (MatrixDomain, GetRowAndColDomain)
 
 TEST (MatrixDomain, RowAndColDomainList)
 
 TEST (MatrixSubtraction, SubtractTwoMatrices)
 
 TEST (MatrixSubtraction, SubtractInPlace)
 
 TEST (MatrixSubtraction, SubtractSparseMatrices)
 
 TEST (MatrixSubtraction, SubtractFromItself)
 
 TEST (MatrixSubtraction, DomainMismatchThrows)
 
 TEST (MatrixCopyMove, CopyConstructor)
 
 TEST (MatrixCopyMove, CopyAssignment)
 
 TEST (MatrixCopyMove, SelfAssignment)
 
 TEST (MatrixCopyMove, MoveConstructor)
 
 TEST (MatrixCopyMove, MoveAssignment)
 
 TEST (MatrixCopyMove, CopyPreservesEpsilon)
 
 TEST (MatrixSharedPtr, ConstructWithSharedPtrDomains)
 
 TEST (MatrixSharedPtr, DomainOutlivesLocalScope)
 
 TEST (MatrixSharedPtr, CopiedMatrixSharesDomain)
 
 TEST (MatrixSharedPtr, VectorWithSharedPtrDomain)
 
 TEST (MatrixSharedPtr, MatrixVectorMultWithSharedDomains)
 
 TEST (MatrixMultDomainIdentity, SameDomainWorks)
 
 TEST (MatrixMultDomainIdentity, DifferentDomainsThrows)
 
 TEST (MatrixMultDomainIdentity, ChainedMultiplicationWithSharedDomain)
 
 TEST (MatrixTranspose, OfRowsAndColumnsOfDifferentTypes)
 
 TEST (MatrixMult, WithAnotherTypeOfColumns)
 
 TEST (MatrixMult, OfFloats)
 
 TEST (MatrixToStr, LabelsInTheOrderOfTheKeys)
 
 TEST (MatrixDomains, ResultsOutliveAMatrixThatOwnsItsDomains)
 
 TEST (MatrixDomains, KeepsTemporaryDomains)
 
 TEST (MatrixDomains, NeedsDomains)
 
 TEST (MatrixConstruction, ListOfListsRowLengthMismatchThrows)
 
 TEST (MatrixConstruction, ByRowsOrColumnsNeedsAVectorPerElement)
 

Detailed Description

Exhaustive tests for al-matrix.H (sparse matrix with generic domains)

Tests cover:

  • Construction (empty, initializer list, DynList)
  • Entry access and modification (get_entry, set_entry)
  • Sparse storage semantics (zero entries not stored)
  • Transpose
  • Row/column extraction (as list and as vector)
  • Matrix-vector and vector-matrix multiplication
  • Matrix addition and scalar multiplication
  • Identity matrix
  • Equality comparison
  • Static factory methods (create_by_rows, create_by_columns)
  • Outer product

Definition in file al_matrix_test.cc.

Function Documentation

◆ TEST() [1/74]

TEST ( MatrixAddition  ,
AddInPlace   
)

Definition at line 526 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [2/74]

TEST ( MatrixAddition  ,
AddSparseMatrices   
)

Definition at line 548 of file al_matrix_test.cc.

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

◆ TEST() [3/74]

TEST ( MatrixAddition  ,
AddTwoMatrices   
)

Definition at line 504 of file al_matrix_test.cc.

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

◆ TEST() [4/74]

TEST ( MatrixConstruction  ,
ByRowsOrColumnsNeedsAVectorPerElement   
)

Definition at line 1563 of file al_matrix_test.cc.

References Aleph::DynList< T >::append(), cols, m, and rows.

◆ TEST() [5/74]

TEST ( MatrixConstruction  ,
EmptyMatrixHasZeroEntries   
)

Definition at line 103 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, r, and rows.

◆ TEST() [6/74]

TEST ( MatrixConstruction  ,
InitializerListColMismatchThrows   
)

Definition at line 164 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [7/74]

TEST ( MatrixConstruction  ,
InitializerListConstructor   
)

Definition at line 116 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [8/74]

TEST ( MatrixConstruction  ,
InitializerListRowMismatchThrows   
)

Definition at line 151 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [9/74]

TEST ( MatrixConstruction  ,
InitializerListWithZerosNotStored   
)

Definition at line 134 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [10/74]

TEST ( MatrixConstruction  ,
ListOfListsRowLengthMismatchThrows   
)

Definition at line 1541 of file al_matrix_test.cc.

References Aleph::DynList< T >::append(), cols, and rows.

◆ TEST() [11/74]

TEST ( MatrixConversion  ,
ToColList   
)

◆ TEST() [12/74]

TEST ( MatrixConversion  ,
ToRowList   
)

◆ TEST() [13/74]

TEST ( MatrixCopyMove  ,
CopyAssignment   
)

Definition at line 1112 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [14/74]

TEST ( MatrixCopyMove  ,
CopyConstructor   
)

Definition at line 1092 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [15/74]

TEST ( MatrixCopyMove  ,
CopyPreservesEpsilon   
)

Definition at line 1184 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [16/74]

TEST ( MatrixCopyMove  ,
MoveAssignment   
)

Definition at line 1166 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [17/74]

TEST ( MatrixCopyMove  ,
MoveConstructor   
)

Definition at line 1149 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [18/74]

TEST ( MatrixCopyMove  ,
SelfAssignment   
)

Definition at line 1132 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [19/74]

TEST ( MatrixDomain  ,
GetRowAndColDomain   
)

Definition at line 955 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [20/74]

TEST ( MatrixDomain  ,
RowAndColDomainList   
)

◆ TEST() [21/74]

TEST ( MatrixDomains  ,
KeepsTemporaryDomains   
)

◆ TEST() [22/74]

TEST ( MatrixDomains  ,
NeedsDomains   
)

Definition at line 1529 of file al_matrix_test.cc.

◆ TEST() [23/74]

TEST ( MatrixDomains  ,
ResultsOutliveAMatrixThatOwnsItsDomains   
)

Definition at line 1460 of file al_matrix_test.cc.

References cols, m, Aleph::outer_product(), r, and rows.

◆ TEST() [24/74]

TEST ( MatrixEntries  ,
OverwriteEntry   
)

Definition at line 219 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [25/74]

TEST ( MatrixEntries  ,
SetAndGetEntry   
)

Definition at line 182 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [26/74]

TEST ( MatrixEntries  ,
SetEntryToZeroRemovesIt   
)

Definition at line 196 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [27/74]

TEST ( MatrixEntries  ,
SetEntryWithinEpsilonIsZero   
)

Definition at line 209 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [28/74]

TEST ( MatrixEpsilon  ,
GetAndSetEpsilon   
)

Definition at line 234 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [29/74]

TEST ( MatrixEpsilon  ,
NegativeEpsilonThrows   
)

Definition at line 246 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [30/74]

TEST ( MatrixEquality  ,
EqualMatrices   
)

Definition at line 644 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [31/74]

TEST ( MatrixEquality  ,
EqualWithinEpsilon   
)

Definition at line 680 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [32/74]

TEST ( MatrixEquality  ,
UnequalMatrices   
)

Definition at line 662 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [33/74]

TEST ( MatrixExtraction  ,
GetColAsList   
)

◆ TEST() [34/74]

TEST ( MatrixExtraction  ,
GetColVector   
)

Definition at line 355 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [35/74]

TEST ( MatrixExtraction  ,
GetRowAsList   
)

◆ TEST() [36/74]

TEST ( MatrixExtraction  ,
GetRowVector   
)

Definition at line 338 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [37/74]

TEST ( MatrixExtraction  ,
InvalidColThrows   
)

Definition at line 381 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [38/74]

TEST ( MatrixExtraction  ,
InvalidRowThrows   
)

Definition at line 371 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [39/74]

TEST ( MatrixFactory  ,
CreateByColumns   
)

Definition at line 726 of file al_matrix_test.cc.

References Aleph::DynList< T >::append(), cols, Aleph::Domain, m, and rows.

◆ TEST() [40/74]

TEST ( MatrixFactory  ,
CreateByRows   
)

Definition at line 697 of file al_matrix_test.cc.

References Aleph::DynList< T >::append(), cols, Aleph::Domain, m, and rows.

◆ TEST() [41/74]

TEST ( MatrixGenericDomain  ,
StringDomainMatrix   
)

Definition at line 886 of file al_matrix_test.cc.

References cols, m, and rows.

◆ TEST() [42/74]

TEST ( MatrixGenericDomain  ,
StringDomainTranspose   
)

Definition at line 910 of file al_matrix_test.cc.

References cols, m, and rows.

◆ TEST() [43/74]

TEST ( MatrixIdentity  ,
CreateIdentity   
)

Definition at line 610 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [44/74]

TEST ( MatrixIdentity  ,
IdentityTimesVectorIsVector   
)

Definition at line 622 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [45/74]

TEST ( MatrixMult  ,
OfFloats   
)

◆ TEST() [46/74]

TEST ( MatrixMult  ,
WithAnotherTypeOfColumns   
)

Definition at line 1389 of file al_matrix_test.cc.

References r, and rows.

◆ TEST() [47/74]

TEST ( MatrixMultDomainIdentity  ,
ChainedMultiplicationWithSharedDomain   
)

Definition at line 1313 of file al_matrix_test.cc.

References cols, and rows.

◆ TEST() [48/74]

TEST ( MatrixMultDomainIdentity  ,
DifferentDomainsThrows   
)

Definition at line 1300 of file al_matrix_test.cc.

◆ TEST() [49/74]

TEST ( MatrixMultDomainIdentity  ,
SameDomainWorks   
)

Definition at line 1283 of file al_matrix_test.cc.

◆ TEST() [50/74]

TEST ( MatrixOuterProduct  ,
BasicOuterProduct   
)

Definition at line 854 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [51/74]

TEST ( MatrixScalar  ,
MultiplyByScalar   
)

Definition at line 572 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [52/74]

TEST ( MatrixScalar  ,
ScalarTimesMatrix   
)

Definition at line 589 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [53/74]

TEST ( MatrixSetVector  ,
SetVectorAsCol   
)

Definition at line 829 of file al_matrix_test.cc.

References col, Aleph::Domain, and m.

◆ TEST() [54/74]

TEST ( MatrixSetVector  ,
SetVectorAsRow   
)

Definition at line 808 of file al_matrix_test.cc.

References Aleph::Domain, m, and row.

◆ TEST() [55/74]

TEST ( MatrixSharedPtr  ,
ConstructWithSharedPtrDomains   
)

Definition at line 1201 of file al_matrix_test.cc.

References cols, m, and rows.

◆ TEST() [56/74]

TEST ( MatrixSharedPtr  ,
CopiedMatrixSharesDomain   
)

Definition at line 1231 of file al_matrix_test.cc.

◆ TEST() [57/74]

TEST ( MatrixSharedPtr  ,
DomainOutlivesLocalScope   
)

Definition at line 1219 of file al_matrix_test.cc.

References m, and OhashCommon< HashTbl, Key >::size().

◆ TEST() [58/74]

TEST ( MatrixSharedPtr  ,
MatrixVectorMultWithSharedDomains   
)

Definition at line 1259 of file al_matrix_test.cc.

References m.

◆ TEST() [59/74]

TEST ( MatrixSharedPtr  ,
VectorWithSharedPtrDomain   
)

Definition at line 1244 of file al_matrix_test.cc.

◆ TEST() [60/74]

TEST ( MatrixString  ,
ToStrDoesNotCrash   
)

Definition at line 938 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [61/74]

TEST ( MatrixSubtraction  ,
DomainMismatchThrows   
)

Definition at line 1076 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [62/74]

TEST ( MatrixSubtraction  ,
SubtractFromItself   
)

Definition at line 1059 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [63/74]

TEST ( MatrixSubtraction  ,
SubtractInPlace   
)

Definition at line 1017 of file al_matrix_test.cc.

References Aleph::Domain.

◆ TEST() [64/74]

TEST ( MatrixSubtraction  ,
SubtractSparseMatrices   
)

Definition at line 1039 of file al_matrix_test.cc.

References Aleph::diff(), and Aleph::Domain.

◆ TEST() [65/74]

TEST ( MatrixSubtraction  ,
SubtractTwoMatrices   
)

Definition at line 995 of file al_matrix_test.cc.

References Aleph::diff(), and Aleph::Domain.

◆ TEST() [66/74]

TEST ( MatrixToStr  ,
LabelsInTheOrderOfTheKeys   
)

Definition at line 1436 of file al_matrix_test.cc.

References m.

◆ TEST() [67/74]

TEST ( MatrixTranspose  ,
DoubleTransposeIsIdentity   
)

Definition at line 280 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [68/74]

◆ TEST() [69/74]

TEST ( MatrixTranspose  ,
TransposeSwapsRowsAndCols   
)

Definition at line 259 of file al_matrix_test.cc.

References cols, Aleph::Domain, m, and rows.

◆ TEST() [70/74]

TEST ( MatrixVectorMult  ,
DomainMismatchThrows   
)

Definition at line 489 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [71/74]

TEST ( MatrixVectorMult  ,
DotProductMethod   
)

Definition at line 469 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [72/74]

TEST ( MatrixVectorMult  ,
MatrixTimesVector   
)

Definition at line 395 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [73/74]

TEST ( MatrixVectorMult  ,
SparseMultiplication   
)

Definition at line 447 of file al_matrix_test.cc.

References Aleph::Domain, and m.

◆ TEST() [74/74]

TEST ( MatrixVectorMult  ,
VectorTimesMatrix   
)

Definition at line 421 of file al_matrix_test.cc.

References Aleph::Domain, and m.