-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* remove id implementation * fix tests
- Loading branch information
1 parent
9c939f1
commit a708779
Showing
10 changed files
with
218 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
use crate::query::query_id::QueryId; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct RemoveEdge {} | ||
pub struct RemoveEdge { | ||
pub id: QueryId, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn derived_from_debug() { | ||
format!("{:?}", RemoveEdge {}); | ||
format!("{:?}", RemoveEdge { id: QueryId::Id(0) }); | ||
} | ||
|
||
#[test] | ||
fn derived_from_partial_eq() { | ||
assert_eq!(RemoveEdge {}, RemoveEdge {}); | ||
assert_eq!( | ||
RemoveEdge { id: QueryId::Id(0) }, | ||
RemoveEdge { id: QueryId::Id(0) } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,58 @@ | ||
use super::query_id::QueryId; | ||
use super::query_ids::QueryIds; | ||
use crate::commands::remove_edge::RemoveEdge; | ||
use crate::commands::remove_node::RemoveNode; | ||
use crate::commands::Commands; | ||
|
||
pub struct RemoveQuery(pub QueryIds); | ||
|
||
impl RemoveQuery { | ||
pub(crate) fn commands(&self) -> Vec<Commands> { | ||
match &self.0 { | ||
QueryIds::All | QueryIds::Search(_) => panic!("Invalid query"), | ||
QueryIds::Id(id) => Self::id(id), | ||
QueryIds::Ids(ids) => Self::ids(ids), | ||
} | ||
} | ||
|
||
fn id(id: &QueryId) -> Vec<Commands> { | ||
if id.is_node() { | ||
vec![Commands::RemoveNode(RemoveNode { id: id.clone() })] | ||
} else { | ||
vec![Commands::RemoveEdge(RemoveEdge { id: id.clone() })] | ||
} | ||
} | ||
|
||
fn ids(ids: &Vec<QueryId>) -> Vec<Commands> { | ||
let mut commands = Vec::<Commands>::new(); | ||
|
||
for id in ids { | ||
if id.is_node() { | ||
commands.push(Commands::RemoveNode(RemoveNode { id: id.clone() })); | ||
} else { | ||
commands.push(Commands::RemoveEdge(RemoveEdge { id: id.clone() })); | ||
} | ||
} | ||
|
||
commands | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::test_utilities::catch_unwidn_silent::catch_unwind_silent; | ||
|
||
#[test] | ||
fn invalid_query_preprocessing_many_many() { | ||
let result = catch_unwind_silent(|| { | ||
let query = RemoveQuery(QueryIds::All); | ||
query.commands(); | ||
}); | ||
|
||
assert_eq!( | ||
*result.unwrap_err().downcast_ref::<&str>().unwrap(), | ||
"Invalid query" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters