• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FilippoFantinato / algorithms-on-graphs / #6

12 Sep 2024 04:59AM UTC coverage: 42.254% (-44.8%) from 87.097%
#6

push

FilippoFantinato
Added basic cli

24 of 65 new or added lines in 4 files covered. (36.92%)

30 of 71 relevant lines covered (42.25%)

27.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/src/graph/directed_graph.rs
1
use std::collections::{HashMap, HashSet};
2

3
use crate::graph::graph::Graph;
4

5
use super::graph::{Vertex, Weight};
6

7
pub struct DirectedGraph {
8
    adj_matrix: HashMap<Vertex, HashMap<Vertex, Weight>>,
9
    vertices: HashSet<Vertex>,
10
    _size: usize,
11
}
12

13
impl DirectedGraph {
14
    pub fn new(size: usize) -> DirectedGraph {
4✔
15
        DirectedGraph {
16
            adj_matrix: HashMap::new(),
4✔
17
            vertices: HashSet::new(),
4✔
18
            _size: size,
19
        }
20
    }
21
}
22

23
impl Graph for DirectedGraph {
24
    fn add_edge(&mut self, u: Vertex, v: Vertex, w: Weight) {
23✔
25
        if self.adj_matrix.get(&u).is_none() {
37✔
26
            self.adj_matrix.insert(u, HashMap::new());
14✔
27
        }
28
        self.adj_matrix.get_mut(&u).unwrap().insert(v, w);
23✔
29

30
        self.vertices.insert(u);
23✔
31
        self.vertices.insert(v);
23✔
32
    }
33

NEW
34
    fn _get_size(&self) -> usize {
×
NEW
35
        self.vertices.len()
×
36
    }
37

NEW
38
    fn _get_adj_list(&self, v: &Vertex) -> Option<&HashMap<Vertex, Weight>> {
×
NEW
39
        self.adj_matrix.get(&v)
×
40
    }
41

42
    fn get_weight(&self, u: &Vertex, v: &Vertex) -> Option<&Weight> {
206✔
43
        self.adj_matrix.get(u).and_then(|el| el.get(v))
497✔
44
    }
45

46
    fn get_vertices(&self) -> &HashSet<Vertex> {
39✔
47
        &self.vertices
39✔
48
    }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc