<commit_before>﻿using System;
using System.Diagnostics;
using System.Threading;
using NUnit.Framework;
using Theraot.Collections.ThreadSafe;
using Theraot.Threading.Needles;

namespace Tests.Theraot.Threading.Needles
{
    [TestFixture]
    class LockableNeedleTest
    {
        [Test]
        public void SimpleTest()
        {
            var context = new LockableContext(16);
            var needle = new LockableNeedle<int>(5, context);

            Assert.AreEqual(5, needle.Value);
            Assert.Throws<InvalidOperationException>(() => needle.Value = 7);

            using (context.Enter())
            {
                needle.Capture();
                Assert.IsTrue(needle.Check());
                Assert.DoesNotThrow(() => needle.Value = 7);
                Assert.AreEqual(7, needle.Value);
            }

            Assert.Throws<InvalidOperationException>(() => needle.Value = 9);
        }

        [Test]
        public void TwoThreadsSet()<commit_msg>Nested test of LockableNeedles<commit_after>﻿using System;
using System.Diagnostics;
using System.Threading;
using NUnit.Framework;
using Theraot.Collections.ThreadSafe;
using Theraot.Threading.Needles;

namespace Tests.Theraot.Threading.Needles
{
    [TestFixture]
    class LockableNeedleTest
    {
        [Test]
        public void SimpleTest()
        {
            var context = new LockableContext(16);
            var needle = new LockableNeedle<int>(5, context);

            Assert.AreEqual(5, needle.Value);
            Assert.Throws<InvalidOperationException>(() => needle.Value = 7);

            using (context.Enter())
            {
                needle.Capture();
                Assert.IsTrue(needle.Check());
                Assert.DoesNotThrow(() => needle.Value = 7);
                Assert.AreEqual(7, needle.Value);
            }

            Assert.Throws<InvalidOperationException>(() => needle.Value = 9);
        }

        [Test]
        public void Nested()
        {
            var context = new LockableContext(16);
            var needle = new LockableNeedle<int>(5, context);

            Assert.AreEqual(5, needle.Value);
            Assert.Throws<InvalidOperationException>(() => needle.Value = 7);

            using (context.Enter())
            {
                needle.Capture();
                Assert.IsTrue(needle.Check());
                Assert.DoesNotThrow(() => needle.Value = 7);
                Assert.AreEqual(7, needle.Value);
                using (context.Enter())
                {
                    // You can recapture
                    needle.Capture();
                    Assert.IsTrue(needle.Check());
                    Assert.DoesNotThrow(() => needle.Value = 9);
                    Assert.AreEqual(9, needle.Value);
                }
                using (context.Enter())
                {
                    // There is no need to recapture
                    Assert.IsTrue(needle.Check());
                    Assert.DoesNotThrow(() => needle.Value = 11);
                    Assert.AreEqual(11, needle.Value);
                }
            }
        }

        [Test]
        public void TwoThreadsSet()
{'fraction_non_alphanumeric': 0.11244852708267343, 'fraction_numerical': 0.009185936015204309, 'mean_word_length': 1.6471081307627828, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266927', 'n_tokens_mistral': 849, 'n_tokens_neox': 805, 'n_words': 157}