<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Swordfish.NET.Collections;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Swordfish.NET.UnitTestV3
{
    [TestClass]
    public class ConcurrentObservableDictionaryTests
    {
        [TestMethod]
        public void AddRangeTest()
        {
            // There was an issue with ConcurrentObservableDictionary.AddMany throwing an
            // exception when passed an IEnumerable.

            IEnumerable<KeyValuePair<string,string>> GetIEnumerable()
            {
                for(int i=0; i<10; ++i)
                {
                    yield return new KeyValuePair<string, string>(i.ToString(), i.ToString());
                }
            }

            var itemsToAdd = GetIEnumerable();
            var dictionary = new ConcurrentObservableDictionary<string,string>();
            dictionary.AddRange(itemsToAdd);

            Assert.IsTrue(dictionary.Count == itemsToAdd.Count(), "Right number of items");
        }

        [TestMethod]
        public void AddTest()
        {

            int testCollectionCount = 10;
            int itemsPerCollection = 200_000;
            var sourceCollections = new List<List<int>>();

            // Use a fixed seed for consistency in results
            Random random = new Random(1);

            // Create 10 test sets
            for (int collection = 0; collection < testCollectionCount; ++collection)
            {
                List<int> sourceCollection = new List<int>();
                for (int item = 0; item < itemsPerCollection; ++item)
                {
                    // Ensure we have some duplicates by picking a random number
                    // less than half the number of items.
                    sourceCollection.Add(random.Next(itemsPerCollection / 2));
                }
                sourceCollections.Add(sourceCollection);<commit_msg>Added another test for issue #16<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Swordfish.NET.Collections;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Swordfish.NET.UnitTestV3
{
    [TestClass]
    public class ConcurrentObservableDictionaryTests
    {
        [TestMethod]
        public void AddRangeTest()
        {
            // There was an issue with ConcurrentObservableDictionary.AddMany throwing an
            // exception when passed an IEnumerable.

            IEnumerable<KeyValuePair<string,string>> GetIEnumerable()
            {
                for(int i=0; i<10; ++i)
                {
                    yield return new KeyValuePair<string, string>(i.ToString(), i.ToString());
                }
            }

            var itemsToAdd = GetIEnumerable();
            var dictionary1 = new ConcurrentObservableDictionary<string,string>();
            dictionary1.AddRange(itemsToAdd);

            Assert.IsTrue(dictionary1.Count == itemsToAdd.Count(), "Right number of items");

            var sourceDictionary = itemsToAdd.ToDictionary(a => a.Key, b => b.Value);
            var dictionary2 = new ConcurrentObservableDictionary<string, string>();
            dictionary2.AddRange(sourceDictionary);

            Assert.IsTrue(dictionary2.Count == sourceDictionary.Count, "Right number of items");
        }

        [TestMethod]
        public void AddTest()
        {

            int testCollectionCount = 10;
            int itemsPerCollection = 200_000;
            var sourceCollections = new List<List<int>>();

            // Use a fixed seed for consistency in results
            Random random = new Random(1);

            // Create 10 test sets
            for (int collection = 0; collection < testCollectionCount; ++collection)
            {
                List<int> sourceCollection = new List<int>();
                for (int item = 0; item < itemsPerCollection; ++item)
                {
                    // Ensure we have some duplicates by picking a random number
                    // less than half the number of items.
                    sourceCollection.Add(random.Next(itemsPerCollection / 2));
                }
                sourceCollections.Add(sourceCollection);
{'fraction_non_alphanumeric': 0.08591715976331361, 'fraction_numerical': 0.010414201183431953, 'mean_word_length': 1.9225449515905948, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 22, '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': '5541809', 'n_tokens_mistral': 1054, 'n_tokens_neox': 977, 'n_words': 276}