Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

62 #84

Closed
wants to merge 16 commits into from
23 changes: 22 additions & 1 deletion src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::Edge;
use crate::Hex;
use crate::Sodg;
use crate::Vertex;
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use log::trace;
use rstest::rstest;

Expand Down Expand Up @@ -106,7 +106,13 @@ impl Sodg {
.vertices
.get_mut(&v)
.context(format!("Can't find ν{v}"))?;
if vtx.posted {
return Err(anyhow!(
"The vertex isn't available, #put() was called earlier"
l3r8yJ marked this conversation as resolved.
Show resolved Hide resolved
));
}
vtx.data = d.clone();
vtx.posted = true;
l3r8yJ marked this conversation as resolved.
Show resolved Hide resolved
self.validate(vec![v])?;
trace!("#data: data of ν{v} set to {d}");
Ok(())
Expand Down Expand Up @@ -475,3 +481,18 @@ fn checks_for_data_absence() -> Result<()> {
assert!(!g.full(0).unwrap());
Ok(())
}

#[test]
fn checks_for_put_called_once() -> Result<()> {
let mut g = Sodg::empty();
g.add(0)?;
g.add(1)?;
g.bind(0, 1, "bar/baz")?;
g.put(0, Hex::from(42))?;
let actual = g.put(0, Hex::from(42)).unwrap_err();
assert_eq!(
format!("{}", actual.root_cause()),
"The vertex isn't available, #put() was called earlier"
);
Ok(())
}
2 changes: 2 additions & 0 deletions src/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) struct Vertex {
pub data: Hex,
pub parents: HashSet<u32>,
pub taken: bool,
pub posted: bool,
}

impl Vertex {
Expand All @@ -46,6 +47,7 @@ impl Vertex {
data: Hex::empty(),
parents: HashSet::new(),
taken: false,
posted: false,
}
}
}
Expand Down