nonscalar/
lib.rs

1mod vector;
2mod complex;
3
4pub use vector::*;
5pub use complex::*;
6
7#[cfg(test)]
8mod tests {
9    use crate::*;
10
11    #[test]
12    fn test_complex_arithmetic() {
13        let c1 = Complex::new(1, 4);
14        let c2 = Complex::new(7, 8);
15        
16        // Addition
17        let mut c3 = c1 + c2;
18
19        assert_eq!(c3, Complex::new(8, 12));
20
21        c3 += c1;
22
23        assert_eq!(c3, Complex::new(9, 16));
24
25        // Subtraction
26        let mut c3 = c1 - c2;
27
28        assert_eq!(c3, Complex::new(-6, -4));
29
30        c3 -= c1;
31
32        assert_eq!(c3, Complex::new(-7, -8));
33
34        // Multiplication
35        let mut c3 = c1 * c2;
36
37        assert_eq!(c3, Complex::new(-25, 36));
38
39        c3 *= c1;
40
41        assert_eq!(c3, Complex::new(-169, -64));
42
43        // Division
44        let c1 = Complex::new(2.0, 4.0);
45        let c2 = Complex::new(6.0, 8.0);
46
47        let mut c3 = c1 / c2;
48
49        assert_eq!(c3, Complex::new(0.44, 0.08));
50
51        c3 /= c1;
52
53        assert_eq!(c3, Complex::new(0.06, -0.08));
54    }
55
56    #[test]
57    fn test_complex_conjugate() {
58        let c = Complex::new(1, 2);
59        let d = c.conj();
60
61        assert_eq!(d, Complex::new(1, -2));
62    }
63
64
65}