Browse Source

- Additional "wrong header" testcase for the tra parser

- Methods of the sparse matrix now throw objects (instead of pointers)
- Initializations of the pointer attributes of the sparse matrix with
NULL (otherwise strange things may happen...)

Note: Test cases for the sparse matrix now work for me.
tempestpy_adaptions
Thomas Heinemann 12 years ago
committed by Lanchid
parent
commit
d37b23a5c5
  1. 21
      src/sparse/static_sparse_matrix.h
  2. 12
      test/parser/read_tra_file_test.cpp
  3. 8
      test/sparse/static_sparse_matrix.cpp

21
src/sparse/static_sparse_matrix.h

@ -33,6 +33,11 @@ class StaticSparseMatrix {
current_size = 0;
storage_size = 0;
value_storage = NULL;
diagonal_storage = NULL;
column_indications = NULL;
row_indications = NULL;
row_count = rows;
non_zero_entry_count = non_zero_entries;
@ -71,7 +76,7 @@ class StaticSparseMatrix {
}
if ((row > row_count) || (col > row_count) || (row == 0) || (col == 0)) {
throw new mrmc::exceptions::out_of_range("mrmc::StaticSparseMatrix::getValue: row or col not in 1 .. rows");
throw mrmc::exceptions::out_of_range("mrmc::StaticSparseMatrix::getValue: row or col not in 1 .. rows");
}
uint_fast32_t row_start = row_indications[row - 1];
@ -100,12 +105,12 @@ class StaticSparseMatrix {
if (row_count == 0) {
pantheios::log_ERROR("StaticSparseMatrix::initialize: Throwing invalid_argument for row_count = 0");
throw new mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: Matrix with 0 rows is not reasonable");
throw mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: Matrix with 0 rows is not reasonable");
}
if (((row_count * row_count) - row_count) < non_zero_entry_count) {
pantheios::log_ERROR("StaticSparseMatrix::initialize: Throwing invalid_argument: More non-zero entries than entries in target matrix");
throw new mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: More non-zero entries than entries in target matrix");
throw mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: More non-zero entries than entries in target matrix");
}
storage_size = non_zero_entry_count;
@ -122,10 +127,10 @@ class StaticSparseMatrix {
if ((value_storage == NULL) || (column_indications == NULL) || (row_indications == NULL) || (diagonal_storage == NULL)) {
pantheios::log_ERROR("StaticSparseMatrix::initialize: Throwing bad_alloc: memory allocation failed");
#ifdef __linux__
throw new std::bad_alloc();
#ifdef _WIN32
throw std::bad_alloc("mrmc::StaticSparseMatrix::initialize: memory allocation failed");
#else
throw new std::bad_alloc("mrmc::StaticSparseMatrix::initialize: memory allocation failed");
throw std::bad_alloc();
#endif
}
}
@ -138,7 +143,7 @@ class StaticSparseMatrix {
void addNextValue(const uint_fast32_t row, const uint_fast32_t col, const T value) {
if ((row > row_count) || (col > row_count) || (row == 0) || (col == 0)) {
pantheios::log_ERROR("StaticSparseMatrix::addNextValue: Throwing out_of_range: row or col not in 1 .. rows");
throw new mrmc::exceptions::out_of_range("mrmc::StaticSparseMatrix::addNextValue: row or col not in 1 .. rows");
throw mrmc::exceptions::out_of_range("mrmc::StaticSparseMatrix::addNextValue: row or col not in 1 .. rows");
}
if (row == col) {
@ -162,7 +167,7 @@ class StaticSparseMatrix {
void finalize() {
if (storage_size != current_size) {
pantheios::log_ERROR("StaticSparseMatrix::finalize: Throwing invalid_state: Wrong call count for addNextValue");
throw new mrmc::exceptions::invalid_state("mrmc::StaticSparseMatrix::finalize: Wrong call count for addNextValue");
throw mrmc::exceptions::invalid_state("mrmc::StaticSparseMatrix::finalize: Wrong call count for addNextValue");
}
if (last_row != row_count) {

12
test/parser/read_tra_file_test.cpp

@ -61,10 +61,16 @@ TEST(ReadTraFileTest, ParseFileTest1) {
ASSERT_EQ(val,0);
}
TEST(ReadTraFileTest, WrongFormatTestHeader) {
pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader");
TEST(ReadTraFileTest, WrongFormatTestHeader1) {
pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader1");
ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/wrong_format_header.tra"), mrmc::exceptions::wrong_file_format);
ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/wrong_format_header1.tra"), mrmc::exceptions::wrong_file_format);
}
TEST(ReadTraFileTest, WrongFormatTestHeader2) {
pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader2");
ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/wrong_format_header2.tra"), mrmc::exceptions::wrong_file_format);
}
TEST(ReadTraFileTest, WrongFormatTestTransition) {

8
test/sparse/static_sparse_matrix.cpp

@ -3,7 +3,6 @@
#include "src/exceptions/invalid_argument.h"
TEST(StaticSparseMatrixTest, ZeroRowsTest) {
pantheios::log_INFORMATIONAL("Started ZeroRowsTest");
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(0, 50);
ASSERT_THROW(ssm->initialize(), mrmc::exceptions::invalid_argument);
@ -92,10 +91,15 @@ TEST(StaticSparseMatrixTest, Test) {
}
// test for a few of the empty rows
for (int row = 14; row < 24; ++row) {
for (int row = 15; row < 24; ++row) {
for (int col = 1; col <= 25; ++col) {
target = 1;
if (row != col) {
ASSERT_FALSE(ssm->getValue(row, col, &target));
} else {
ASSERT_TRUE(ssm->getValue(row, col, &target));
}
ASSERT_EQ(0, target);
}
}

Loading…
Cancel
Save