<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using NRules.Aggregators;
using Xunit;

namespace NRules.Tests.Aggregators
{
    public class FlatteningAggregatorTest : AggregatorTest
    {
        [Fact]
        public void Add_Facts_AddedResult()
        {
            //Arrange
            var target = CreateTarget();

            //Act
            var facts = AsFact(new TestFact(1, "value11", "value12"), new TestFact(2, "value21", "value22"));
            var result = target.Add(EmptyTuple(), facts).ToArray();

            //Assert
            Assert.Equal(4, result.Length);
            Assert.Equal(AggregationAction.Added, result[0].Action);
            Assert.Equal("value11", result[0].Aggregate);
            Assert.Equal(AggregationAction.Added, result[1].Action);
            Assert.Equal("value12", result[1].Aggregate);
            Assert.Equal(AggregationAction.Added, result[2].Action);
            Assert.Equal("value21", result[2].Aggregate);
            Assert.Equal(AggregationAction.Added, result[3].Action);
            Assert.Equal("value22", result[3].Aggregate);
        }

        [Fact]
        public void Add_NoFacts_EmptyResult()
        {
            //Arrange
            var target = CreateTarget();

            //Act
            var facts = AsFact(new TestFact[0]);
            var result = target.Add(EmptyTuple(), facts).ToArray();

            //Assert
            Assert.Equal(0, result.Length);
        }

        [Fact]
        public void Modify_ExistingFactsSameIdentity_ModifiedResult()
        {
            //Arrange
            var target = CreateTarget();
            var facts = AsFact(new TestFact(1, "value11", "value12"), new TestFact(2, "value21", "value22"));
            target.Add(EmptyTuple(), facts);

            //Act
            var toUpdate = facts.Take(1).ToArray();
            var result = target.Modify(EmptyTuple(), toUpdate).ToArray();

            //Assert
            Assert.Equal(2, result.Length);
            Assert.Equal(AggregationAction.Modified, result[0].Action);
            Assert.Equal("value11", result[0].Aggregate);
            Assert.Equal(AggregationAction.Modified, result[1].Action);<commit_msg>Add test for flattening duplicates<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using NRules.Aggregators;
using Xunit;

namespace NRules.Tests.Aggregators
{
    public class FlatteningAggregatorTest : AggregatorTest
    {
        [Fact]
        public void Add_Facts_AddedResult()
        {
            //Arrange
            var target = CreateTarget();

            //Act
            var facts = AsFact(new TestFact(1, "value11", "value12"), new TestFact(2, "value21", "value22"));
            var result = target.Add(EmptyTuple(), facts).ToArray();

            //Assert
            Assert.Equal(4, result.Length);
            Assert.Equal(AggregationAction.Added, result[0].Action);
            Assert.Equal("value11", result[0].Aggregate);
            Assert.Equal(AggregationAction.Added, result[1].Action);
            Assert.Equal("value12", result[1].Aggregate);
            Assert.Equal(AggregationAction.Added, result[2].Action);
            Assert.Equal("value21", result[2].Aggregate);
            Assert.Equal(AggregationAction.Added, result[3].Action);
            Assert.Equal("value22", result[3].Aggregate);
        }

        [Fact]
        public void Add_FactsWithDuplicates_AddedDistinctResult()
        {
            //Arrange
            var target = CreateTarget();

            //Act
            var facts = AsFact(new TestFact(1, "value11", "value12", "value12"), new TestFact(2, "value21", "value21", "value22"));
            var result = target.Add(EmptyTuple(), facts).ToArray();

            //Assert
            Assert.Equal(4, result.Length);
            Assert.Equal(AggregationAction.Added, result[0].Action);
            Assert.Equal("value11", result[0].Aggregate);
            Assert.Equal(AggregationAction.Added, result[1].Action);
            Assert.Equal("value12", result[1].Aggregate);
            Assert.Equal(AggregationAction.Added, result[2].Action);
            Assert.Equal("value21", result[2].Aggregate);
            Assert.Equal(AggregationAction.Added, result[3].Action);
            Assert.Equal("value22", result[3].Aggregate);
        }

        [Fact]
        public void Add_NoFacts_EmptyResult()
        {
            //Arrange
            var target = CreateTarget();

            //Act
            var facts = AsFact(new TestFact[0]);
            var result = target.Add(EmptyTuple(), facts).ToArray();

            //Assert
            Assert.Equal(0, result.Length);
        }

        [Fact]
        public void Modify_ExistingFactsSameIdentity_ModifiedResult()
        {
            //Arrange
            var target = CreateTarget();
            var facts = AsFact(new TestFact(1, "value11", "value12"), new TestFact(2, "value21", "value22"));
            target.Add(EmptyTuple(), facts);

            //Act
            var toUpdate = facts.Take(1).ToArray();
            var result = target.Modify(EmptyTuple(), toUpdate).ToArray();

            //Assert
            Assert.Equal(2, result.Length);
            Assert.Equal(AggregationAction.Modified, result[0].Action);
            Assert.Equal("value11", result[0].Aggregate);
            Assert.Equal(AggregationAction.Modified, result[1].Action);
{'fraction_non_alphanumeric': 0.12907984510418588, 'fraction_numerical': 0.02268117278259266, 'mean_word_length': 2.1479976784677888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2562262', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1470, 'n_words': 277}