diff --git a/src/modelChecker/DtmcPrctlModelChecker.h b/src/modelChecker/DtmcPrctlModelChecker.h index bed1c9832..1473b2d8a 100644 --- a/src/modelChecker/DtmcPrctlModelChecker.h +++ b/src/modelChecker/DtmcPrctlModelChecker.h @@ -39,11 +39,11 @@ class DtmcPrctlModelChecker { explicit DtmcPrctlModelChecker(mrmc::models::Dtmc* DTMC); ~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 multiplyMatrixVector(std::vector*) = 0; - virtual mrmc::vector::BitVector checkStateFormula(mrmc::formula::PCTLStateFormula* formula) { + virtual mrmc::storage::BitVector checkStateFormula(mrmc::formula::PCTLStateFormula* formula) { if (formula->type() == AND) { return checkAnd(static_cast(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*) = 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*) = 0; virtual std::vector checkPathFormula(mrmc::formula::PCTLPathFormula* formula) { if (formula->type() == NEXT) { diff --git a/src/models/atomic_propositions_labeling.h b/src/models/atomic_propositions_labeling.h index 476097811..560b6f9ed 100644 --- a/src/models/atomic_propositions_labeling.h +++ b/src/models/atomic_propositions_labeling.h @@ -10,7 +10,7 @@ #include -#include "single_atomic_proposition_labeling.h" +#include "src/models/single_atomic_proposition_labeling.h" /* Map types: By default, the boost hash map is used. * 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 * 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); } diff --git a/src/models/backward_transitions.h b/src/models/backward_transitions.h index cc20c17e3..97ea77e35 100644 --- a/src/models/backward_transitions.h +++ b/src/models/backward_transitions.h @@ -35,11 +35,9 @@ public: * @param transition_matrix The (0-based) matrix representing the transition * relation. */ - BackwardTransitions(mrmc::sparse::SquareSparseMatrix* transitionMatrix) { - numberOfNonZeroTransitions = transitionMatrix->getNonZeroEntryCount(); + BackwardTransitions(mrmc::storage::SquareSparseMatrix* transitionMatrix) + : numberOfStates(transitionMatrix->getRowCount()), numberOfNonZeroTransitions(transitionMatrix->getNonZeroEntryCount()) { this->predecessor_list = new uint_fast64_t[numberOfNonZeroTransitions]; - - numberOfStates = transitionMatrix->getRowCount(); this->state_indices_list = new uint_fast64_t[numberOfStates + 1]; // First, we need to count how many backward transitions each state has. diff --git a/src/models/dtmc.h b/src/models/dtmc.h index 8a648a24e..41c1ebb5d 100644 --- a/src/models/dtmc.h +++ b/src/models/dtmc.h @@ -35,7 +35,7 @@ public: * @param state_labeling The labeling that assigns a set of atomic * propositions to each state. */ - Dtmc(mrmc::sparse::SquareSparseMatrix* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling) + Dtmc(mrmc::storage::SquareSparseMatrix* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling) : backward_transitions(probability_matrix) { this->probability_matrix = probability_matrix; this->state_labeling = state_labeling; @@ -84,7 +84,7 @@ public: * @return A pointer to the matrix representing the transition probability * function. */ - mrmc::sparse::SquareSparseMatrix* getTransitionProbabilityMatrix() { + mrmc::storage::SquareSparseMatrix* getTransitionProbabilityMatrix() { return this->probability_matrix; } @@ -111,7 +111,7 @@ public: private: /*! A matrix representing the transition probability function of the DTMC. */ - mrmc::sparse::SquareSparseMatrix* probability_matrix; + mrmc::storage::SquareSparseMatrix* probability_matrix; /*! The labeling of the states of the DTMC. */ mrmc::models::AtomicPropositionsLabeling* state_labeling; diff --git a/src/models/single_atomic_proposition_labeling.h b/src/models/single_atomic_proposition_labeling.h index 33691e4df..b1f543c52 100644 --- a/src/models/single_atomic_proposition_labeling.h +++ b/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 * labeled. */ - mrmc::vector::BitVector label_vector; + mrmc::storage::BitVector label_vector; }; } // namespace models diff --git a/src/mrmc.cpp b/src/mrmc.cpp index 1dbf4b1f3..9c5c5ff76 100644 --- a/src/mrmc.cpp +++ b/src/mrmc.cpp @@ -77,7 +77,7 @@ int main(const int argc, const char* argv[]) { return 0; } - mrmc::sparse::SquareSparseMatrix* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str()); + mrmc::storage::SquareSparseMatrix* 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::Dtmc dtmc(probMatrix, labeling); diff --git a/src/parser/read_tra_file.cpp b/src/parser/read_tra_file.cpp index 504269b3d..90a3e9a5c 100644 --- a/src/parser/read_tra_file.cpp +++ b/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. */ -sparse::SquareSparseMatrix * read_tra_file(const char * filename) { +storage::SquareSparseMatrix * read_tra_file(const char * filename) { FILE *p = NULL; char s[BUFFER_SIZE]; uint_fast64_t non_zero = 0; int rows = 0; - sparse::SquareSparseMatrix *sp = NULL; + storage::SquareSparseMatrix *sp = NULL; p = fopen(filename, "r"); if(p == NULL) { @@ -129,7 +129,7 @@ sparse::SquareSparseMatrix * read_tra_file(const char * filename) { * 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) */ - sp = new sparse::SquareSparseMatrix(static_cast(rows) + 1); + sp = new storage::SquareSparseMatrix(static_cast(rows) + 1); if ( NULL == sp ) { throw std::bad_alloc(); return NULL; diff --git a/src/parser/read_tra_file.h b/src/parser/read_tra_file.h index 2b7cf6f32..bd4ac7f22 100644 --- a/src/parser/read_tra_file.h +++ b/src/parser/read_tra_file.h @@ -11,7 +11,7 @@ namespace mrmc{ namespace parser { -mrmc::sparse::SquareSparseMatrix * read_tra_file(const char * filename); +mrmc::storage::SquareSparseMatrix * read_tra_file(const char * filename); } } diff --git a/src/storage/BitVector.h b/src/storage/BitVector.h index b4e03c6b9..ca1c7ec09 100644 --- a/src/storage/BitVector.h +++ b/src/storage/BitVector.h @@ -18,7 +18,7 @@ extern log4cplus::Logger logger; namespace mrmc { -namespace vector { +namespace storage { /*! * A bit vector that is internally represented by an array of 64-bit values. @@ -27,6 +27,7 @@ class BitVector { public: class constIndexIterator { + public: constIndexIterator(uint_fast64_t* bucketPtr, uint_fast64_t* endBucketPtr) : bucketPtr(bucketPtr), endBucketPtr(endBucketPtr), offset(0), currentBitInByte(0) { } constIndexIterator& operator++() { do { @@ -63,15 +64,15 @@ public: } // 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) { - ++bucket_count; + ++bucketCount; } // Finally, create the full bucket array. This should initialize the array // with 0s (notice the parentheses at the end) for standard conforming // compilers. - bucket_array = new uint_fast64_t[bucket_count](); + bucketArray = new uint_fast64_t[bucketCount](); } //! Copy Constructor @@ -79,10 +80,10 @@ public: * Copy Constructor. Performs a deep copy of the given bit vector. * @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."); - 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 @@ -90,8 +91,8 @@ public: * Destructor. Frees the underlying bucket array. */ ~BitVector() { - if (bucket_array != nullptr) { - delete[] bucket_array; + if (bucketArray != nullptr) { + delete[] bucketArray; } } @@ -102,24 +103,24 @@ public: void resize(uint_fast64_t newLength) { uint_fast64_t newBucketCount = newLength >> 6; if ((newLength & mod64mask) != 0) { - ++bucket_count; + ++bucketCount; } // Reserve a temporary array for copying. uint_fast64_t* tempArray = new uint_fast64_t[newBucketCount]; // 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. - 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. - delete[] bucket_array; - bucket_array = tempArray; + delete[] bucketArray; + bucketArray = tempArray; } /*! @@ -131,9 +132,9 @@ public: uint_fast64_t bucket = index >> 6; uint_fast64_t mask = static_cast(1) << (index & mod64mask); if (value) { - bucket_array[bucket] |= mask; + bucketArray[bucket] |= mask; } else { - bucket_array[bucket] &= ~mask; + bucketArray[bucket] &= ~mask; } } @@ -144,7 +145,7 @@ public: bool get(const uint_fast64_t index) { uint_fast64_t bucket = index >> 6; uint_fast64_t mask = static_cast(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. */ 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. BitVector result(minSize << 6); 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; @@ -174,12 +175,12 @@ public: * @return A bit vector corresponding to the logical "or" of the two bit vectors. */ 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. BitVector result(minSize << 6); 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; @@ -193,12 +194,12 @@ public: * @return A bit vector corresponding to the logical "xor" of the two bit vectors. */ 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. BitVector result(minSize << 6); 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; @@ -210,9 +211,9 @@ public: */ BitVector operator ~() { // 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; @@ -226,12 +227,12 @@ public: * @return A bit vector corresponding to the logical "implies" of the two bit vectors. */ 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. 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; @@ -243,13 +244,13 @@ public: */ uint_fast64_t getNumberOfSetBits() { 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 #if (defined (__GNUG__) || defined(__clang__)) - set_bits += __builtin_popcountll(this->bucket_array[i]); + set_bits += __builtin_popcountll(this->bucketArray[i]); #else uint_fast32_t cnt; - uint_fast64_t bitset = this->bucket_array[i]; + uint_fast64_t bitset = this->bucketArray[i]; for (cnt = 0; bitset; cnt++) { bitset &= bitset - 1; } @@ -263,7 +264,7 @@ public: * Retrieves the number of bits this bit vector can store. */ 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. */ 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: /*! 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. */ - uint64_t* bucket_array; + uint64_t* bucketArray; /*! 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; diff --git a/src/storage/SquareSparseMatrix.h b/src/storage/SquareSparseMatrix.h index 246ea0857..d2c2480bf 100644 --- a/src/storage/SquareSparseMatrix.h +++ b/src/storage/SquareSparseMatrix.h @@ -20,7 +20,7 @@ extern log4cplus::Logger logger; namespace mrmc { -namespace sparse { +namespace storage { /*! * A sparse matrix class with a constant number of non-zero entries on the non-diagonal fields diff --git a/test/parser/read_tra_file_test.cpp b/test/parser/read_tra_file_test.cpp index 4c2fce2bd..2b5e8000d 100644 --- a/test/parser/read_tra_file_test.cpp +++ b/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 */ TEST(ReadTraFileTest, ParseFileTest1) { - mrmc::sparse::SquareSparseMatrix *result = NULL; + mrmc::storage::SquareSparseMatrix *result = NULL; 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) { diff --git a/test/storage/BitVectorTest.cpp b/test/storage/BitVectorTest.cpp index ba1f030cb..a556fb790 100644 --- a/test/storage/BitVectorTest.cpp +++ b/test/storage/BitVectorTest.cpp @@ -3,8 +3,8 @@ #include "src/exceptions/invalid_argument.h" 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) { bv->set(i, i % 2 == 0); @@ -17,7 +17,7 @@ TEST(BitVectorTest, GetSetTest) { } TEST(BitVectorTest, InitialZeroTest) { - mrmc::vector::BitVector bvA(32); + mrmc::storage::BitVector bvA(32); for (int i = 0; i < 32; ++i) { ASSERT_FALSE(bvA.get(i)); @@ -25,7 +25,7 @@ TEST(BitVectorTest, InitialZeroTest) { } TEST(BitVectorTest, ResizeTest) { - mrmc::vector::BitVector bvA(32); + mrmc::storage::BitVector bvA(32); for (int i = 0; i < 32; ++i) { bvA.set(i, true); @@ -46,15 +46,15 @@ TEST(BitVectorTest, ResizeTest) { } 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) { bvA.set(i, i % 2 == 0); bvB.set(i, i % 2 == 1); } - mrmc::vector::BitVector bvN = ~bvB; + mrmc::storage::BitVector bvN = ~bvB; for (int i = 0; i < 32; ++i) { ASSERT_EQ(bvA.get(i), bvN.get(i)); @@ -62,15 +62,15 @@ TEST(BitVectorTest, OperatorNotTest) { } 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) { bvA.set(i, i % 2 == 0); 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) { ASSERT_FALSE(bvN.get(i)); @@ -78,15 +78,15 @@ TEST(BitVectorTest, OperatorAndTest) { } 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) { bvA.set(i, i % 2 == 0); 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) { ASSERT_TRUE(bvN.get(i)); @@ -94,17 +94,17 @@ TEST(BitVectorTest, OperatorOrTest) { } 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) { bvA.set(i, true); 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) { ASSERT_EQ(bvN.get(i), bvO.get(i)); diff --git a/test/storage/SquareSparseMatrixTest.cpp b/test/storage/SquareSparseMatrixTest.cpp index d7cfd537d..e10d6bf88 100644 --- a/test/storage/SquareSparseMatrixTest.cpp +++ b/test/storage/SquareSparseMatrixTest.cpp @@ -3,70 +3,70 @@ #include "src/exceptions/invalid_argument.h" TEST(SquareSparseMatrixTest, ZeroRowsTest) { - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(0); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(0); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); ASSERT_THROW(ssm->initialize(50), mrmc::exceptions::invalid_argument); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); delete ssm; } TEST(SquareSparseMatrixTest, TooManyEntriesTest) { - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(2); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(2); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); ASSERT_THROW(ssm->initialize(10), mrmc::exceptions::invalid_argument); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); delete ssm; } TEST(SquareSparseMatrixTest, addNextValueTest) { - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(5); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(5); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); ASSERT_NO_THROW(ssm->initialize(1)); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); ASSERT_THROW(ssm->addNextValue(-1, 1, 1), mrmc::exceptions::out_of_range); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); ASSERT_THROW(ssm->addNextValue(1, -1, 1), mrmc::exceptions::out_of_range); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); ASSERT_THROW(ssm->addNextValue(6, 1, 1), mrmc::exceptions::out_of_range); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); ASSERT_THROW(ssm->addNextValue(1, 6, 1), mrmc::exceptions::out_of_range); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); delete ssm; } TEST(SquareSparseMatrixTest, finalizeTest) { - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(5); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(5); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); ASSERT_NO_THROW(ssm->initialize(5)); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); ASSERT_NO_THROW(ssm->addNextValue(1, 2, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 3, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 4, 1)); ASSERT_NO_THROW(ssm->addNextValue(1, 5, 1)); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); ASSERT_THROW(ssm->finalize(), mrmc::exceptions::invalid_state); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Error); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Error); delete ssm; } TEST(SquareSparseMatrixTest, Test) { // 25 rows, 50 non zero entries - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(25); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(25); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); int values[50] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, @@ -78,7 +78,7 @@ TEST(SquareSparseMatrixTest, Test) { 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, /* 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 */ 13, 13, 13, 13, /* a few empty rows, middle columns */ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, @@ -95,15 +95,15 @@ TEST(SquareSparseMatrixTest, Test) { }; ASSERT_NO_THROW(ssm->initialize(50)); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); for (int i = 0; i < 50; ++i) { ASSERT_NO_THROW(ssm->addNextValue(position_row[i], position_col[i], values[i])); } - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); int target; for (int i = 0; i < 50; ++i) { @@ -124,15 +124,15 @@ TEST(SquareSparseMatrixTest, Test) { ASSERT_EQ(0, target); } } - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); delete ssm; } TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) { // 10 rows, 100 non zero entries - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(10); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(10); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); Eigen::SparseMatrix esm(10, 10); for (int row = 0; row < 10; ++row) { @@ -148,7 +148,7 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); int target = -1; for (int row = 0; row < 10; ++row) { @@ -161,8 +161,8 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) { // 10 rows, 100 non zero entries - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(10); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(10); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); Eigen::SparseMatrix esm(10, 10); for (int row = 0; row < 10; ++row) { @@ -178,7 +178,7 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); int target = -1; for (int row = 0; row < 10; ++row) { @@ -191,8 +191,8 @@ TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) { // 10 rows, 15 non zero entries - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(10); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(10); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); Eigen::SparseMatrix esm(10, 10); @@ -226,7 +226,7 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); int target = -1; @@ -238,8 +238,8 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) { // 10 rows, 15 non zero entries - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(10); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::UnInitialized); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(10); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::UnInitialized); Eigen::SparseMatrix esm(10, 10); @@ -273,7 +273,7 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); int target = -1; @@ -285,24 +285,24 @@ TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest TEST(SquareSparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) { int values[100]; - mrmc::sparse::SquareSparseMatrix *ssm = new mrmc::sparse::SquareSparseMatrix(10); + mrmc::storage::SquareSparseMatrix *ssm = new mrmc::storage::SquareSparseMatrix(10); for (uint_fast32_t i = 0; i < 100; ++i) { values[i] = i; } ASSERT_NO_THROW(ssm->initialize(100 - 10)); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); for (uint_fast32_t row = 0; row < 10; ++row) { for (uint_fast32_t col = 0; col < 10; ++col) { ASSERT_NO_THROW(ssm->addNextValue(row, col, values[row * 10 + col])); } } - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::Initialized); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::Initialized); ASSERT_NO_THROW(ssm->finalize()); - ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix::MatrixStatus::ReadReady); + ASSERT_EQ(ssm->getState(), mrmc::storage::SquareSparseMatrix::MatrixStatus::ReadReady); Eigen::SparseMatrix* esm = ssm->toEigenSparseMatrix();