master > master: code-rust - verwendung von assertion rules in unit-tests

This commit is contained in:
RD 2022-04-10 10:35:35 +02:00
parent 5da0084a6d
commit 5f5165dca8
1 changed files with 11 additions and 17 deletions

View File

@ -5,8 +5,8 @@
use rstest::fixture; use rstest::fixture;
use rstest::rstest; use rstest::rstest;
use ads2::core::utils;
use ads2::graphs::graph; use ads2::graphs::graph;
use ads2::*;
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// Fixtures // Fixtures
@ -31,7 +31,7 @@ fn test_graph_create_noerror() {
vec![5, 7, 8], vec![5, 7, 8],
vec![(5,7), (7, 8)] vec![(5,7), (7, 8)]
); );
assert_eq!(gph.len(), 3); assert_length!(gph, 3);
}); });
assert!(result.is_ok()); assert!(result.is_ok());
let result = std::panic::catch_unwind(|| { let result = std::panic::catch_unwind(|| {
@ -39,12 +39,12 @@ fn test_graph_create_noerror() {
vec!["5", "7", "8", "10"], vec!["5", "7", "8", "10"],
vec![("5", "7"), ("7", "8")] vec![("5", "7"), ("7", "8")]
); );
assert_eq!(gph.len(), 4); assert_length!(gph, 4);
}); });
assert!(result.is_ok()); assert!(result.is_ok());
let result = std::panic::catch_unwind(|| { let result = std::panic::catch_unwind(|| {
let gph = graph::Graph::<f64>::new(Vec::new(), Vec::new()); let gph = graph::Graph::<f64>::new(Vec::new(), Vec::new());
assert_eq!(gph.len(), 0); assert_length!(gph, 0);
}); });
assert!(result.is_ok()); assert!(result.is_ok());
} }
@ -52,22 +52,16 @@ fn test_graph_create_noerror() {
#[rstest] #[rstest]
fn test_graph_subgraph(fixture_graph: graph::Graph<i32>) { fn test_graph_subgraph(fixture_graph: graph::Graph<i32>) {
let sub_gph = fixture_graph.subgraph(vec![2,4,5,6,8]); let sub_gph = fixture_graph.subgraph(vec![2,4,5,6,8]);
assert_eq!(utils::vec_to_set(&sub_gph.edges), utils::vec_to_set(&vec![(6,2), (4,5), (5,6), (6,8)])); assert_eq_contents!(sub_gph.edges, vec![(6,2), (4,5), (5,6), (6,8)]);
} }
#[rstest] #[rstest]
fn test_graph_successors_and_predecessors(fixture_graph: graph::Graph<i32>) { fn test_graph_successors_and_predecessors(fixture_graph: graph::Graph<i32>) {
let u = 1; assert_eq_contents!(fixture_graph.successors(&1), vec![2, 3]);
assert_eq!(utils::vec_to_set(&fixture_graph.successors(&u)), utils::vec_to_set(&vec![2, 3])); assert_length_unique!(fixture_graph.successors(&8), 0);
let u = 8; assert_eq_contents!(fixture_graph.successors(&6), vec![2, 7, 8]);
assert_eq!(utils::vec_to_set(&fixture_graph.successors(&u)).len(), 0);
let u = 6;
assert_eq!(utils::vec_to_set(&fixture_graph.successors(&u)), utils::vec_to_set(&vec![2, 7, 8]));
let u = 1; assert_length_unique!(fixture_graph.predecessors(&1), 0);
assert_eq!(utils::vec_to_set(&fixture_graph.predecessors(&u)).len(), 0); assert_eq_contents!(fixture_graph.predecessors(&8), vec![6]);
let u = 8; assert_eq_contents!(fixture_graph.predecessors(&6), vec![5]);
assert_eq!(utils::vec_to_set(&fixture_graph.predecessors(&u)), utils::vec_to_set(&vec![6]));
let u = 6;
assert_eq!(utils::vec_to_set(&fixture_graph.predecessors(&u)), utils::vec_to_set(&vec![5]));
} }