summaryrefslogtreecommitdiff
path: root/graph_macro/tests/works.rs
blob: dc0f75ad914f3c94c63481ac37e19393bd630e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#![allow(dead_code)]

use graph_macro::Graph;

#[derive(Debug, Graph, Default)]
pub(crate) struct Haha {
    test: String,
    #[graph]
    little_graph: graph::ALGraph,
}

#[derive(Debug)]
/// Testing docs
#[repr(C)]
#[derive(Default, Graph)]
#[allow(unused)]
pub struct HahaU(pub(crate) graph::ALGraph);

#[derive(Debug, Graph)]
pub struct HahaG<T: graph::GraphLabel> {
    #[graph(haha)]
    #[allow(unused)]
    #[inline]
    pub(crate) 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() {
    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);
}