use imagnum::*;
#[test]
fn test_create_complex() {
let z = create_complex("3", "4");
assert_eq!(z.to_string(), "3.0 + 4.0i");
}
#[test]
fn test_complex_addition() {
let z1 = create_complex("3", "4");
let z2 = create_complex("1", "2");
let result = (z1 + z2).unwrap();
assert_eq!(result.to_string(), "4.0 + 6.0i");
}
#[test]
fn test_complex_subtraction() {
let z1 = create_complex("5", "7");
let z2 = create_complex("2", "3");
let result = (z1 - z2).unwrap();
assert_eq!(result.to_string(), "3.0 + 4.0i");
}
#[test]
fn test_complex_multiplication() {
let z1 = create_complex("3", "2");
let z2 = create_complex("1", "4");
let result = (z1 * z2).unwrap();
assert_eq!(result.to_string(), "-5.0 + 14.0i");
}
#[test]
fn test_complex_division() {
let z1 = create_complex("4", "2");
let z2 = create_complex("3", "-1");
let result = (z1 / z2).unwrap();
assert_eq!(result.to_string(), "1.0 + i");
}
#[test]
fn test_pure_imaginary() {
let z = create_complex("0", "5");
assert_eq!(z.to_string(), "5.0i");
}
#[test]
fn test_pure_real() {
let z = create_complex("7", "0");
assert_eq!(z.to_string(), "7.0");
}
#[test]
fn test_imaginary_unit() {
let i = create_imaginary();
assert_eq!(i.to_string(), "i");
}
#[test]
fn test_negative_imaginary() {
let z = create_complex("0", "-1");
assert_eq!(z.to_string(), "-i");
}
#[test]
fn test_complex_with_negative_imaginary() {
let z = create_complex("3", "-4");
assert_eq!(z.to_string(), "3.0 - 4.0i");
}
#[test]
fn test_complex_real_addition() {
let z = create_complex("3", "4");
let r = create_float("2");
let result = (z + r).unwrap();
assert_eq!(result.to_string(), "5.0 + 4.0i");
}
#[test]
fn test_real_complex_addition() {
let r = create_float("2");
let z = create_complex("3", "4");
let result = (r + z).unwrap();
assert_eq!(result.to_string(), "5.0 + 4.0i");
}
#[test]
fn test_complex_real_multiplication() {
let z = create_complex("3", "4");
let r = create_float("2");
let result = (z * r).unwrap();
assert_eq!(result.to_string(), "6.0 + 8.0i");
}
#[test]
fn test_complex_real_division() {
let z = create_complex("6", "8");
let r = create_float("2");
let result = (z / r).unwrap();
assert_eq!(result.to_string(), "3.0 + 4.0i");
}
#[test]
fn test_real_complex_division() {
let r = create_float("10");
let z = create_complex("3", "4");
let result = (r / z).unwrap();
assert_eq!(result.to_string(), "1.2 - 1.6i");
}
#[test]
fn test_i_squared() {
let i = create_imaginary();
let result = (i.clone() * i).unwrap();
assert_eq!(result.to_string(), "-1.0");
}
#[test]
fn test_complex_conjugate_multiplication() {
let z1 = create_complex("3", "4");
let z2 = create_complex("3", "-4");
let result = (z1 * z2).unwrap();
assert_eq!(result.to_string(), "25.0");
}
#[test]
fn test_complex_zero_addition() {
let z1 = create_complex("3", "4");
let z2 = create_complex("0", "0");
let result = (z1 + z2).unwrap();
assert_eq!(result.to_string(), "3.0 + 4.0i");
}
#[test]
fn test_complex_division_by_real() {
let z = create_complex("8", "6");
let r = create_float("2");
let result = (z / r).unwrap();
assert_eq!(result.to_string(), "4.0 + 3.0i");
}