clm-kernel 0.0.11

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
use super::*;

    #[test]
    fn test_gcd() {
        assert_eq!(math_gcd(12, 18), 6);
        assert_eq!(math_gcd(18, 12), 6);
        assert_eq!(math_gcd(-8, 12), 4);
        assert_eq!(math_gcd(12, -8), 4);
        assert_eq!(math_gcd(0, 5), 5);
        assert_eq!(math_gcd(5, 0), 5);
        assert_eq!(math_gcd(0, 0), 0);
    }

    #[test]
    fn test_lcm() {
        assert_eq!(math_lcm(4, 6), 12);
        assert_eq!(math_lcm(7, 13), 91);
        assert_eq!(math_lcm(0, 5), 0);
    }

    #[test]
    fn test_solve_nullspace_1() {
        // D = [ -1 ]
        //     [  1 ]
        // Transpose = true => A = [ -1 1 ]
        let matrix = vec![vec![-1], vec![1]];
        let basis = solve_nullspace(&matrix, 2, 1, true);
        assert_eq!(basis.len(), 1);
        assert_eq!(basis[0], vec![1, 1]);
    }

    #[test]
    fn test_precomputed_invariants() {
        let matrix = vec![vec![-1], vec![1]];
        let initial_marking = vec![5, 0];
        let precomputed = PrecomputedInvariants::compile(&matrix, 2, 1, &initial_marking);

        assert_eq!(precomputed.initial_constants, vec![5]);
        // Valid marking [3, 2] -> sum = 5
        assert!(precomputed.verify_marking(&[3, 2]));
        // Invalid marking [3, 3] -> sum = 6 != 5
        assert!(!precomputed.verify_marking(&[3, 3]));

        // Delta for valid transition: [-1, 1] -> dot product = 0
        assert!(precomputed.verify_delta(&[-1, 1]));
        // Delta for invalid transition: [-1, 2] -> dot product = 1 != 0
        assert!(!precomputed.verify_delta(&[-1, 2]));
    }