<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Interchange.Tests
{
    public class BasicTests
    {
        [Theory]
        [InlineData(1)]
        [InlineData(2)]
        [InlineData(3)]
        [InlineData(4)]
        [InlineData(5)]
        public async Task ConnectionTest(int clientCount) {
            using (var server = new TestNode()) {
                await server.ListenAsync();

                List<TestNode> clients = new List<TestNode>(clientCount);
                for (int i = 0; i < clientCount; i++) {
                    var client = new TestNode();

                    await client.ConnectAsync();

                    clients.Add(client);

                    var result = await server.ReadState();
                    Assert.Equal(result, TestNodeState.Connected);
                    Assert.True(server.IsStatesQueueEmpty());
                }

                foreach (var client in clients) {
                    client.Dispose();
                }
            }
        }

        public static IEnumerable<object[]> MessageTestPayloads {
            get {
                var latencies = new int[]
                {
                    0, 100, 300, 1000
                };
                var dropPercentages = new int[]
                {
                    0, 20, 40, 60, 80
                };

                foreach (var latency in latencies) {
                    foreach (var dropPercentage in dropPercentages) {
                        yield return new object[] {
                            new byte[][]
                            {
                                new byte[] { 40, 41, 42, 43, 44 },
                            },
                            latency,
                            dropPercentage
                        };

                        yield return new object[] {
                        new byte[][]
                            {
                                new byte[] { 40, 41, 42, 43, 44 },
                                new byte[] { 40, 41, 42, 43, 44, 45 }
                            },
                            latency,
                            dropPercentage
                        };

                        yield return new object[] {
                        new byte[][]
                            {
                                new byte[] { 40, 41, 42, 43, 44 },
                                new byte[] { 40, 41, 42, 43, 44, 45 },
                                new byte[] { 40, 41, 42, 43, 44, 45, 46, 47, 48 }
                            },
                            latency,
                            dropPercentage
                        };
                    }
                }
            }
        }

        [Theory]
        [MemberData(nameof(MessageTestPayloads))]
        public async Task SimpleMessageTest(byte[][] payloads, int latency, int dropPercentage) {
            using (var server = new TestNode()) {
                using (var client = new TestNode(new TestSettings(latency, dropPercentage))) {
                    await server.ListenAsync();
                    await client.ConnectAsync();

                    await SendPayloads(server, client, payloads);

                    await client.DisconnectAsync();
                }
            }
        }

        [Theory]<commit_msg>Only use latency/packet dropping on simple message test to speed up testing<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Interchange.Tests
{
    public class BasicTests
    {
        [Theory]
        [InlineData(1)]
        [InlineData(2)]
        [InlineData(3)]
        [InlineData(4)]
        [InlineData(5)]
        public async Task ConnectionTest(int clientCount) {
            using (var server = new TestNode()) {
                await server.ListenAsync();

                List<TestNode> clients = new List<TestNode>(clientCount);
                for (int i = 0; i < clientCount; i++) {
                    var client = new TestNode();

                    await client.ConnectAsync();

                    clients.Add(client);

                    var result = await server.ReadState();
                    Assert.Equal(result, TestNodeState.Connected);
                    Assert.True(server.IsStatesQueueEmpty());
                }

                foreach (var client in clients) {
                    client.Dispose();
                }
            }
        }

        public static IEnumerable<object[]> MessageTestPayloads() {
            return MessageTestPayloads(new int[] { 0 }, new int[] { 0 });
        }

        public static IEnumerable<object[]> MessageTestPayloads(int[] latencies, int[] dropPercentages) {
            foreach (var latency in latencies) {
                foreach (var dropPercentage in dropPercentages) {
                    yield return new object[] {
                        new byte[][]
                        {
                            new byte[] { 40, 41, 42, 43, 44 },
                        },
                        latency,
                        dropPercentage
                    };

                    yield return new object[] {
                        new byte[][]
                        {
                            new byte[] { 40, 41, 42, 43, 44 },
                            new byte[] { 40, 41, 42, 43, 44, 45 }
                        },
                        latency,
                        dropPercentage
                    };

                    yield return new object[] {
                        new byte[][]
                        {
                            new byte[] { 40, 41, 42, 43, 44 },
                            new byte[] { 40, 41, 42, 43, 44, 45 },
                            new byte[] { 40, 41, 42, 43, 44, 45, 46, 47, 48 }
                        },
                        latency,
                        dropPercentage
                    };
                }
            }
        }

        [Theory]
        [MemberData(nameof(MessageTestPayloads), new int[] { 0, 100, 300, 1000 }, new int[] { 0, 20, 40, 60, 80 })]
        public async Task SimpleMessageTest(byte[][] payloads, int latency, int dropPercentage) {
            using (var server = new TestNode()) {
                using (var client = new TestNode(new TestSettings(latency, dropPercentage))) {
                    await server.ListenAsync();
                    await client.ConnectAsync();

                    await SendPayloads(server, client, payloads);

                    await client.DisconnectAsync();
                }
            }
        }

        [Theory]
{'fraction_non_alphanumeric': 0.09136754672204093, 'fraction_numerical': 0.029368140017798874, 'mean_word_length': 0.9985180794309425, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4184877', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1508, 'n_words': 423}