Skip to content

Commit

Permalink
Refactor (#133)
Browse files Browse the repository at this point in the history
* Refactor

* name change
  • Loading branch information
t-lohse authored Nov 17, 2022
1 parent 4d14929 commit 463f1f6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Ecdar-ProtoBuf
Submodule Ecdar-ProtoBuf updated 1 files
+4 −1 query.proto
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use crate::DataReader::component_loader::{
};
pub use crate::DataReader::{parse_queries, xml_parser};
pub use crate::ModelObjects::queries::Query;
use crate::ProtobufServer::services::query_request::settings::ReduceClocksLevel::All;
pub use crate::System::extract_system_rep;
pub use ModelObjects::component;
pub use ModelObjects::queries;
Expand All @@ -23,7 +24,7 @@ pub use System::executable_query::QueryResult;

pub const DEFAULT_SETTINGS: ProtobufServer::services::query_request::Settings =
ProtobufServer::services::query_request::Settings {
reduce_clocks_level: Some(-1),
reduce_clocks_level: Some(All(true)),
};

#[macro_use]
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
use clap::{load_yaml, App};
use reveaal::logging::setup_logger;

use reveaal::ProtobufServer::services::query_request::settings::ReduceClocksLevel;
use reveaal::ProtobufServer::services::query_request::Settings;
use reveaal::{
extract_system_rep, parse_queries, start_grpc_server_with_tokio, xml_parser, ComponentLoader,
JsonProjectLoader, ProjectLoader, Query, QueryResult, XmlProjectLoader,
JsonProjectLoader, ProjectLoader, Query, QueryResult, XmlProjectLoader, DEFAULT_SETTINGS,
};
use std::env;
use std::str::FromStr;
Expand Down Expand Up @@ -53,9 +54,18 @@ fn parse_args(matches: &clap::ArgMatches) -> (Box<dyn ComponentLoader>, Vec<Quer
let folder_path = matches.value_of("folder").unwrap_or("");
let query = matches.value_of("query").unwrap_or("");
let settings = Settings {
reduce_clocks_level: matches.value_of("").map(|v| {
i32::from_str(v).unwrap_or_else(|e| panic!("Argument {} could not be parsed", e))
}),
reduce_clocks_level: matches
.value_of("clock-reduction-level")
.map(|v| {
let lvl = i32::from_str(v)
.unwrap_or_else(|e| panic!("Argument {} could not be parsed", e));
if lvl < 0 {
ReduceClocksLevel::All(false)
} else {
ReduceClocksLevel::Level(lvl)
}
})
.or(DEFAULT_SETTINGS.reduce_clocks_level),
};

let project_loader = get_project_loader(folder_path.to_string(), settings);
Expand Down
6 changes: 6 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::ProtobufServer::services::query_request::settings::ReduceClocksLevel::All;
use crate::ProtobufServer::services::query_request::Settings;

pub mod ClockReduction;
pub mod ModelObjects;
pub mod edge_ids;
Expand All @@ -7,3 +10,6 @@ pub mod reachability;
pub mod refinement;
pub mod sample;
pub mod save_component;
pub const TEST_SETTINGS: Settings = Settings {
reduce_clocks_level: Some(All(false)),
};
4 changes: 2 additions & 2 deletions src/tests/reachability/helper_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub mod reachability_test_helper_functions {
folder_path: &str,
) -> (Box<SystemRecipe>, Box<dyn TransitionSystem>) {
let mut comp_loader = if xml_parser::is_xml_project(folder_path) {
XmlProjectLoader::new(folder_path.to_string(), crate::DEFAULT_SETTINGS)
XmlProjectLoader::new(folder_path.to_string(), crate::tests::TEST_SETTINGS)
} else {
JsonProjectLoader::new(folder_path.to_string(), crate::DEFAULT_SETTINGS)
JsonProjectLoader::new(folder_path.to_string(), crate::tests::TEST_SETTINGS)
}
.to_comp_loader();
let mut dim: ClockIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/reachability/parse_partial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod reachability_parse_partial_state {
"Both end and start are partial")]
fn query_parser_reject_partial_start(parser_input: &str) {
let mut comp_loader =
JsonProjectLoader::new(String::from(FOLDER_PATH), crate::DEFAULT_SETTINGS)
JsonProjectLoader::new(String::from(FOLDER_PATH), crate::tests::TEST_SETTINGS)
.to_comp_loader();
// Make query:
let q = parse_queries::parse_to_query(parser_input);
Expand Down
8 changes: 4 additions & 4 deletions src/tests/reachability/parser_restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ mod reachability_parser_restrictions_test {
fn query_parser_checks_invalid_amount_of_location_and_machine_args(parser_input: &str) {
let folder_path = "samples/json/EcdarUniversity".to_string();
let mut comp_loader = if xml_parser::is_xml_project(&folder_path) {
XmlProjectLoader::new(folder_path, crate::DEFAULT_SETTINGS)
XmlProjectLoader::new(folder_path, crate::tests::TEST_SETTINGS)
} else {
JsonProjectLoader::new(folder_path, crate::DEFAULT_SETTINGS)
JsonProjectLoader::new(folder_path, crate::tests::TEST_SETTINGS)
}
.to_comp_loader();
// Make query:
Expand All @@ -39,9 +39,9 @@ mod reachability_parser_restrictions_test {
fn query_parser_checks_valid_amount_of_location_and_machine_args(parser_input: &str) {
let folder_path = "samples/json/EcdarUniversity".to_string();
let mut comp_loader = if xml_parser::is_xml_project(&folder_path) {
XmlProjectLoader::new(folder_path, crate::DEFAULT_SETTINGS)
XmlProjectLoader::new(folder_path, crate::tests::TEST_SETTINGS)
} else {
JsonProjectLoader::new(folder_path, crate::DEFAULT_SETTINGS)
JsonProjectLoader::new(folder_path, crate::tests::TEST_SETTINGS)
}
.to_comp_loader();
// Make query:
Expand Down
4 changes: 2 additions & 2 deletions src/tests/refinement/Helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn json_refinement_check(PATH: &str, QUERY: &str) -> bool {

pub fn xml_run_query(PATH: &str, QUERY: &str) -> QueryResult {
let project_path = String::from(PATH);
let project_loader = XmlProjectLoader::new(project_path, crate::DEFAULT_SETTINGS);
let project_loader = XmlProjectLoader::new(project_path, crate::tests::TEST_SETTINGS);
let query = parse_queries::parse_to_expression_tree(QUERY)
.unwrap()
.remove(0);
Expand All @@ -50,7 +50,7 @@ pub fn xml_run_query(PATH: &str, QUERY: &str) -> QueryResult {
}

pub fn json_run_query(PATH: &str, QUERY: &str) -> QueryResult {
let project_loader = JsonProjectLoader::new(String::from(PATH), crate::DEFAULT_SETTINGS);
let project_loader = JsonProjectLoader::new(String::from(PATH), crate::tests::TEST_SETTINGS);
let query = parse_queries::parse_to_expression_tree(QUERY)
.unwrap()
.remove(0);
Expand Down
8 changes: 4 additions & 4 deletions src/tests/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod samples {
#[test]
fn test_locations_T1() {
let mut project_loader =
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::DEFAULT_SETTINGS);
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::tests::TEST_SETTINGS);
let t1 = project_loader.get_component("Test1");

assert_eq!(t1.get_name(), "Test1");
Expand All @@ -17,7 +17,7 @@ mod samples {
#[test]
fn test_locations_T2() {
let mut project_loader =
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::DEFAULT_SETTINGS);
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::tests::TEST_SETTINGS);
let t2 = project_loader.get_component("Test2");

assert_eq!(t2.get_name(), "Test2");
Expand All @@ -27,7 +27,7 @@ mod samples {
#[test]
fn test_locations_T3() {
let mut project_loader =
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::DEFAULT_SETTINGS);
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::tests::TEST_SETTINGS);
let t3 = project_loader.get_component("Test3");

assert_eq!(t3.get_name(), "Test3");
Expand All @@ -37,7 +37,7 @@ mod samples {
#[test]
fn test_names_T1_through_T12() {
let mut project_loader =
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::DEFAULT_SETTINGS);
JsonProjectLoader::new(CONJUNCTION_SAMPLE.to_string(), crate::tests::TEST_SETTINGS);

for i in 1..12 {
let t = project_loader.get_component(&format!("Test{}", i).to_string());
Expand Down
2 changes: 1 addition & 1 deletion src/tests/save_component/save_comp_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod util {

pub fn json_reconstructed_component_refines_base_self(input_path: &str, system: &str) {
let project_loader =
JsonProjectLoader::new(String::from(input_path), crate::DEFAULT_SETTINGS);
JsonProjectLoader::new(String::from(input_path), crate::tests::TEST_SETTINGS);

//This query is not executed but simply used to extract an UncachedSystem so the tests can just give system expressions
let str_query = format!("get-component: {} save-as test", system);
Expand Down

0 comments on commit 463f1f6

Please sign in to comment.