use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub struct GraphinaException {
pub message: String,
}
impl GraphinaException {
pub fn new(message: &str) -> Self {
GraphinaException {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaException {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaException: {}", self.message)
}
}
impl Error for GraphinaException {}
#[derive(Debug)]
pub struct GraphinaError {
pub message: String,
}
impl GraphinaError {
pub fn new(message: &str) -> Self {
GraphinaError {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaError: {}", self.message)
}
}
impl Error for GraphinaError {}
#[derive(Debug)]
pub struct GraphinaPointlessConcept {
pub message: String,
}
impl GraphinaPointlessConcept {
pub fn new(message: &str) -> Self {
GraphinaPointlessConcept {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaPointlessConcept {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaPointlessConcept: {}", self.message)
}
}
impl Error for GraphinaPointlessConcept {}
#[derive(Debug)]
pub struct GraphinaAlgorithmError {
pub message: String,
}
impl GraphinaAlgorithmError {
pub fn new(message: &str) -> Self {
GraphinaAlgorithmError {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaAlgorithmError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaAlgorithmError: {}", self.message)
}
}
impl Error for GraphinaAlgorithmError {}
#[derive(Debug)]
pub struct GraphinaUnfeasible {
pub message: String,
}
impl GraphinaUnfeasible {
pub fn new(message: &str) -> Self {
GraphinaUnfeasible {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaUnfeasible {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaUnfeasible: {}", self.message)
}
}
impl Error for GraphinaUnfeasible {}
#[derive(Debug)]
pub struct GraphinaNoPath {
pub message: String,
}
impl GraphinaNoPath {
pub fn new(message: &str) -> Self {
GraphinaNoPath {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaNoPath {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaNoPath: {}", self.message)
}
}
impl Error for GraphinaNoPath {}
#[derive(Debug)]
pub struct GraphinaNoCycle {
pub message: String,
}
impl GraphinaNoCycle {
pub fn new(message: &str) -> Self {
GraphinaNoCycle {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaNoCycle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaNoCycle: {}", self.message)
}
}
impl Error for GraphinaNoCycle {}
#[derive(Debug)]
pub struct NodeNotFound {
pub message: String,
}
impl NodeNotFound {
pub fn new(message: &str) -> Self {
NodeNotFound {
message: message.to_string(),
}
}
}
impl fmt::Display for NodeNotFound {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "NodeNotFound: {}", self.message)
}
}
impl Error for NodeNotFound {}
#[derive(Debug)]
pub struct HasACycle {
pub message: String,
}
impl HasACycle {
pub fn new(message: &str) -> Self {
HasACycle {
message: message.to_string(),
}
}
}
impl fmt::Display for HasACycle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "HasACycle: {}", self.message)
}
}
impl Error for HasACycle {}
#[derive(Debug)]
pub struct GraphinaUnbounded {
pub message: String,
}
impl GraphinaUnbounded {
pub fn new(message: &str) -> Self {
GraphinaUnbounded {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaUnbounded {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaUnbounded: {}", self.message)
}
}
impl Error for GraphinaUnbounded {}
#[derive(Debug)]
pub struct GraphinaNotImplemented {
pub message: String,
}
impl GraphinaNotImplemented {
pub fn new(message: &str) -> Self {
GraphinaNotImplemented {
message: message.to_string(),
}
}
}
impl fmt::Display for GraphinaNotImplemented {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GraphinaNotImplemented: {}", self.message)
}
}
impl Error for GraphinaNotImplemented {}
#[derive(Debug)]
pub struct AmbiguousSolution {
pub message: String,
}
impl AmbiguousSolution {
pub fn new(message: &str) -> Self {
AmbiguousSolution {
message: message.to_string(),
}
}
}
impl fmt::Display for AmbiguousSolution {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "AmbiguousSolution: {}", self.message)
}
}
impl Error for AmbiguousSolution {}
#[derive(Debug)]
pub struct ExceededMaxIterations {
pub message: String,
}
impl ExceededMaxIterations {
pub fn new(message: &str) -> Self {
ExceededMaxIterations {
message: message.to_string(),
}
}
}
impl fmt::Display for ExceededMaxIterations {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ExceededMaxIterations: {}", self.message)
}
}
impl Error for ExceededMaxIterations {}
#[derive(Debug)]
pub struct PowerIterationFailedConvergence {
pub num_iterations: usize,
pub message: String,
}
impl PowerIterationFailedConvergence {
pub fn new(num_iterations: usize, message: &str) -> Self {
PowerIterationFailedConvergence {
num_iterations,
message: message.to_string(),
}
}
}
impl fmt::Display for PowerIterationFailedConvergence {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"PowerIterationFailedConvergence after {} iterations: {}",
self.num_iterations, self.message
)
}
}
impl Error for PowerIterationFailedConvergence {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_graphina_exception_display() {
let err = GraphinaException::new("Generic error");
assert_eq!(format!("{}", err), "GraphinaException: Generic error");
}
#[test]
fn test_graphina_error_display() {
let err = GraphinaError::new("Serious error");
assert_eq!(format!("{}", err), "GraphinaError: Serious error");
}
#[test]
fn test_pointless_concept_display() {
let err = GraphinaPointlessConcept::new("Null graph provided");
assert_eq!(
format!("{}", err),
"GraphinaPointlessConcept: Null graph provided"
);
}
#[test]
fn test_algorithm_error_display() {
let err = GraphinaAlgorithmError::new("Unexpected termination");
assert_eq!(
format!("{}", err),
"GraphinaAlgorithmError: Unexpected termination"
);
}
#[test]
fn test_unfeasible_display() {
let err = GraphinaUnfeasible::new("No feasible solution");
assert_eq!(
format!("{}", err),
"GraphinaUnfeasible: No feasible solution"
);
}
#[test]
fn test_no_path_display() {
let err = GraphinaNoPath::new("No path exists");
assert_eq!(format!("{}", err), "GraphinaNoPath: No path exists");
}
#[test]
fn test_no_cycle_display() {
let err = GraphinaNoCycle::new("No cycle found");
assert_eq!(format!("{}", err), "GraphinaNoCycle: No cycle found");
}
#[test]
fn test_node_not_found_display() {
let err = NodeNotFound::new("Node missing");
assert_eq!(format!("{}", err), "NodeNotFound: Node missing");
}
#[test]
fn test_has_a_cycle_display() {
let err = HasACycle::new("Cycle detected");
assert_eq!(format!("{}", err), "HasACycle: Cycle detected");
}
#[test]
fn test_unbounded_display() {
let err = GraphinaUnbounded::new("Optimization unbounded");
assert_eq!(
format!("{}", err),
"GraphinaUnbounded: Optimization unbounded"
);
}
#[test]
fn test_not_implemented_display() {
let err = GraphinaNotImplemented::new("Feature not available");
assert_eq!(
format!("{}", err),
"GraphinaNotImplemented: Feature not available"
);
}
#[test]
fn test_ambiguous_solution_display() {
let err = AmbiguousSolution::new("Multiple solutions exist");
assert_eq!(
format!("{}", err),
"AmbiguousSolution: Multiple solutions exist"
);
}
#[test]
fn test_exceeded_max_iterations_display() {
let err = ExceededMaxIterations::new("Iteration limit exceeded");
assert_eq!(
format!("{}", err),
"ExceededMaxIterations: Iteration limit exceeded"
);
}
#[test]
fn test_power_iteration_failed_convergence_display() {
let err = PowerIterationFailedConvergence::new(150, "Failed to converge");
assert_eq!(
format!("{}", err),
"PowerIterationFailedConvergence after 150 iterations: Failed to converge"
);
}
}