<commit_before>﻿using System.Threading.Tasks;
using NUnit.Framework;
using SafeOrbit.Library;
using SafeOrbit.Tests;

namespace SafeOrbit.Memory
{
    [TestFixture]
    public class SafeStringPerformanceTests : TestsFor<ISafeString>
    {
        [Test]
        public async Task GetHashCode_1000Chars_Takes_Less_Than_100ms()
        {
            // Arrange
            const int expectedHigherLimit = 100;
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(new string('m', 1000));

            // Act
            var actualPerformance = Measure(() =>
            {
                _ = sut.ToSafeBytesAsync();
            }, 10);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }


        [Test]
        public async Task ToSafeBytes_1000Chars_Takes_Less_Than_100ms()
        {
            // Arrange
            const int expectedHigherLimit = 100;
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(new string('m', 1000));

            // Act
            var actualPerformance = Measure(() =>
            {
                _ = sut.GetHashCode();
            }, 10);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }

        protected override ISafeString GetSut()
        {
            return new SafeString();
        }
    }
}
<commit_msg>more tests 🤓<commit_after>﻿using System.Threading.Tasks;
using NUnit.Framework;
using SafeOrbit.Library;
using SafeOrbit.Tests;

namespace SafeOrbit.Memory
{
    [TestFixture]
    public class SafeStringPerformanceTests : TestsFor<ISafeString>
    {
        [Test]
        public async Task GetHashCode_1000Chars_TakesLessThan100ms()
        {
            // Arrange
            const int expectedHigherLimit = 100;
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(new string('m', 1000));

            // Act
            var actualPerformance = Measure(() =>
            {
                _ = sut.ToSafeBytesAsync();
            }, 10);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }


        [Test]
        public async Task ToSafeBytes_1000Chars_TakesLessThan100ms()
        {
            // Arrange
            const int expectedHigherLimit = 100;
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(new string('m', 1000));

            // Act
            var actualPerformance = Measure(() =>
            {
                _ = sut.GetHashCode();
            }, 10);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }

        [Test]
        public async Task EqualsAsync_Same1000CharsString_TakesLessThan5000ms()
        {
            // Arrange
            const int expectedHigherLimit = 5000;
            var expected = new string('m', 1000);
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(expected);

            // Act
            var actualPerformance = await MeasureAsync(async () =>
            {
                _ = await sut.EqualsAsync(expected);
            }, 3);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }

        [Test]
        public async Task EqualsAsync_Same1000CharsISafeString_TakesLessThan5000ms()
        {
            // Arrange
            const int expectedHigherLimit = 5000;
            var expectedStr = new string('m', 1000);
            SafeOrbitCore.Current.StartEarly();
            var sut = GetSut();
            await sut.AppendAsync(expectedStr);
            var other = GetSut();
            await other.AppendAsync(expectedStr);

            // Act
            var actualPerformance = await MeasureAsync(async () =>
            {
                _ = await sut.EqualsAsync(other);
            }, 3);

            // Assert
            Assert.That(actualPerformance, Is.LessThanOrEqualTo(expectedHigherLimit));
        }

        protected override ISafeString GetSut()
        {
            return new SafeString();
        }
    }
}

{'fraction_non_alphanumeric': 0.09289121053826936, 'fraction_numerical': 0.022257551669316374, 'mean_word_length': 1.653012048192771, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3111917', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1119, 'n_words': 223}