<commit_before>﻿using Binance.Api;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;

namespace Binance.Tests.Api
{
    public class RateLimiterTest
    {
        [Fact]
        public void ConfigureThrows()
        {
            var rateLimiter = new RateLimiter();

            Assert.Throws<ArgumentException>("count", () => rateLimiter.Configure(-1, TimeSpan.FromSeconds(1)));
            Assert.Throws<ArgumentException>("count", () => rateLimiter.Configure(0, TimeSpan.FromSeconds(1)));
        }

        [Fact]
        public void Configure()
        {
            const int count = 3;
            var duration = TimeSpan.FromSeconds(3);

            var enabled = !RateLimiter.EnabledDefault;

            var rateLimiter = new RateLimiter
            {
                IsEnabled = enabled
            };
            rateLimiter.Configure(count, duration);

            Assert.Equal(count, rateLimiter.Count);
            Assert.Equal(duration, rateLimiter.Duration);
            Assert.Equal(enabled, rateLimiter.IsEnabled);
        }

        [Fact]
        public async Task RateLimit()
        {
            const int count = 3;
            const int intervals = 2;

            var rateLimiter = new RateLimiter
            {
                IsEnabled = true
            };
            rateLimiter.Configure(count, TimeSpan.FromSeconds(1));

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < count * intervals + 1; i++)
                await rateLimiter.DelayAsync();

            stopwatch.Stop();

            Assert.True(stopwatch.ElapsedMilliseconds > rateLimiter.Duration.TotalMilliseconds * intervals);
            Assert.True(stopwatch.ElapsedMilliseconds < rateLimiter.Duration.TotalMilliseconds * (intervals + 0.5));
        }<commit_msg>Update unit test<commit_after>﻿using Binance.Api;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;

namespace Binance.Tests.Api
{
    public class RateLimiterTest
    {
        [Fact]
        public void ConfigureThrows()
        {
            var rateLimiter = new RateLimiter();

            Assert.Throws<ArgumentException>("count", () => rateLimiter.Configure(-1, TimeSpan.FromSeconds(1)));
            Assert.Throws<ArgumentException>("count", () => rateLimiter.Configure(0, TimeSpan.FromSeconds(1)));
        }

        [Fact]
        public void Configure()
        {
            const int count = 3;
            var duration = TimeSpan.FromSeconds(3);

            var enabled = !RateLimiter.EnabledDefault;

            var rateLimiter = new RateLimiter
            {
                IsEnabled = enabled
            };
            rateLimiter.Configure(count, duration);

            Assert.Equal(count, rateLimiter.Count);
            Assert.Equal(duration, rateLimiter.Duration);
            Assert.Equal(enabled, rateLimiter.IsEnabled);
        }

        [Fact]
        public async Task RateLimit()
        {
            const int count = 3;
            const int intervals = 2;

            var rateLimiter = new RateLimiter
            {
                IsEnabled = true
            };
            rateLimiter.Configure(count, TimeSpan.FromSeconds(1));

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < count * intervals + 1; i++)
                await rateLimiter.DelayAsync();

            stopwatch.Stop();

            Assert.True(stopwatch.ElapsedMilliseconds > rateLimiter.Duration.TotalMilliseconds * (intervals - 0.1));
            Assert.False(stopwatch.ElapsedMilliseconds > rateLimiter.Duration.TotalMilliseconds * (intervals + 0.1));
        }
{'fraction_non_alphanumeric': 0.09983633387888707, 'fraction_numerical': 0.007637752318603383, 'mean_word_length': 1.9265762170790104, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, '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': '2754266', 'n_tokens_mistral': 986, 'n_tokens_neox': 949, 'n_words': 203}