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

using Parseq;
using Parseq.Combinators;

namespace Parseq.Test
{
    public static class Testing
    {
        internal static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
        {
            foreach (var i in enumerable)
                action(i);
        }

        internal static void ForEach<T>(this IEnumerable<T> enumerable, Action<T, Int32> action)
        {
            var index = 0;
            foreach (var i in enumerable)
                action(i, index++);
        }

        public static Parser<TToken, IEnumerable<TResult>> ExpectSuccess<TToken, TResult>(this Parser<TToken, IEnumerable<TResult>> parser, IEnumerable<TResult> expected)
            where TToken : IEquatable<TToken>
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenSuccess(actual => actual.Zip(expected, Tuple.Create).ForEach(t => Assert.AreEqual(t.Item1, t.Item2)))
                .DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails));
        }

        public static Parser<TToken, TResult> ExpectSuccess<TToken, TResult>(this Parser<TToken, TResult> parser, TResult expected)
            where TToken : IEquatable<TToken>
        {
            if(parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenSuccess(actual => Assert.AreEqual(expected, actual))
                .DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails));                
        }

        public static Parser<TToken, TResult> ExpectSuccess<TToken, TResult>(this Parser<TToken, TResult> parser)
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails)); 
        }

        public static Parser<TToken, TResult> ExpectFailure<TToken, TResult>(this Parser<TToken, TResult> parser)
        {
            if (parser == null)
                throw new ArgumentNullException("parser");
<commit_msg>Fix the two sequence's determination of equivalence in `ExpectSuccess`<commit_after>﻿using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Parseq;
using Parseq.Combinators;

namespace Parseq.Test
{
    public static class Testing
    {
        internal static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
        {
            foreach (var i in enumerable)
                action(i);
        }

        internal static void ForEach<T>(this IEnumerable<T> enumerable, Action<T, Int32> action)
        {
            var index = 0;
            foreach (var i in enumerable)
                action(i, index++);
        }

        public static Parser<TToken, IEnumerable<TResult>> ExpectSuccess<TToken, TResult>(this Parser<TToken, IEnumerable<TResult>> parser, IEnumerable<TResult> expected)
            where TToken : IEquatable<TToken>
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenSuccess(actual => Assert.IsTrue(expected.SequenceEqual(actual)))
                .DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails));
        }

        public static Parser<TToken, TResult> ExpectSuccess<TToken, TResult>(this Parser<TToken, TResult> parser, TResult expected)
            where TToken : IEquatable<TToken>
        {
            if(parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenSuccess(actual => Assert.AreEqual(expected, actual))
                .DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails));                
        }

        public static Parser<TToken, TResult> ExpectSuccess<TToken, TResult>(this Parser<TToken, TResult> parser)
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

            return parser.DoWhenFailure(() => Assert.Fail())
                .DoWhenError(error => Assert.Fail(error.MessageDetails)); 
        }

        public static Parser<TToken, TResult> ExpectFailure<TToken, TResult>(this Parser<TToken, TResult> parser)
        {
            if (parser == null)
                throw new ArgumentNullException("parser");

{'fraction_non_alphanumeric': 0.10451255853554704, 'fraction_numerical': 0.0017028522775649213, 'mean_word_length': 2.3781452192667145, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 66, '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': '6849369', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1211, 'n_words': 291}