<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoTest.Core.BuildRunners;
using AutoTest.Core.TestRunners;
using AutoTest.Messages;

namespace AutoTest.Core.Caching.RunResultCache
{
    class RunResultCache : IRunResultCache, IMergeRunResults
    {
        private object _padLock = new object();

        private List<BuildItem> _errors = new List<BuildItem>();
        private List<BuildItem> _warnings = new List<BuildItem>();
        private List<TestItem> _failed = new List<TestItem>();
        private List<TestItem> _ignored = new List<TestItem>();

        public BuildItem[] Errors { get { lock (_padLock) { return _errors.ToArray(); } } }
        public BuildItem[] Warnings { get { lock (_padLock) { return _warnings.ToArray(); } } }
        public TestItem[] Failed { get { lock (_padLock) { return _failed.ToArray(); } } }
        public TestItem[] Ignored { get { lock (_padLock) { return _ignored.ToArray(); } } }

        public void Merge(BuildRunResults results)
        {
            lock (_padLock)
            {
                mergeBuildList(_errors, results.Project, results.Errors);
                mergeBuildList(_warnings, results.Project, results.Warnings);
            }
        }

        public void Merge(TestRunResults results)
        {
            lock (_padLock)
            {
                removeChanged(results);
                mergeTestList(_failed, results.Assembly, results.Project, results.Failed, results.Passed);
                mergeTestList(_ignored, results.Assembly, results.Project, results.Ignored, results.Passed);
            }
        }

        private void mergeBuildList(List<BuildItem> list, string key, BuildMessage[] results)
        {
            list.RemoveAll(e => e.Key.Equals(key));
            foreach (var message in results)
                list.Insert(0, new BuildItem(key, message));
        }

        private void removeChanged(TestRunResults results)
        {
            foreach (var test in results.Passed)
            {<commit_msg>Starting to verify pr item (failing tests)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoTest.Core.BuildRunners;
using AutoTest.Core.TestRunners;
using AutoTest.Messages;

namespace AutoTest.Core.Caching.RunResultCache
{
    class RunResultCache : IRunResultCache, IMergeRunResults
    {
        private object _padLock = new object();

        private List<BuildItem> _errors = new List<BuildItem>();
        private List<BuildItem> _warnings = new List<BuildItem>();
        private List<TestItem> _failed = new List<TestItem>();
        private List<TestItem> _ignored = new List<TestItem>();

        public BuildItem[] Errors { get { lock (_padLock) { return _errors.ToArray(); } } }
        public BuildItem[] Warnings { get { lock (_padLock) { return _warnings.ToArray(); } } }
        public TestItem[] Failed { get { lock (_padLock) { return _failed.ToArray(); } } }
        public TestItem[] Ignored { get { lock (_padLock) { return _ignored.ToArray(); } } }

        public void Merge(BuildRunResults results)
        {
            lock (_padLock)
            {
                mergeBuildList(_errors, results.Project, results.Errors);
                mergeBuildList(_warnings, results.Project, results.Warnings);
            }
        }

        public void Merge(TestRunResults results)
        {
            lock (_padLock)
            {
                removeChanged(results);
                mergeTestList(_failed, results.Assembly, results.Project, results.Failed, results.Passed);
                mergeTestList(_ignored, results.Assembly, results.Project, results.Ignored, results.Passed);
            }
        }

        private void mergeBuildList(List<BuildItem> list, string key, BuildMessage[] results)
        {
            var itemsToRemove = new List<BuildItem>();
            foreach (var item in list)
            {
                var found = false;
                foreach (var message in results)
                {
                    var resultItem = new BuildItem(key, message);
                    if (resultItem.Equals(item))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    itemsToRemove.Add(item);
            }
            foreach (var item in itemsToRemove)
                list.Remove(item);
            foreach (var message in results)
            {
                var item = new BuildItem(key, message);
                if (!list.Contains(item))
                    list.Insert(0, item);
            }
        }

        private void removeChanged(TestRunResults results)
        {
            foreach (var test in results.Passed)
            {
{'fraction_non_alphanumeric': 0.09641532756489493, 'fraction_numerical': 0.00041203131437989287, 'mean_word_length': 2.0061919504643964, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, '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': '3519817', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1226, 'n_words': 313}