コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】2 つのコレクションに差集合があれば Test Runner でテスト失敗にするクラス

ソースコード

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace Kogane
{
    internal static class ExceptTester
    {
        public static void Test<T>
        (
            string         message,
            IEnumerable<T> source1,
            IEnumerable<T> source2
        )
        {
            var result = source1
                    .Except( source2 )
                    .ToArray()
                ;

            if ( result.Length <= 0 ) return;

            Assert.Fail
            (
                $@"{message}

{string.Join( "\n", result.Select( x => x.ToString() ) )}"
            );
        }
    }
}

使用例

ExceptTester.Test
(
    "【ここにメッセージ】",
    new[] { 1, 2, 3 },
    new[] { 2, 3 }
);