Change conditional panic to expect
All checks were successful
/ test (pull_request) Successful in 2m21s
All checks were successful
/ test (pull_request) Successful in 2m21s
Use `expect` to communicate that every element should have a column index when `pose` is called. Rewrite the panic messages in the style recommended by the `expect` documentation.
This commit is contained in:
parent
99a9c3ec55
commit
5eeb0935ca
1 changed files with 17 additions and 21 deletions
|
@ -134,12 +134,11 @@ impl Element {
|
||||||
|
|
||||||
impl ProblemPoser for Element {
|
impl ProblemPoser for Element {
|
||||||
fn pose(&self, problem: &mut ConstraintProblem, _elts: &Slab<Element>) {
|
fn pose(&self, problem: &mut ConstraintProblem, _elts: &Slab<Element>) {
|
||||||
if let Some(index) = self.column_index {
|
let index = self.column_index.expect(
|
||||||
problem.gram.push_sym(index, index, 1.0);
|
format!("Element \"{}\" should be indexed before writing problem data", self.id).as_str()
|
||||||
problem.guess.set_column(index, &self.representation.get_clone_untracked());
|
);
|
||||||
} else {
|
problem.gram.push_sym(index, index, 1.0);
|
||||||
panic!("Tried to write problem data from an unindexed element: \"{}\"", self.id);
|
problem.guess.set_column(index, &self.representation.get_clone_untracked());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,14 +201,12 @@ impl ProblemPoser for InversiveDistanceRegulator {
|
||||||
fn pose(&self, problem: &mut ConstraintProblem, elts: &Slab<Element>) {
|
fn pose(&self, problem: &mut ConstraintProblem, elts: &Slab<Element>) {
|
||||||
self.set_point.with_untracked(|set_pt| {
|
self.set_point.with_untracked(|set_pt| {
|
||||||
if let Some(val) = set_pt.value {
|
if let Some(val) = set_pt.value {
|
||||||
let subject_column_indices = self.subjects.map(
|
let [row, col] = self.subjects.map(
|
||||||
|subj| elts[subj].column_index
|
|subj| elts[subj].column_index.expect(
|
||||||
|
"Subjects should be indexed before inversive distance regulator writes problem data"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
if let [Some(row), Some(col)] = subject_column_indices {
|
problem.gram.push_sym(row, col, val);
|
||||||
problem.gram.push_sym(row, col, val);
|
|
||||||
} else {
|
|
||||||
panic!("Tried to write problem data from a regulator with an unindexed subject");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -268,11 +265,10 @@ impl ProblemPoser for HalfCurvatureRegulator {
|
||||||
fn pose(&self, problem: &mut ConstraintProblem, elts: &Slab<Element>) {
|
fn pose(&self, problem: &mut ConstraintProblem, elts: &Slab<Element>) {
|
||||||
self.set_point.with_untracked(|set_pt| {
|
self.set_point.with_untracked(|set_pt| {
|
||||||
if let Some(val) = set_pt.value {
|
if let Some(val) = set_pt.value {
|
||||||
if let Some(col) = elts[self.subject].column_index {
|
let col = elts[self.subject].column_index.expect(
|
||||||
problem.frozen.push(Element::CURVATURE_COMPONENT, col, val);
|
"Subject should be indexed before half-curvature regulator writes problem data"
|
||||||
} else {
|
);
|
||||||
panic!("Tried to write problem data from a regulator with an unindexed subject");
|
problem.frozen.push(Element::CURVATURE_COMPONENT, col, val);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -611,7 +607,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "Tried to write problem data from an unindexed element: \"sphere\"")]
|
#[should_panic(expected = "Element \"sphere\" should be indexed before writing problem data")]
|
||||||
fn unindexed_element_test() {
|
fn unindexed_element_test() {
|
||||||
let _ = create_root(|| {
|
let _ = create_root(|| {
|
||||||
Element::new(
|
Element::new(
|
||||||
|
@ -624,8 +620,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "Tried to write problem data from a regulator with an unindexed subject")]
|
#[should_panic(expected = "Subjects should be indexed before inversive distance regulator writes problem data")]
|
||||||
fn unindexed_subject_test() {
|
fn unindexed_subject_test_inversive_distance() {
|
||||||
let _ = create_root(|| {
|
let _ = create_root(|| {
|
||||||
let mut elts = Slab::new();
|
let mut elts = Slab::new();
|
||||||
let subjects = [0, 1].map(|k| {
|
let subjects = [0, 1].map(|k| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue