Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lryan599 opened this issue Nov 29, 2024 · 0 comments
Open

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

lryan599 opened this issue Nov 29, 2024 · 0 comments
Assignees

Comments

@lryan599
Copy link

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);
    }
@Lee-Janggun Lee-Janggun self-assigned this Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants