Browse Source
Added tests for deterministic models i.e. DeterministicModelParserTest and DeterministicSparseTransitionParserTest
Added tests for deterministic models i.e. DeterministicModelParserTest and DeterministicSparseTransitionParserTest
- Additionally lots of small changes to other tests and test files.
Former-commit-id: d0b3f968ea
tempestpy_adaptions
masawei
11 years ago
6 changed files with 385 additions and 48 deletions
-
10src/parser/MarkovAutomatonSparseTransitionParser.cpp
-
13test/functional/parser/AutoParserTest.cpp
-
101test/functional/parser/DeterministicModelParserTest.cpp
-
229test/functional/parser/DeterministicSparseTransitionParserTest.cpp
-
8test/functional/parser/LabFileParserTest.cpp
-
72test/functional/parser/MarkovAutomatonSparseTransitionParserTest.cpp
@ -0,0 +1,101 @@ |
|||
/*
|
|||
* DeterministicModelParserTest.cpp |
|||
* |
|||
* Created on: Feb 24, 2014 |
|||
* Author: Manuel Sascha Weiand |
|||
*/ |
|||
|
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "src/parser/DeterministicModelParser.h"
|
|||
#include "src/models/Dtmc.h"
|
|||
#include "src/models/Ctmc.h"
|
|||
#include "src/exceptions/FileIoException.h"
|
|||
|
|||
TEST(DeterministicModelParserTest, NonExistingFile) { |
|||
// No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException); |
|||
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseCtmc(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException); |
|||
} |
|||
|
|||
TEST(DeterministicModelParserTest, BasicDtmcParsing) { |
|||
|
|||
// Parse a Dtmc and check the result.
|
|||
storm::models::Dtmc<double> dtmc(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general_input.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.state.rew", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.trans.rew")); |
|||
|
|||
ASSERT_EQ(dtmc.getNumberOfStates(), 8); |
|||
ASSERT_EQ(dtmc.getNumberOfTransitions(), 21); |
|||
|
|||
ASSERT_EQ(dtmc.getInitialStates().getNumberOfSetBits(), 2); |
|||
ASSERT_TRUE(dtmc.getInitialStates().get(0)); |
|||
ASSERT_TRUE(dtmc.getInitialStates().get(7)); |
|||
ASSERT_EQ(dtmc.getStateLabeling().getNumberOfAtomicPropositions(), 5); |
|||
ASSERT_EQ(dtmc.getLabelsForState(6).size(), 2); |
|||
|
|||
ASSERT_TRUE(dtmc.hasStateRewards()); |
|||
ASSERT_EQ(dtmc.getStateRewardVector()[7], 42); |
|||
double rewardSum = 0; |
|||
for(uint_fast64_t i = 0; i < dtmc.getStateRewardVector().size(); i++) { |
|||
rewardSum += dtmc.getStateRewardVector()[i]; |
|||
} |
|||
ASSERT_EQ(rewardSum, 263.32); |
|||
|
|||
ASSERT_TRUE(dtmc.hasTransitionRewards()); |
|||
ASSERT_EQ(dtmc.getTransitionRewardMatrix().getEntryCount(), 17); |
|||
rewardSum = 0; |
|||
for(uint_fast64_t i = 0; i < dtmc.getTransitionRewardMatrix().getRowCount(); i++) { |
|||
rewardSum += dtmc.getTransitionRewardMatrix().getRowSum(i); |
|||
} |
|||
ASSERT_EQ(rewardSum, 125.4); |
|||
} |
|||
|
|||
|
|||
TEST(DeterministicModelParserTest, BasicCtmcParsing) { |
|||
|
|||
// Parse a Ctmc and check the result.
|
|||
storm::models::Ctmc<double> ctmc(storm::parser::DeterministicModelParser::parseCtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general_input.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.state.rew", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.trans.rew")); |
|||
|
|||
ASSERT_EQ(ctmc.getNumberOfStates(), 8); |
|||
ASSERT_EQ(ctmc.getNumberOfTransitions(), 21); |
|||
|
|||
ASSERT_EQ(ctmc.getInitialStates().getNumberOfSetBits(), 2); |
|||
ASSERT_TRUE(ctmc.getInitialStates().get(0)); |
|||
ASSERT_TRUE(ctmc.getInitialStates().get(7)); |
|||
ASSERT_EQ(ctmc.getStateLabeling().getNumberOfAtomicPropositions(), 5); |
|||
ASSERT_EQ(ctmc.getLabelsForState(6).size(), 2); |
|||
|
|||
ASSERT_TRUE(ctmc.hasStateRewards()); |
|||
ASSERT_EQ(ctmc.getStateRewardVector()[7], 42); |
|||
double rewardSum = 0; |
|||
for(uint_fast64_t i = 0; i < ctmc.getStateRewardVector().size(); i++) { |
|||
rewardSum += ctmc.getStateRewardVector()[i]; |
|||
} |
|||
ASSERT_EQ(rewardSum, 263.32); |
|||
|
|||
ASSERT_TRUE(ctmc.hasTransitionRewards()); |
|||
ASSERT_EQ(ctmc.getTransitionRewardMatrix().getEntryCount(), 17); |
|||
rewardSum = 0; |
|||
for(uint_fast64_t i = 0; i < ctmc.getTransitionRewardMatrix().getRowCount(); i++) { |
|||
rewardSum += ctmc.getTransitionRewardMatrix().getRowSum(i); |
|||
} |
|||
ASSERT_EQ(rewardSum, 125.4); |
|||
} |
|||
|
|||
TEST(DeterministicModelParserTest, UnmatchedFiles) { |
|||
|
|||
// Test file combinations that do not match, i.e. differing number of states, transitions, etc.
|
|||
|
|||
// The labeling file contains a label for a non existent state.
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_unmatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general_input.lab"), storm::exceptions::OutOfRangeException); |
|||
|
|||
// The state reward file contains a reward for a non existent state.
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_unmatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_unmatched.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.state.rew"), storm::exceptions::OutOfRangeException); |
|||
|
|||
// The transition reward file contains rewards for a non existent state.
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_unmatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_unmatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.trans.rew"), storm::exceptions::OutOfRangeException); |
|||
|
|||
// The transition reward file contains rewards for a non existent transition
|
|||
ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_unmatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_unmatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_unmatched.trans.rew"), storm::exceptions::OutOfRangeException); |
|||
} |
@ -0,0 +1,229 @@ |
|||
/*
|
|||
* DeterministicSparseTransitionParserTest.cpp |
|||
* |
|||
* Created on: Feb 24, 2014 |
|||
* Author: Manuel Sascha Weiand |
|||
*/ |
|||
|
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "src/parser/DeterministicSparseTransitionParser.h"
|
|||
#include "src/storage/SparseMatrix.h"
|
|||
#include "src/settings/InternalOptionMemento.h"
|
|||
#include "src/exceptions/FileIoException.h"
|
|||
#include "src/exceptions/WrongFormatException.h"
|
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, NonExistingFile) { |
|||
|
|||
// No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
|
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException); |
|||
|
|||
storm::storage::SparseMatrix<double> nullMatrix; |
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", nullMatrix), storm::exceptions::FileIoException); |
|||
} |
|||
|
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, BasicTransitionsParsing) { |
|||
|
|||
// Parse a deterministic transitions file and test the resulting matrix.
|
|||
storm::storage::SparseMatrix<double> transitionMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra"); |
|||
|
|||
ASSERT_EQ(transitionMatrix.getColumnCount(), 8); |
|||
ASSERT_EQ(transitionMatrix.getEntryCount(), 21); |
|||
|
|||
// Test every entry of the matrix.
|
|||
storm::storage::SparseMatrix<double>::const_iterator cIter = transitionMatrix.begin(0); |
|||
|
|||
ASSERT_EQ(cIter->first, 0); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 1); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 1); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 2); |
|||
ASSERT_EQ(cIter->second, 0.5); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 0.5); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 2); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 0.4); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 4); |
|||
ASSERT_EQ(cIter->second, 0.4); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 0.2); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 4); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 0.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 4); |
|||
ASSERT_EQ(cIter->second, 0.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 0.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 0.7); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 0); |
|||
ASSERT_EQ(cIter->second, 0.9); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 0.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 0.224653); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 7); |
|||
ASSERT_EQ(cIter->second, 0.775347); |
|||
} |
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, BasicTransitionsRewardsParsing) { |
|||
|
|||
// First parse a transition file. Then parse a transition reward file for the resulting transitiion matrix.
|
|||
storm::storage::SparseMatrix<double> transitionMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra"); |
|||
|
|||
storm::storage::SparseMatrix<double> rewardMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.trans.rew", transitionMatrix); |
|||
|
|||
ASSERT_EQ(rewardMatrix.getColumnCount(), 8); |
|||
ASSERT_EQ(rewardMatrix.getEntryCount(), 17); |
|||
|
|||
// Test every entry of the matrix.
|
|||
storm::storage::SparseMatrix<double>::const_iterator cIter = rewardMatrix.begin(0); |
|||
|
|||
ASSERT_EQ(cIter->first, 1); |
|||
ASSERT_EQ(cIter->second, 10); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 2); |
|||
ASSERT_EQ(cIter->second, 5); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 5.5); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 21.4); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 4); |
|||
ASSERT_EQ(cIter->second, 4); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 2); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 3); |
|||
ASSERT_EQ(cIter->second, 0.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 4); |
|||
ASSERT_EQ(cIter->second, 1.1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 9.5); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 6.7); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 0); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 5); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 12); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 35.224653); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 7); |
|||
ASSERT_EQ(cIter->second, 9.875347); |
|||
} |
|||
|
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, Whitespaces) { |
|||
|
|||
// Test the resilience of the parser against whitespaces.
|
|||
// Do so by comparing the hash of the matrix resulting from the file without whitespaces with the hash of the matrix resulting from the file with whitespaces.
|
|||
uint_fast64_t correctHash = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra").hash(); |
|||
storm::storage::SparseMatrix<double> transitionMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_whitespaces_input.tra"); |
|||
ASSERT_EQ(correctHash, transitionMatrix.hash()); |
|||
|
|||
// Do the same for the corresponding transition rewards file (with and without whitespaces)
|
|||
correctHash = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general_input.trans.rew", transitionMatrix).hash(); |
|||
ASSERT_EQ(correctHash, storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_whitespaces_input.trans.rew", transitionMatrix).hash()); |
|||
} |
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, MixedTransitionOrder) { |
|||
|
|||
// Since the MatrixBuilder needs sequential input of new elements reordering of transitions or states should throw an exception.
|
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mixedTransitionOrder_input.tra"), storm::exceptions::InvalidArgumentException); |
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mixedStateOrder_input.tra"), storm::exceptions::InvalidArgumentException); |
|||
|
|||
storm::storage::SparseMatrix<double> transitionMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general_input.tra"); |
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_mixedTransitionOrder_input.trans.rew", transitionMatrix), storm::exceptions::InvalidArgumentException); |
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitionRewards(STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_mixedStateOrder_input.trans.rew", transitionMatrix), storm::exceptions::InvalidArgumentException); |
|||
} |
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, FixDeadlocks) { |
|||
|
|||
// Set the fixDeadlocks flag temporarily. It is set to its old value once the deadlockOption object is destructed.
|
|||
storm::settings::InternalOptionMemento setDeadlockOption("fixDeadlocks", true); |
|||
|
|||
// Parse a transitions file with the fixDeadlocks Flag set and test if it works.
|
|||
storm::storage::SparseMatrix<double> transitionMatrix = storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_deadlock_input.tra"); |
|||
|
|||
ASSERT_EQ(transitionMatrix.getColumnCount(), 9); |
|||
ASSERT_EQ(transitionMatrix.getEntryCount(), 23); |
|||
|
|||
storm::storage::SparseMatrix<double>::const_iterator cIter = transitionMatrix.begin(7); |
|||
ASSERT_EQ(cIter->first, 7); |
|||
ASSERT_EQ(cIter->second, 1); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 6); |
|||
ASSERT_EQ(cIter->second, 0.224653); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 7); |
|||
ASSERT_EQ(cIter->second, 0.775347); |
|||
cIter++; |
|||
ASSERT_EQ(cIter->first, 8); |
|||
ASSERT_EQ(cIter->second, 0); |
|||
} |
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, DontFixDeadlocks) { |
|||
|
|||
// Try to parse a transitions file containing a deadlock state with the fixDeadlocksFlag unset. This should throw an exception.
|
|||
storm::settings::InternalOptionMemento unsetDeadlockOption("fixDeadlocks", false); |
|||
|
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_deadlock_input.tra"), storm::exceptions::WrongFormatException); |
|||
} |
|||
|
|||
TEST(DeterministicSparseTransitionParserTest, DoubledLines) { |
|||
// There is a redundant line in the transition file. As the transition already exists this should throw an exception.
|
|||
// Note: If two consecutive lines are doubled no exception is thrown.
|
|||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser::parseDeterministicTransitions(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_doubledLines_input.tra"), storm::exceptions::InvalidArgumentException); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue