Browse Source

Fixed wrong namespace for bit vector and square sparse matrix classes.

tempestpy_adaptions
dehnert 12 years ago
parent
commit
8911b0b71a
  1. 16
      src/modelChecker/DtmcPrctlModelChecker.h
  2. 5
      src/models/atomic_propositions_labeling.h
  3. 6
      src/models/backward_transitions.h
  4. 6
      src/models/dtmc.h
  5. 2
      src/models/single_atomic_proposition_labeling.h
  6. 2
      src/mrmc.cpp
  7. 6
      src/parser/read_tra_file.cpp
  8. 2
      src/parser/read_tra_file.h
  9. 91
      src/storage/BitVector.h
  10. 2
      src/storage/SquareSparseMatrix.h
  11. 2
      test/parser/read_tra_file_test.cpp
  12. 36
      test/storage/BitVectorTest.cpp
  13. 82
      test/storage/SquareSparseMatrixTest.cpp

16
src/modelChecker/DtmcPrctlModelChecker.h

@ -39,11 +39,11 @@ class DtmcPrctlModelChecker {
explicit DtmcPrctlModelChecker(mrmc::models::Dtmc<T>* DTMC); explicit DtmcPrctlModelChecker(mrmc::models::Dtmc<T>* DTMC);
~DtmcPrctlModelChecker(); ~DtmcPrctlModelChecker();
virtual void makeAbsorbing(mrmc::vector::BitVector*) = 0;
virtual mrmc::vector::BitVector getStatesSatisying(mrmc::models::SingleAtomicPropositionLabeling*) = 0;
virtual void makeAbsorbing(mrmc::storage::BitVector*) = 0;
virtual mrmc::storage::BitVector getStatesSatisying(mrmc::models::SingleAtomicPropositionLabeling*) = 0;
virtual std::vector<T> multiplyMatrixVector(std::vector<T>*) = 0; virtual std::vector<T> multiplyMatrixVector(std::vector<T>*) = 0;
virtual mrmc::vector::BitVector checkStateFormula(mrmc::formula::PCTLStateFormula* formula) {
virtual mrmc::storage::BitVector checkStateFormula(mrmc::formula::PCTLStateFormula* formula) {
if (formula->type() == AND) { if (formula->type() == AND) {
return checkAnd(static_cast<mrmc::formula::And*>(formula)); return checkAnd(static_cast<mrmc::formula::And*>(formula));
} }
@ -63,11 +63,11 @@ class DtmcPrctlModelChecker {
} }
virtual mrmc::vector::BitVector checkAnd(mrmc::formula::And*) = 0;
virtual mrmc::vector::BitVector checkAP(mrmc::formula::AP*) = 0;
virtual mrmc::vector::BitVector checkNot(mrmc::formula::Not*) = 0;
virtual mrmc::vector::BitVector checkOr(mrmc::formula::Or*) = 0;
virtual mrmc::vector::BitVector checkProbabilisticOperator(mrmc::formula::ProbabilisticOperator<T>*) = 0;
virtual mrmc::storage::BitVector checkAnd(mrmc::formula::And*) = 0;
virtual mrmc::storage::BitVector checkAP(mrmc::formula::AP*) = 0;
virtual mrmc::storage::BitVector checkNot(mrmc::formula::Not*) = 0;
virtual mrmc::storage::BitVector checkOr(mrmc::formula::Or*) = 0;
virtual mrmc::storage::BitVector checkProbabilisticOperator(mrmc::formula::ProbabilisticOperator<T>*) = 0;
virtual std::vector<T> checkPathFormula(mrmc::formula::PCTLPathFormula* formula) { virtual std::vector<T> checkPathFormula(mrmc::formula::PCTLPathFormula* formula) {
if (formula->type() == NEXT) { if (formula->type() == NEXT) {

5
src/models/atomic_propositions_labeling.h

@ -10,7 +10,7 @@
#include <ostream> #include <ostream>
#include "single_atomic_proposition_labeling.h"
#include "src/models/single_atomic_proposition_labeling.h"
/* Map types: By default, the boost hash map is used. /* Map types: By default, the boost hash map is used.
* If the macro USE_STD_MAP is defined, the default C++ class (std::map) * If the macro USE_STD_MAP is defined, the default C++ class (std::map)
@ -140,8 +140,7 @@ public:
* @return True if the node is labeled with the atomic proposition, false * @return True if the node is labeled with the atomic proposition, false
* otherwise. * otherwise.
*/ */
bool stateHasAtomicProposition(std::string ap,
const uint_fast32_t state) {
bool stateHasAtomicProposition(std::string ap, const uint_fast32_t state) {
return this->single_labelings[name_to_labeling_map[ap]]->hasLabel(state); return this->single_labelings[name_to_labeling_map[ap]]->hasLabel(state);
} }

6
src/models/backward_transitions.h

@ -35,11 +35,9 @@ public:
* @param transition_matrix The (0-based) matrix representing the transition * @param transition_matrix The (0-based) matrix representing the transition
* relation. * relation.
*/ */
BackwardTransitions(mrmc::sparse::SquareSparseMatrix<T>* transitionMatrix) {
numberOfNonZeroTransitions = transitionMatrix->getNonZeroEntryCount();
BackwardTransitions(mrmc::storage::SquareSparseMatrix<T>* transitionMatrix)
: numberOfStates(transitionMatrix->getRowCount()), numberOfNonZeroTransitions(transitionMatrix->getNonZeroEntryCount()) {
this->predecessor_list = new uint_fast64_t[numberOfNonZeroTransitions]; this->predecessor_list = new uint_fast64_t[numberOfNonZeroTransitions];
numberOfStates = transitionMatrix->getRowCount();
this->state_indices_list = new uint_fast64_t[numberOfStates + 1]; this->state_indices_list = new uint_fast64_t[numberOfStates + 1];
// First, we need to count how many backward transitions each state has. // First, we need to count how many backward transitions each state has.

6
src/models/dtmc.h

@ -35,7 +35,7 @@ public:
* @param state_labeling The labeling that assigns a set of atomic * @param state_labeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Dtmc(mrmc::sparse::SquareSparseMatrix<T>* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling)
Dtmc(mrmc::storage::SquareSparseMatrix<T>* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling)
: backward_transitions(probability_matrix) { : backward_transitions(probability_matrix) {
this->probability_matrix = probability_matrix; this->probability_matrix = probability_matrix;
this->state_labeling = state_labeling; this->state_labeling = state_labeling;
@ -84,7 +84,7 @@ public:
* @return A pointer to the matrix representing the transition probability * @return A pointer to the matrix representing the transition probability
* function. * function.
*/ */
mrmc::sparse::SquareSparseMatrix<T>* getTransitionProbabilityMatrix() {
mrmc::storage::SquareSparseMatrix<T>* getTransitionProbabilityMatrix() {
return this->probability_matrix; return this->probability_matrix;
} }
@ -111,7 +111,7 @@ public:
private: private:
/*! A matrix representing the transition probability function of the DTMC. */ /*! A matrix representing the transition probability function of the DTMC. */
mrmc::sparse::SquareSparseMatrix<T>* probability_matrix;
mrmc::storage::SquareSparseMatrix<T>* probability_matrix;
/*! The labeling of the states of the DTMC. */ /*! The labeling of the states of the DTMC. */
mrmc::models::AtomicPropositionsLabeling* state_labeling; mrmc::models::AtomicPropositionsLabeling* state_labeling;

2
src/models/single_atomic_proposition_labeling.h

@ -75,7 +75,7 @@ class SingleAtomicPropositionLabeling {
* A bit vector storing for every state whether or not that state is * A bit vector storing for every state whether or not that state is
* labeled. * labeled.
*/ */
mrmc::vector::BitVector label_vector;
mrmc::storage::BitVector label_vector;
}; };
} // namespace models } // namespace models

2
src/mrmc.cpp

@ -77,7 +77,7 @@ int main(const int argc, const char* argv[]) {
return 0; return 0;
} }
mrmc::sparse::SquareSparseMatrix<double>* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str());
mrmc::storage::SquareSparseMatrix<double>* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str());
mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s->getString("labfile").c_str()); mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s->getString("labfile").c_str());
mrmc::models::Dtmc<double> dtmc(probMatrix, labeling); mrmc::models::Dtmc<double> dtmc(probMatrix, labeling);

6
src/parser/read_tra_file.cpp

@ -90,12 +90,12 @@ static uint_fast32_t make_first_pass(FILE* p) {
* @return a pointer to the created sparse matrix. * @return a pointer to the created sparse matrix.
*/ */
sparse::SquareSparseMatrix<double> * read_tra_file(const char * filename) {
storage::SquareSparseMatrix<double> * read_tra_file(const char * filename) {
FILE *p = NULL; FILE *p = NULL;
char s[BUFFER_SIZE]; char s[BUFFER_SIZE];
uint_fast64_t non_zero = 0; uint_fast64_t non_zero = 0;
int rows = 0; int rows = 0;
sparse::SquareSparseMatrix<double> *sp = NULL;
storage::SquareSparseMatrix<double> *sp = NULL;
p = fopen(filename, "r"); p = fopen(filename, "r");
if(p == NULL) { if(p == NULL) {
@ -129,7 +129,7 @@ sparse::SquareSparseMatrix<double> * read_tra_file(const char * filename) {
* Memory for diagonal elements is automatically allocated, hence only the number of non-diagonal * Memory for diagonal elements is automatically allocated, hence only the number of non-diagonal
* non-zero elements has to be specified (which is non_zero, computed by make_first_pass) * non-zero elements has to be specified (which is non_zero, computed by make_first_pass)
*/ */
sp = new sparse::SquareSparseMatrix<double>(static_cast<uint_fast64_t>(rows) + 1);
sp = new storage::SquareSparseMatrix<double>(static_cast<uint_fast64_t>(rows) + 1);
if ( NULL == sp ) { if ( NULL == sp ) {
throw std::bad_alloc(); throw std::bad_alloc();
return NULL; return NULL;

2
src/parser/read_tra_file.h

@ -11,7 +11,7 @@
namespace mrmc{ namespace mrmc{
namespace parser { namespace parser {
mrmc::sparse::SquareSparseMatrix<double> * read_tra_file(const char * filename);
mrmc::storage::SquareSparseMatrix<double> * read_tra_file(const char * filename);
} }
} }

91
src/storage/BitVector.h

@ -18,7 +18,7 @@ extern log4cplus::Logger logger;
namespace mrmc { namespace mrmc {
namespace vector {
namespace storage {
/*! /*!
* A bit vector that is internally represented by an array of 64-bit values. * A bit vector that is internally represented by an array of 64-bit values.
@ -27,6 +27,7 @@ class BitVector {
public: public:
class constIndexIterator { class constIndexIterator {
public:
constIndexIterator(uint_fast64_t* bucketPtr, uint_fast64_t* endBucketPtr) : bucketPtr(bucketPtr), endBucketPtr(endBucketPtr), offset(0), currentBitInByte(0) { } constIndexIterator(uint_fast64_t* bucketPtr, uint_fast64_t* endBucketPtr) : bucketPtr(bucketPtr), endBucketPtr(endBucketPtr), offset(0), currentBitInByte(0) { }
constIndexIterator& operator++() { constIndexIterator& operator++() {
do { do {
@ -63,15 +64,15 @@ public:
} }
// Compute the correct number of buckets needed to store the given number of bits // Compute the correct number of buckets needed to store the given number of bits
bucket_count = initialLength >> 6;
bucketCount = initialLength >> 6;
if ((initialLength & mod64mask) != 0) { if ((initialLength & mod64mask) != 0) {
++bucket_count;
++bucketCount;
} }
// Finally, create the full bucket array. This should initialize the array // Finally, create the full bucket array. This should initialize the array
// with 0s (notice the parentheses at the end) for standard conforming // with 0s (notice the parentheses at the end) for standard conforming
// compilers. // compilers.
bucket_array = new uint_fast64_t[bucket_count]();
bucketArray = new uint_fast64_t[bucketCount]();
} }
//! Copy Constructor //! Copy Constructor
@ -79,10 +80,10 @@ public:
* Copy Constructor. Performs a deep copy of the given bit vector. * Copy Constructor. Performs a deep copy of the given bit vector.
* @param bv A reference to the bit vector to be copied. * @param bv A reference to the bit vector to be copied.
*/ */
BitVector(const BitVector &bv) : bucket_count(bv.bucket_count) {
BitVector(const BitVector &bv) : bucketCount(bv.bucketCount) {
LOG4CPLUS_WARN(logger, "Invoking copy constructor."); LOG4CPLUS_WARN(logger, "Invoking copy constructor.");
bucket_array = new uint_fast64_t[bucket_count];
memcpy(bucket_array, bv.bucket_array, sizeof(uint_fast64_t) * bucket_count);
bucketArray = new uint_fast64_t[bucketCount];
memcpy(bucketArray, bv.bucketArray, sizeof(uint_fast64_t) * bucketCount);
} }
//! Destructor //! Destructor
@ -90,8 +91,8 @@ public:
* Destructor. Frees the underlying bucket array. * Destructor. Frees the underlying bucket array.
*/ */
~BitVector() { ~BitVector() {
if (bucket_array != nullptr) {
delete[] bucket_array;
if (bucketArray != nullptr) {
delete[] bucketArray;
} }
} }
@ -102,24 +103,24 @@ public:
void resize(uint_fast64_t newLength) { void resize(uint_fast64_t newLength) {
uint_fast64_t newBucketCount = newLength >> 6; uint_fast64_t newBucketCount = newLength >> 6;
if ((newLength & mod64mask) != 0) { if ((newLength & mod64mask) != 0) {
++bucket_count;
++bucketCount;
} }
// Reserve a temporary array for copying. // Reserve a temporary array for copying.
uint_fast64_t* tempArray = new uint_fast64_t[newBucketCount]; uint_fast64_t* tempArray = new uint_fast64_t[newBucketCount];
// Copy over the elements from the old bit vector. // Copy over the elements from the old bit vector.
uint_fast64_t copySize = (newBucketCount <= bucket_count) ? newBucketCount : bucket_count;
memcpy(tempArray, bucket_array, sizeof(uint_fast64_t) * copySize);
uint_fast64_t copySize = (newBucketCount <= bucketCount) ? newBucketCount : bucketCount;
memcpy(tempArray, bucketArray, sizeof(uint_fast64_t) * copySize);
// Initialize missing values in the new bit vector. // Initialize missing values in the new bit vector.
for (uint_fast64_t i = copySize; i < bucket_count; ++i) {
bucket_array[i] = 0;
for (uint_fast64_t i = copySize; i < bucketCount; ++i) {
bucketArray[i] = 0;
} }
// Dispose of the old bit vector and set the new one. // Dispose of the old bit vector and set the new one.
delete[] bucket_array;
bucket_array = tempArray;
delete[] bucketArray;
bucketArray = tempArray;
} }
/*! /*!
@ -131,9 +132,9 @@ public:
uint_fast64_t bucket = index >> 6; uint_fast64_t bucket = index >> 6;
uint_fast64_t mask = static_cast<uint_fast64_t>(1) << (index & mod64mask); uint_fast64_t mask = static_cast<uint_fast64_t>(1) << (index & mod64mask);
if (value) { if (value) {
bucket_array[bucket] |= mask;
bucketArray[bucket] |= mask;
} else { } else {
bucket_array[bucket] &= ~mask;
bucketArray[bucket] &= ~mask;
} }
} }
@ -144,7 +145,7 @@ public:
bool get(const uint_fast64_t index) { bool get(const uint_fast64_t index) {
uint_fast64_t bucket = index >> 6; uint_fast64_t bucket = index >> 6;
uint_fast64_t mask = static_cast<uint_fast64_t>(1) << (index & mod64mask); uint_fast64_t mask = static_cast<uint_fast64_t>(1) << (index & mod64mask);
return ((bucket_array[bucket] & mask) == mask);
return ((bucketArray[bucket] & mask) == mask);
} }
/*! /*!
@ -155,12 +156,12 @@ public:
* @return A bit vector corresponding to the logical "and" of the two bit vectors. * @return A bit vector corresponding to the logical "and" of the two bit vectors.
*/ */
BitVector operator &(BitVector const &bv) { BitVector operator &(BitVector const &bv) {
uint_fast64_t minSize = (bv.bucket_count < this->bucket_count) ? bv.bucket_count : this->bucket_count;
uint_fast64_t minSize = (bv.bucketCount < this->bucketCount) ? bv.bucketCount : this->bucketCount;
// Create resulting bit vector and perform the operation on the individual elements. // Create resulting bit vector and perform the operation on the individual elements.
BitVector result(minSize << 6); BitVector result(minSize << 6);
for (uint_fast64_t i = 0; i < minSize; ++i) { for (uint_fast64_t i = 0; i < minSize; ++i) {
result.bucket_array[i] = this->bucket_array[i] & bv.bucket_array[i];
result.bucketArray[i] = this->bucketArray[i] & bv.bucketArray[i];
} }
return result; return result;
@ -174,12 +175,12 @@ public:
* @return A bit vector corresponding to the logical "or" of the two bit vectors. * @return A bit vector corresponding to the logical "or" of the two bit vectors.
*/ */
BitVector operator |(BitVector const &bv) { BitVector operator |(BitVector const &bv) {
uint_fast64_t minSize = (bv.bucket_count < this->bucket_count) ? bv.bucket_count : this->bucket_count;
uint_fast64_t minSize = (bv.bucketCount < this->bucketCount) ? bv.bucketCount : this->bucketCount;
// Create resulting bit vector and perform the operation on the individual elements. // Create resulting bit vector and perform the operation on the individual elements.
BitVector result(minSize << 6); BitVector result(minSize << 6);
for (uint_fast64_t i = 0; i < minSize; ++i) { for (uint_fast64_t i = 0; i < minSize; ++i) {
result.bucket_array[i] = this->bucket_array[i] | bv.bucket_array[i];
result.bucketArray[i] = this->bucketArray[i] | bv.bucketArray[i];
} }
return result; return result;
@ -193,12 +194,12 @@ public:
* @return A bit vector corresponding to the logical "xor" of the two bit vectors. * @return A bit vector corresponding to the logical "xor" of the two bit vectors.
*/ */
BitVector operator ^(BitVector const &bv) { BitVector operator ^(BitVector const &bv) {
uint_fast64_t minSize = (bv.bucket_count < this->bucket_count) ? bv.bucket_count : this->bucket_count;
uint_fast64_t minSize = (bv.bucketCount < this->bucketCount) ? bv.bucketCount : this->bucketCount;
// Create resulting bit vector and perform the operation on the individual elements. // Create resulting bit vector and perform the operation on the individual elements.
BitVector result(minSize << 6); BitVector result(minSize << 6);
for (uint_fast64_t i = 0; i < minSize; ++i) { for (uint_fast64_t i = 0; i < minSize; ++i) {
result.bucket_array[i] = this->bucket_array[i] ^ bv.bucket_array[i];
result.bucketArray[i] = this->bucketArray[i] ^ bv.bucketArray[i];
} }
return result; return result;
@ -210,9 +211,9 @@ public:
*/ */
BitVector operator ~() { BitVector operator ~() {
// Create resulting bit vector and perform the operation on the individual elements. // Create resulting bit vector and perform the operation on the individual elements.
BitVector result(this->bucket_count << 6);
for (uint_fast64_t i = 0; i < this->bucket_count; ++i) {
result.bucket_array[i] = ~this->bucket_array[i];
BitVector result(this->bucketCount << 6);
for (uint_fast64_t i = 0; i < this->bucketCount; ++i) {
result.bucketArray[i] = ~this->bucketArray[i];
} }
return result; return result;
@ -226,12 +227,12 @@ public:
* @return A bit vector corresponding to the logical "implies" of the two bit vectors. * @return A bit vector corresponding to the logical "implies" of the two bit vectors.
*/ */
BitVector implies(BitVector& bv) { BitVector implies(BitVector& bv) {
uint_fast64_t minSize = (bv.bucket_count < this->bucket_count) ? bv.bucket_count : this->bucket_count;
uint_fast64_t minSize = (bv.bucketCount < this->bucketCount) ? bv.bucketCount : this->bucketCount;
// Create resulting bit vector and perform the operation on the individual elements. // Create resulting bit vector and perform the operation on the individual elements.
BitVector result(minSize << 6); BitVector result(minSize << 6);
for (uint_fast64_t i = 0; i < this->bucket_count; ++i) {
result.bucket_array[i] = ~this->bucket_array[i] | bv.bucket_array[i];
for (uint_fast64_t i = 0; i < this->bucketCount; ++i) {
result.bucketArray[i] = ~this->bucketArray[i] | bv.bucketArray[i];
} }
return result; return result;
@ -243,13 +244,13 @@ public:
*/ */
uint_fast64_t getNumberOfSetBits() { uint_fast64_t getNumberOfSetBits() {
uint_fast64_t set_bits = 0; uint_fast64_t set_bits = 0;
for (uint_fast64_t i = 0; i < bucket_count; ++i) {
for (uint_fast64_t i = 0; i < bucketCount; ++i) {
// Check if we are using g++ or clang++ and, if so, use the built-in function // Check if we are using g++ or clang++ and, if so, use the built-in function
#if (defined (__GNUG__) || defined(__clang__)) #if (defined (__GNUG__) || defined(__clang__))
set_bits += __builtin_popcountll(this->bucket_array[i]);
set_bits += __builtin_popcountll(this->bucketArray[i]);
#else #else
uint_fast32_t cnt; uint_fast32_t cnt;
uint_fast64_t bitset = this->bucket_array[i];
uint_fast64_t bitset = this->bucketArray[i];
for (cnt = 0; bitset; cnt++) { for (cnt = 0; bitset; cnt++) {
bitset &= bitset - 1; bitset &= bitset - 1;
} }
@ -263,7 +264,7 @@ public:
* Retrieves the number of bits this bit vector can store. * Retrieves the number of bits this bit vector can store.
*/ */
uint_fast64_t getSize() { uint_fast64_t getSize() {
return bucket_count << 6;
return bucketCount << 6;
} }
/*! /*!
@ -271,15 +272,29 @@ public:
* @return The size of the bit vector in memory measured in bytes. * @return The size of the bit vector in memory measured in bytes.
*/ */
uint_fast64_t getSizeInMemory() { uint_fast64_t getSizeInMemory() {
return sizeof(*this) + sizeof(uint_fast64_t) * bucket_count;
return sizeof(*this) + sizeof(uint_fast64_t) * bucketCount;
}
/*!
* Returns an iterator to the indices of the set bits in the bit vector.
*/
constIndexIterator begin() const {
return constIndexIterator(this->bucketArray, this->bucketArray + bucketCount);
}
/*!
* Returns an iterator pointing at the element past the bit vector.
*/
constIndexIterator end() const {
return constIndexIterator(this->bucketArray + bucketCount, 0);
} }
private: private:
/*! The number of 64-bit buckets we use as internal storage. */ /*! The number of 64-bit buckets we use as internal storage. */
uint_fast64_t bucket_count;
uint_fast64_t bucketCount;
/*! Array of 64-bit buckets to store the bits. */ /*! Array of 64-bit buckets to store the bits. */
uint64_t* bucket_array;
uint64_t* bucketArray;
/*! A bit mask that can be used to reduce a modulo operation to a logical "and". */ /*! A bit mask that can be used to reduce a modulo operation to a logical "and". */
static const uint_fast64_t mod64mask = (1 << 6) - 1; static const uint_fast64_t mod64mask = (1 << 6) - 1;

2
src/storage/SquareSparseMatrix.h

@ -20,7 +20,7 @@ extern log4cplus::Logger logger;
namespace mrmc { namespace mrmc {
namespace sparse {
namespace storage {
/*! /*!
* A sparse matrix class with a constant number of non-zero entries on the non-diagonal fields * A sparse matrix class with a constant number of non-zero entries on the non-diagonal fields

2
test/parser/read_tra_file_test.cpp

@ -20,7 +20,7 @@ TEST(ReadTraFileTest, NonExistingFileTest) {
/* The following test case is based on one of the original MRMC test cases /* The following test case is based on one of the original MRMC test cases
*/ */
TEST(ReadTraFileTest, ParseFileTest1) { TEST(ReadTraFileTest, ParseFileTest1) {
mrmc::sparse::SquareSparseMatrix<double> *result = NULL;
mrmc::storage::SquareSparseMatrix<double> *result = NULL;
ASSERT_NO_THROW(result = mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra")); ASSERT_NO_THROW(result = mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra"));
if (result != NULL) { if (result != NULL) {

36
test/storage/BitVectorTest.cpp

@ -3,8 +3,8 @@
#include "src/exceptions/invalid_argument.h" #include "src/exceptions/invalid_argument.h"
TEST(BitVectorTest, GetSetTest) { TEST(BitVectorTest, GetSetTest) {
mrmc::vector::BitVector *bv = NULL;
ASSERT_NO_THROW(bv = new mrmc::vector::BitVector(32));
mrmc::storage::BitVector *bv = NULL;
ASSERT_NO_THROW(bv = new mrmc::storage::BitVector(32));
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bv->set(i, i % 2 == 0); bv->set(i, i % 2 == 0);
@ -17,7 +17,7 @@ TEST(BitVectorTest, GetSetTest) {
} }
TEST(BitVectorTest, InitialZeroTest) { TEST(BitVectorTest, InitialZeroTest) {
mrmc::vector::BitVector bvA(32);
mrmc::storage::BitVector bvA(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ASSERT_FALSE(bvA.get(i)); ASSERT_FALSE(bvA.get(i));
@ -25,7 +25,7 @@ TEST(BitVectorTest, InitialZeroTest) {
} }
TEST(BitVectorTest, ResizeTest) { TEST(BitVectorTest, ResizeTest) {
mrmc::vector::BitVector bvA(32);
mrmc::storage::BitVector bvA(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bvA.set(i, true); bvA.set(i, true);
@ -46,15 +46,15 @@ TEST(BitVectorTest, ResizeTest) {
} }
TEST(BitVectorTest, OperatorNotTest) { TEST(BitVectorTest, OperatorNotTest) {
mrmc::vector::BitVector bvA(32);
mrmc::vector::BitVector bvB(32);
mrmc::storage::BitVector bvA(32);
mrmc::storage::BitVector bvB(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bvA.set(i, i % 2 == 0); bvA.set(i, i % 2 == 0);
bvB.set(i, i % 2 == 1); bvB.set(i, i % 2 == 1);
} }
mrmc::vector::BitVector bvN = ~bvB;
mrmc::storage::BitVector bvN = ~bvB;
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ASSERT_EQ(bvA.get(i), bvN.get(i)); ASSERT_EQ(bvA.get(i), bvN.get(i));
@ -62,15 +62,15 @@ TEST(BitVectorTest, OperatorNotTest) {
} }
TEST(BitVectorTest, OperatorAndTest) { TEST(BitVectorTest, OperatorAndTest) {
mrmc::vector::BitVector bvA(32);
mrmc::vector::BitVector bvB(32);
mrmc::storage::BitVector bvA(32);
mrmc::storage::BitVector bvB(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bvA.set(i, i % 2 == 0); bvA.set(i, i % 2 == 0);
bvB.set(i, i % 2 == 1); bvB.set(i, i % 2 == 1);
} }
mrmc::vector::BitVector bvN = bvA & bvB;
mrmc::storage::BitVector bvN = bvA & bvB;
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ASSERT_FALSE(bvN.get(i)); ASSERT_FALSE(bvN.get(i));
@ -78,15 +78,15 @@ TEST(BitVectorTest, OperatorAndTest) {
} }
TEST(BitVectorTest, OperatorOrTest) { TEST(BitVectorTest, OperatorOrTest) {
mrmc::vector::BitVector bvA(32);
mrmc::vector::BitVector bvB(32);
mrmc::storage::BitVector bvA(32);
mrmc::storage::BitVector bvB(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bvA.set(i, i % 2 == 0); bvA.set(i, i % 2 == 0);
bvB.set(i, i % 2 == 1); bvB.set(i, i % 2 == 1);
} }
mrmc::vector::BitVector bvN = bvA | bvB;
mrmc::storage::BitVector bvN = bvA | bvB;
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ASSERT_TRUE(bvN.get(i)); ASSERT_TRUE(bvN.get(i));
@ -94,17 +94,17 @@ TEST(BitVectorTest, OperatorOrTest) {
} }
TEST(BitVectorTest, OperatorXorTest) { TEST(BitVectorTest, OperatorXorTest) {
mrmc::vector::BitVector bvA(32);
mrmc::vector::BitVector bvB(32);
mrmc::storage::BitVector bvA(32);
mrmc::storage::BitVector bvB(32);
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
bvA.set(i, true); bvA.set(i, true);
bvB.set(i, i % 2 == 1); bvB.set(i, i % 2 == 1);
} }
mrmc::vector::BitVector bvN = bvA ^ bvB;
mrmc::vector::BitVector bvO = ~bvB;
mrmc::vector::BitVector bvP = bvA ^ bvA;
mrmc::storage::BitVector bvN = bvA ^ bvB;
mrmc::storage::BitVector bvO = ~bvB;
mrmc::storage::BitVector bvP = bvA ^ bvA;
for (int i = 0; i < 32; ++i) { for (int i = 0; i < 32; ++i) {
ASSERT_EQ(bvN.get(i), bvO.get(i)); ASSERT_EQ(bvN.get(i), bvO.get(i));

82
test/storage/SquareSparseMatrixTest.cpp

@ -3,70 +3,70 @@
#include "src/exceptions/invalid_argument.h" #include "src/exceptions/invalid_argument.h"
TEST(SquareSparseMatrixTest, ZeroRowsTest) { TEST(SquareSparseMatrixTest, ZeroRowsTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(0);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(0);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_THROW(ssm->initialize(50), mrmc::exceptions::invalid_argument); ASSERT_THROW(ssm->initialize(50), mrmc::exceptions::invalid_argument);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm; delete ssm;
} }
TEST(SquareSparseMatrixTest, TooManyEntriesTest) { TEST(SquareSparseMatrixTest, TooManyEntriesTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(2);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(2);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_THROW(ssm->initialize(10), mrmc::exceptions::invalid_argument); ASSERT_THROW(ssm->initialize(10), mrmc::exceptions::invalid_argument);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm; delete ssm;
} }
TEST(SquareSparseMatrixTest, addNextValueTest) { TEST(SquareSparseMatrixTest, addNextValueTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_NO_THROW(ssm->initialize(1)); ASSERT_NO_THROW(ssm->initialize(1));
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_THROW(ssm->addNextValue(-1, 1, 1), mrmc::exceptions::out_of_range); ASSERT_THROW(ssm->addNextValue(-1, 1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(1, -1, 1), mrmc::exceptions::out_of_range); ASSERT_THROW(ssm->addNextValue(1, -1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(6, 1, 1), mrmc::exceptions::out_of_range); ASSERT_THROW(ssm->addNextValue(6, 1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(1, 6, 1), mrmc::exceptions::out_of_range); ASSERT_THROW(ssm->addNextValue(1, 6, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm; delete ssm;
} }
TEST(SquareSparseMatrixTest, finalizeTest) { TEST(SquareSparseMatrixTest, finalizeTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_NO_THROW(ssm->initialize(5)); ASSERT_NO_THROW(ssm->initialize(5));
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_NO_THROW(ssm->addNextValue(1, 2, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 2, 1));
ASSERT_NO_THROW(ssm->addNextValue(1, 3, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 3, 1));
ASSERT_NO_THROW(ssm->addNextValue(1, 4, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 4, 1));
ASSERT_NO_THROW(ssm->addNextValue(1, 5, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 5, 1));
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_THROW(ssm->finalize(), mrmc::exceptions::invalid_state); ASSERT_THROW(ssm->finalize(), mrmc::exceptions::invalid_state);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm; delete ssm;
} }
TEST(SquareSparseMatrixTest, Test) { TEST(SquareSparseMatrixTest, Test) {
// 25 rows, 50 non zero entries // 25 rows, 50 non zero entries
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(25);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(25);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
int values[50] = { int values[50] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
@ -78,7 +78,7 @@ TEST(SquareSparseMatrixTest, Test) {
int position_row[50] = { int position_row[50] = {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, /* first row empty, one full row ��� 25 minus the diagonal entry */
2, 2, 2, 2, /* first row empty, one full row ��������� 25 minus the diagonal entry */
4, 4, /* one empty row, then first and last column */ 4, 4, /* one empty row, then first and last column */
13, 13, 13, 13, /* a few empty rows, middle columns */ 13, 13, 13, 13, /* a few empty rows, middle columns */
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
@ -95,15 +95,15 @@ TEST(SquareSparseMatrixTest, Test) {
}; };
ASSERT_NO_THROW(ssm->initialize(50)); ASSERT_NO_THROW(ssm->initialize(50));
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
ASSERT_NO_THROW(ssm->addNextValue(position_row[i], position_col[i], values[i])); ASSERT_NO_THROW(ssm->addNextValue(position_row[i], position_col[i], values[i]));
} }
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target; int target;
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
@ -124,15 +124,15 @@ TEST(SquareSparseMatrixTest, Test) {
ASSERT_EQ(0, target); ASSERT_EQ(0, target);
} }
} }
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
delete ssm; delete ssm;
} }
TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) { TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) {
// 10 rows, 100 non zero entries // 10 rows, 100 non zero entries
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int> esm(10, 10); Eigen::SparseMatrix<int> esm(10, 10);
for (int row = 0; row < 10; ++row) { for (int row = 0; row < 10; ++row) {
@ -148,7 +148,7 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest)
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1; int target = -1;
for (int row = 0; row < 10; ++row) { for (int row = 0; row < 10; ++row) {
@ -161,8 +161,8 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest)
TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) { TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) {
// 10 rows, 100 non zero entries // 10 rows, 100 non zero entries
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10); Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10);
for (int row = 0; row < 10; ++row) { for (int row = 0; row < 10; ++row) {
@ -178,7 +178,7 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest)
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1; int target = -1;
for (int row = 0; row < 10; ++row) { for (int row = 0; row < 10; ++row) {
@ -191,8 +191,8 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest)
TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) { TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) {
// 10 rows, 15 non zero entries // 10 rows, 15 non zero entries
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int> esm(10, 10); Eigen::SparseMatrix<int> esm(10, 10);
@ -226,7 +226,7 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1; int target = -1;
@ -238,8 +238,8 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest
TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) { TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) {
// 10 rows, 15 non zero entries // 10 rows, 15 non zero entries
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10); Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10);
@ -273,7 +273,7 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1; int target = -1;
@ -285,24 +285,24 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest
TEST(SquareSparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) { TEST(SquareSparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) {
int values[100]; int values[100];
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
mrmc::storage::SquareSparseMatrix<int> *ssm = new mrmc::storage::SquareSparseMatrix<int>(10);
for (uint_fast32_t i = 0; i < 100; ++i) { for (uint_fast32_t i = 0; i < 100; ++i) {
values[i] = i; values[i] = i;
} }
ASSERT_NO_THROW(ssm->initialize(100 - 10)); ASSERT_NO_THROW(ssm->initialize(100 - 10));
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
for (uint_fast32_t row = 0; row < 10; ++row) { for (uint_fast32_t row = 0; row < 10; ++row) {
for (uint_fast32_t col = 0; col < 10; ++col) { for (uint_fast32_t col = 0; col < 10; ++col) {
ASSERT_NO_THROW(ssm->addNextValue(row, col, values[row * 10 + col])); ASSERT_NO_THROW(ssm->addNextValue(row, col, values[row * 10 + col]));
} }
} }
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_NO_THROW(ssm->finalize()); ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
Eigen::SparseMatrix<int, Eigen::RowMajor, int_fast32_t>* esm = ssm->toEigenSparseMatrix(); Eigen::SparseMatrix<int, Eigen::RowMajor, int_fast32_t>* esm = ssm->toEigenSparseMatrix();

Loading…
Cancel
Save