Skip to content
Snippets Groups Projects
Commit aed1d972 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Property: avoid setting incompatible vlaue types.

Add corresponding unit test.
parent 6a4ae0b3
No related branches found
No related tags found
1 merge request!46Resolve "Properties: set_value function: Check value type."
......@@ -739,7 +739,7 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "opossum"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"approx",
"chrono",
......
//! Module for handling node properties
use plotters::prelude::LogScalable;
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::HashMap, mem};
use uuid::Uuid;
use crate::{
......@@ -163,6 +163,9 @@ impl Property {
));
}
}
if mem::discriminant(&self.prop) != mem::discriminant(&prop) {
return Err(OpossumError::Properties("incompatible value types".into()));
}
self.check_conditions(&prop)?;
self.prop = prop;
Ok(())
......@@ -323,3 +326,17 @@ pub enum PropCondition {
GreaterThanEqual(f64),
LessThanEqual(f64),
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn property_set_different_type() {
let mut prop = Property {
prop: Proptype::Bool(true),
description: "".into(),
conditions: None,
};
assert!(prop.set_value(Proptype::Bool(false)).is_ok());
assert!(prop.set_value(Proptype::F64(3.14)).is_err());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment