<commit_before>﻿//-----------------------------------------------------------------------
// <copyright file="VirtualClockTest.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace TimerSample.Test.Unit
{
    using System;
    using System.Threading;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class VirtualClockTest
    {
        [TestMethod]
        public void ShouldInvokeCreatedActionOnSleepAfterEndpointOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval + TimeSpan.FromTicks(interval.Ticks / 4));

            Assert.AreEqual(1, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(2, invokeCount);
        }

        [TestMethod]
        public void ShouldNotInvokeCreatedActionOnSleepAtEndpointOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(1, invokeCount);
        }

        [TestMethod]
        public void ShouldNotInvokeCreatedActionOnSleepAtBeginningOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(0, invokeCount);
            
            clock.Sleep(TimeSpan.FromTicks(interval.Ticks / 4));

            Assert.AreEqual(1, invokeCount);
        }
    }
}
<commit_msg>VirtualClock should invoke created action on sleep for very small contained interval<commit_after>﻿//-----------------------------------------------------------------------
// <copyright file="VirtualClockTest.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace TimerSample.Test.Unit
{
    using System;
    using System.Threading;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class VirtualClockTest
    {
        [TestMethod]
        public void ShouldInvokeCreatedActionOnSleepAfterEndpointOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval + TimeSpan.FromTicks(interval.Ticks / 4));

            Assert.AreEqual(1, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(2, invokeCount);
        }

        [TestMethod]
        public void ShouldNotInvokeCreatedActionOnSleepAtEndpointOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(1, invokeCount);
        }

        [TestMethod]
        public void ShouldNotInvokeCreatedActionOnSleepAtBeginningOfInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval);

            Assert.AreEqual(0, invokeCount);
            
            clock.Sleep(TimeSpan.FromTicks(interval.Ticks / 4));

            Assert.AreEqual(1, invokeCount);
        }

        [TestMethod]
        public void ShouldInvokeCreatedActionOnSleepForVerySmallContainedInterval()
        {
            VirtualClock clock = new VirtualClock();
            int invokeCount = 0;
            TimeSpan interval = TimeSpan.FromSeconds(1.0d);

            clock.CreateAction(interval, () => ++invokeCount);

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(interval - TimeSpan.FromTicks(interval.Ticks / 8));

            Assert.AreEqual(0, invokeCount);

            clock.Sleep(TimeSpan.FromTicks(interval.Ticks / 4));

            Assert.AreEqual(1, invokeCount);
        }
    }
}

{'fraction_non_alphanumeric': 0.15298507462686567, 'fraction_numerical': 0.009426551453260016, 'mean_word_length': 1.799890049477735, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '375532', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1225, 'n_words': 234}