Skip to content

A new test about *Arc::make_mut() #974

@lryan599

Description

@lryan599

When I was implementing Arc, I found that the testing for *Arc:: make_cut() was not very comprehensive. The documentation only explained that it need to clone an inner value, but did not mention how to update the internal count. I made a mistake during my first implementation. Later, I compared with the standard library and updated the following tests. I believe this will make the test samples in this section more comprehensive.

    #[test]
    fn test_try_make_mut_count() {
        let mut data1 = Arc::new(5);
        let mut data2 = Arc::clone(&data1); // Won't clone inner data
        let mut data3 = Arc::clone(&data1);
        assert_eq!(Arc::count(&data1), 3);
        assert_eq!(Arc::count(&data2), 3);
        assert_eq!(Arc::count(&data3), 3);
        *Arc::make_mut(&mut data1) += 1;
        assert_eq!(Arc::count(&data1), 1);
        assert_eq!(Arc::count(&data2), 2);
        assert_eq!(Arc::count(&data3), 2);
        *Arc::make_mut(&mut data2) *= 2; // clone
        assert_eq!(Arc::count(&data1), 1);
        assert_eq!(Arc::count(&data2), 1);
        assert_eq!(Arc::count(&data3), 1);
        *Arc::make_mut(&mut data3) += 1; // clone
        assert_eq!(Arc::count(&data1), 1);
        assert_eq!(Arc::count(&data2), 1);
        assert_eq!(Arc::count(&data3), 1);
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions