fn vector_clock()

in src/runtime/task/clock.rs [88:131]


    fn vector_clock() {
        let v1 = VectorClock::new_from(&[1, 2, 3, 4]);
        let v2 = VectorClock::new_from(&[1, 2, 4, 5]);
        let v3 = VectorClock::new_from(&[1, 2, 3, 1]);
        let v4 = VectorClock::new_from(&[1, 2, 4, 1]);
        let v5 = VectorClock::new_from(&[1, 2, 3, 4]);
        assert!(v1 < v2 && v1 > v3 && v1 == v5);
        assert!(v2 > v3 && v2 > v4);
        assert!(v3 < v4);
        assert_eq!(v1.partial_cmp(&v4), None);

        let v1 = VectorClock::new_from(&[1, 2, 3, 4]);
        let v2 = VectorClock::new_from(&[1, 2, 2]);
        let v3 = VectorClock::new_from(&[1, 2, 3]);
        let v4 = VectorClock::new_from(&[1, 2, 4]);
        assert!(v1 > v2);
        assert!(v1 > v3);
        assert_eq!(v1.partial_cmp(&v4), None);

        let v1 = VectorClock::new_from(&[]);
        let v2 = VectorClock::new_from(&[1]);
        assert!(v1 < v2);

        let v1 = VectorClock::new_from(&[1, 2, 1]);
        let v2 = VectorClock::new_from(&[1, 3]);
        let v3 = VectorClock::new_from(&[1, 1, 1, 2]);
        let v4 = VectorClock::new_from(&[1, 1, 2]);

        let mut v = v1.clone();
        v.update(&v2);
        assert_eq!(v, VectorClock::new_from(&[1, 3, 1]));

        let mut v = v1.clone();
        v.update(&v3);
        assert_eq!(v, VectorClock::new_from(&[1, 2, 1, 2]));

        let mut v = v1.clone();
        v.update(&v4);
        assert_eq!(v, VectorClock::new_from(&[1, 2, 2]));

        let mut v = v1.clone();
        v.update(&VectorClock::new());
        assert_eq!(v, v1);
    }