summaryrefslogtreecommitdiff
path: root/graph_macro/tests/works.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-05-04 13:02:39 +0800
committerJSDurand <mmemmew@gmail.com>2023-05-04 13:02:39 +0800
commit662817e6367a865a2d86a99581172cc45f585807 (patch)
treee5c7d1a0a52ce9d057d9c27ac4c7549b77198efb /graph_macro/tests/works.rs
parent57d600f261cca5d9076239e548c6e00646f774b6 (diff)
Completed the procedural macro for deriving Graphs.
The macro `graph_derive` can automatically write the boiler-plate codes for wrapper types one of whose sub-fields implements the `Graph` trait. The generated implementation will delegate the `Graph` operations to the sub-field which implements the `Graph` trait. I plan to add more macros, corresponding to various other graph-related traits, so that no such boiler-plate codes are needed, at least for my use-cases.
Diffstat (limited to 'graph_macro/tests/works.rs')
-rw-r--r--graph_macro/tests/works.rs95
1 files changed, 90 insertions, 5 deletions
diff --git a/graph_macro/tests/works.rs b/graph_macro/tests/works.rs
index fe8a853..a57e866 100644
--- a/graph_macro/tests/works.rs
+++ b/graph_macro/tests/works.rs
@@ -1,13 +1,98 @@
#![allow(dead_code)]
-use graph_macro::Testing;
+use graph_macro::Graph;
-#[derive(Debug, Testing)]
-struct Haha {
- size: usize,
+#[derive(Debug, Graph, Default)]
+pub(crate) struct Haha {
+ test: String,
+ #[graph]
+ little_graph: graph::ALGraph,
+}
+
+#[derive(Debug)]
+/// Testing docs
+#[allow(unused)]
+#[derive(Default, Graph)]
+pub struct HahaU(pub(crate) graph::ALGraph);
+
+#[derive(Debug, Graph)]
+pub struct HahaG<T: graph::GraphLabel> {
+ graph: graph::DLGraph<T>,
+}
+
+impl<T: graph::GraphLabel> Default for HahaG<T> {
+ fn default() -> Self {
+ Self {
+ graph: Default::default(),
+ }
+ }
+}
+
+#[derive(Debug, Graph)]
+pub struct HahaW<T>
+where
+ T: graph::GraphLabel,
+{
+ name: String,
+ #[graph]
+ graph: graph::DLGraph<T>,
+}
+
+impl<T: graph::GraphLabel> Default for HahaW<T> {
+ fn default() -> Self {
+ Self {
+ name: Default::default(),
+ graph: Default::default(),
+ }
+ }
+}
+
+impl Haha {
+ fn new(test: impl ToString) -> Self {
+ use graph::builder::Builder;
+
+ let test = test.to_string();
+ let mut little_graph_builder: graph::adlist::ALGBuilder = Default::default();
+
+ little_graph_builder.add_vertex();
+ little_graph_builder.add_vertex();
+ little_graph_builder.add_edge(0, 1, ()).unwrap();
+
+ let little_graph = little_graph_builder.build();
+
+ Self { little_graph, test }
+ }
}
#[test]
fn it_works() {
- println!("it works: {:?}", Haha { size: 0 });
+ use graph::{builder::Builder, Graph};
+ let haha = Haha::new("test");
+
+ assert!(!haha.is_empty());
+
+ assert_eq!(haha.has_edge(0, 1), Ok(true));
+
+ let hahaw = HahaW::<usize>::default();
+
+ assert!(hahaw.is_empty());
+
+ assert!(matches!(
+ hahaw.has_edge(0, 1),
+ Err(graph::error::Error::IndexOutOfBounds(0, 0))
+ ));
+
+ let mut builder: graph::adlist::ALGBuilder = Default::default();
+
+ let first = builder.add_vertex();
+ let second = builder.add_vertex();
+ builder.add_edge(first, second, ()).unwrap();
+
+ let hahau = HahaU(builder.build());
+
+ assert!(!hahau.is_empty());
+
+ assert_eq!(hahau.has_edge(0, 1), Ok(true));
+
+ dbg!(haha, hahaw, hahau);
}