| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| using System;
|
| using System.Collections.Generic;
|
| using System.Collections.Concurrent;
|
| using System.Linq;
|
| using System.Threading.Tasks;
|
| using System.Threading;
|
| using System.Text;
|
| using System.Text.RegularExpressions;
|
| using System.IO;
|
| using System.Diagnostics;
|
| using System.Reflection;
|
| using System.ComponentModel;
|
| using System.Runtime.CompilerServices;
|
| using System.Text.Json;
|
| using System.Globalization;
|
|
|
| namespace Chahuadev.EmojiCleaner.Test
|
| {
|
|
|
|
|
|
|
|
|
| [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property)]
|
| public class EmojiTestAttribute : Attribute
|
| {
|
|
|
| public string Description { get; set; } = "🧪 Default test";
|
|
|
|
|
| public string Category { get; set; } = "🏷️ General";
|
|
|
|
|
| public int Priority { get; set; } = 1;
|
|
|
|
|
| public string[] Tags { get; set; } = Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
| public EmojiTestAttribute(string description, string category = "🏷️ General")
|
| {
|
| Description = description;
|
| Category = category;
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public record EmojiStatistics(
|
| int TotalEmojis, // 🔢 Total emoji count
|
| int UniqueEmojis, // 🎯 Unique emoji varieties
|
| TimeSpan ProcessingTime, // ⏱️ Time taken for processing
|
| Dictionary<string, int> CategoryBreakdown, // 📊 Category statistics
|
| double EfficiencyScore, // 📈 Processing efficiency
|
| bool Success // ✅ Success indicator
|
| )
|
| {
|
|
|
|
|
|
|
|
|
| public string GenerateReport()
|
| {
|
| var report = new StringBuilder();
|
| report.AppendLine("📊 EMOJI PROCESSING STATISTICS");
|
| report.AppendLine("==============================");
|
| report.AppendLine();
|
| report.AppendLine($"🔢 Total emojis processed: {TotalEmojis}");
|
| report.AppendLine($"🎯 Unique emoji types: {UniqueEmojis}");
|
| report.AppendLine($"⏱️ Processing time: {ProcessingTime.TotalMilliseconds:F2} ms");
|
| report.AppendLine($"📈 Efficiency score: {EfficiencyScore:F2}%");
|
| report.AppendLine($"✅ Success status: {(Success ? "Completed" : "Failed")}");
|
| report.AppendLine();
|
|
|
| if (CategoryBreakdown.Count > 0)
|
| {
|
| report.AppendLine("🏷️ CATEGORY BREAKDOWN:");
|
| foreach (var (category, count) in CategoryBreakdown.OrderByDescending(x => x.Value))
|
| {
|
| var percentage = (double)count / TotalEmojis * 100;
|
| report.AppendLine($" {category}: {count} emojis ({percentage:F1}%)");
|
| }
|
| }
|
|
|
| return report.ToString();
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| public delegate Task<TOutput> EmojiProcessorDelegate<TInput, TOutput>(TInput input, CancellationToken cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
| public interface IEmojiProcessor
|
| {
|
|
|
| string Name { get; }
|
|
|
|
|
| EmojiStatistics Statistics { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Task<ProcessingResult> ProcessContentAsync(string content, CancellationToken cancellationToken = default);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Task<IEnumerable<ProcessingResult>> ProcessBatchAsync(IEnumerable<string> contentItems, CancellationToken cancellationToken = default);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public class ProcessingResult
|
| {
|
|
|
| public string OriginalContent { get; init; } = string.Empty;
|
|
|
|
|
| public string CleanedContent { get; init; } = string.Empty;
|
|
|
|
|
| public IReadOnlyList<string> FoundEmojis { get; init; } = Array.Empty<string>();
|
|
|
|
|
| public IReadOnlyDictionary<string, int> CategoryStats { get; init; } = new Dictionary<string, int>();
|
|
|
|
|
| public TimeSpan ProcessingTime { get; init; }
|
|
|
|
|
| public bool Success { get; init; }
|
|
|
|
|
| public string? ErrorMessage { get; init; }
|
|
|
|
|
| public string ProcessorName { get; init; } = "🔧 Unknown";
|
|
|
|
|
|
|
|
|
|
|
| public double CalculateEfficiency()
|
| {
|
| if (OriginalContent.Length == 0) return 100.0;
|
|
|
| var reductionRatio = (double)FoundEmojis.Count / OriginalContent.Length;
|
| return Math.Min(100.0, reductionRatio * 100.0);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public string GenerateDetailedReport()
|
| {
|
| var report = new StringBuilder();
|
| report.AppendLine("🎯 PROCESSING RESULT REPORT");
|
| report.AppendLine("==========================");
|
| report.AppendLine();
|
| report.AppendLine($"🏷️ Processor: {ProcessorName}");
|
| report.AppendLine($"📝 Original length: {OriginalContent.Length:N0} characters");
|
| report.AppendLine($"🧹 Cleaned length: {CleanedContent.Length:N0} characters");
|
| report.AppendLine($"🔍 Emojis detected: {FoundEmojis.Count:N0}");
|
| report.AppendLine($"⏱️ Processing time: {ProcessingTime.TotalMilliseconds:F2} ms");
|
| report.AppendLine($"📈 Efficiency: {CalculateEfficiency():F2}%");
|
| report.AppendLine($"✅ Status: {(Success ? "Success" : "Failed")}");
|
|
|
| if (!string.IsNullOrEmpty(ErrorMessage))
|
| {
|
| report.AppendLine($"❌ Error: {ErrorMessage}");
|
| }
|
|
|
| return report.ToString();
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| [EmojiTest("🧪 Advanced processor implementation", "🔧 Core")]
|
| public class AdvancedEmojiProcessor : IEmojiProcessor, IDisposable
|
| {
|
|
|
| private static readonly Dictionary<string, Regex> EmojiPatterns = new()
|
| {
|
| ["😀 Faces"] = new Regex(@"[\u{1F600}-\u{1F64F}]", RegexOptions.Compiled | RegexOptions.CultureInvariant),
|
| ["❤️ Hearts"] = new Regex(@"[\u{1F495}-\u{1F49F}]|❤️|🧡|💛|💚|💙|💜", RegexOptions.Compiled | RegexOptions.CultureInvariant),
|
| ["🚀 Objects"] = new Regex(@"[\u{1F680}-\u{1F6FF}]", RegexOptions.Compiled | RegexOptions.CultureInvariant),
|
| ["🌸 Nature"] = new Regex(@"[\u{1F300}-\u{1F5FF}]", RegexOptions.Compiled | RegexOptions.CultureInvariant),
|
| ["🎯 Symbols"] = new Regex(@"[\u{2600}-\u{26FF}]", RegexOptions.Compiled | RegexOptions.CultureInvariant)
|
| };
|
|
|
|
|
| private readonly ConcurrentDictionary<string, List<string>> _emojiCache = new();
|
|
|
|
|
| private long _totalProcessed = 0;
|
| private long _totalEmojisRemoved = 0;
|
| private long _totalProcessingTimeMs = 0;
|
|
|
|
|
| private readonly SemaphoreSlim _semaphore;
|
| private readonly CancellationTokenSource _disposalTokenSource = new();
|
| private bool _disposed = false;
|
|
|
|
|
| public string Name => "🧹 Advanced C# Emoji Processor";
|
|
|
|
|
| public EmojiStatistics Statistics => CalculateCurrentStatistics();
|
|
|
|
|
|
|
|
|
|
|
| public AdvancedEmojiProcessor(int maxConcurrency = Environment.ProcessorCount)
|
| {
|
| _semaphore = new SemaphoreSlim(maxConcurrency, maxConcurrency);
|
| LogMessage("✅ Advanced emoji processor initialized successfully");
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| [EmojiTest("🔧 Core processing method", "⚡ Performance")]
|
| public async Task<ProcessingResult> ProcessContentAsync(string content, CancellationToken cancellationToken = default)
|
| {
|
| if (_disposed) throw new ObjectDisposedException(nameof(AdvancedEmojiProcessor));
|
| if (string.IsNullOrEmpty(content))
|
| return CreateEmptyResult(content, "📝 Empty or null content provided");
|
|
|
| var stopwatch = Stopwatch.StartNew();
|
|
|
| try
|
| {
|
| await _semaphore.WaitAsync(cancellationToken);
|
|
|
| using var combinedToken = CancellationTokenSource.CreateLinkedTokenSource(
|
| cancellationToken, _disposalTokenSource.Token);
|
|
|
| LogMessage($"🔄 Processing content ({content.Length:N0} characters)");
|
|
|
|
|
| var foundEmojis = await DetectEmojisAsync(content, combinedToken.Token);
|
|
|
|
|
| var categoryStats = await GenerateCategoryStatisticsAsync(foundEmojis, combinedToken.Token);
|
|
|
|
|
| var cleanedContent = await RemoveEmojisAsync(content, foundEmojis, combinedToken.Token);
|
|
|
| stopwatch.Stop();
|
|
|
|
|
| Interlocked.Increment(ref _totalProcessed);
|
| Interlocked.Add(ref _totalEmojisRemoved, foundEmojis.Count);
|
| Interlocked.Add(ref _totalProcessingTimeMs, stopwatch.ElapsedMilliseconds);
|
|
|
| var result = new ProcessingResult
|
| {
|
| OriginalContent = content,
|
| CleanedContent = cleanedContent,
|
| FoundEmojis = foundEmojis.AsReadOnly(),
|
| CategoryStats = categoryStats,
|
| ProcessingTime = stopwatch.Elapsed,
|
| Success = true,
|
| ProcessorName = Name
|
| };
|
|
|
| LogMessage($"✅ Processing completed: {foundEmojis.Count} emojis removed in {stopwatch.ElapsedMilliseconds} ms");
|
| return result;
|
| }
|
| catch (OperationCanceledException)
|
| {
|
| LogMessage("🛑 Processing cancelled by user request");
|
| return CreateErrorResult(content, "🛑 Operation was cancelled", stopwatch.Elapsed);
|
| }
|
| catch (Exception ex)
|
| {
|
| LogMessage($"❌ Processing failed: {ex.Message}");
|
| return CreateErrorResult(content, $"❌ Processing error: {ex.Message}", stopwatch.Elapsed);
|
| }
|
| finally
|
| {
|
| _semaphore.Release();
|
| stopwatch.Stop();
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| [EmojiTest("📦 Batch processing capability", "⚡ Performance")]
|
| public async Task<IEnumerable<ProcessingResult>> ProcessBatchAsync(
|
| IEnumerable<string> contentItems,
|
| CancellationToken cancellationToken = default)
|
| {
|
| if (_disposed) throw new ObjectDisposedException(nameof(AdvancedEmojiProcessor));
|
|
|
| var items = contentItems?.ToList() ?? new List<string>();
|
| LogMessage($"📦 Starting batch processing for {items.Count:N0} items");
|
|
|
|
|
| var tasks = items.Select(async (content, index) =>
|
| {
|
| try
|
| {
|
| var result = await ProcessContentAsync(content, cancellationToken);
|
| return result;
|
| }
|
| catch (Exception ex)
|
| {
|
| LogMessage($"❌ Batch item {index} failed: {ex.Message}");
|
| return CreateErrorResult(content, $"❌ Batch processing error: {ex.Message}", TimeSpan.Zero);
|
| }
|
| });
|
|
|
| var results = await Task.WhenAll(tasks);
|
|
|
| var successCount = results.Count(r => r.Success);
|
| var totalEmojis = results.Sum(r => r.FoundEmojis.Count);
|
|
|
| LogMessage($"📦 Batch processing completed: {successCount}/{items.Count} successful, {totalEmojis:N0} emojis removed");
|
|
|
| return results;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private async Task<List<string>> DetectEmojisAsync(string content, CancellationToken cancellationToken)
|
| {
|
|
|
| var cacheKey = content.GetHashCode().ToString();
|
| if (_emojiCache.TryGetValue(cacheKey, out var cachedEmojis))
|
| {
|
| LogMessage("📊 Cache hit for emoji detection");
|
| return new List<string>(cachedEmojis);
|
| }
|
|
|
|
|
| var detectionTasks = EmojiPatterns.Select(async pattern =>
|
| {
|
| return await Task.Run(() =>
|
| {
|
| cancellationToken.ThrowIfCancellationRequested();
|
|
|
| var matches = pattern.Value.Matches(content);
|
| return matches.Cast<Match>().Select(m => m.Value).ToList();
|
| }, cancellationToken);
|
| });
|
|
|
| var categoryResults = await Task.WhenAll(detectionTasks);
|
|
|
|
|
| var allEmojis = categoryResults
|
| .SelectMany(emojis => emojis)
|
| .Distinct()
|
| .OrderBy(emoji => emoji)
|
| .ToList();
|
|
|
|
|
| _emojiCache.TryAdd(cacheKey, new List<string>(allEmojis));
|
|
|
| return allEmojis;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private async Task<Dictionary<string, int>> GenerateCategoryStatisticsAsync(
|
| List<string> emojis,
|
| CancellationToken cancellationToken)
|
| {
|
| var categoryStats = new Dictionary<string, int>();
|
|
|
|
|
| var categoryTasks = EmojiPatterns.Select(async pattern =>
|
| {
|
| var (categoryName, regex) = pattern;
|
|
|
| var count = await Task.Run(() =>
|
| {
|
| cancellationToken.ThrowIfCancellationRequested();
|
| return emojis.Count(emoji => regex.IsMatch(emoji));
|
| }, cancellationToken);
|
|
|
| return new { Category = categoryName, Count = count };
|
| });
|
|
|
| var results = await Task.WhenAll(categoryTasks);
|
|
|
| foreach (var result in results.Where(r => r.Count > 0))
|
| {
|
| categoryStats[result.Category] = result.Count;
|
| }
|
|
|
| return categoryStats;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private async Task<string> RemoveEmojisAsync(
|
| string content,
|
| List<string> emojis,
|
| CancellationToken cancellationToken)
|
| {
|
| return await Task.Run(() =>
|
| {
|
| cancellationToken.ThrowIfCancellationRequested();
|
|
|
| var result = content;
|
|
|
|
|
| foreach (var emoji in emojis)
|
| {
|
| cancellationToken.ThrowIfCancellationRequested();
|
| result = result.Replace(emoji, string.Empty);
|
| }
|
|
|
|
|
| result = Regex.Replace(result, @"\s+", " ").Trim();
|
|
|
| return result;
|
| }, cancellationToken);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private EmojiStatistics CalculateCurrentStatistics()
|
| {
|
| var totalProcessed = Interlocked.Read(ref _totalProcessed);
|
| var totalEmojisRemoved = Interlocked.Read(ref _totalEmojisRemoved);
|
| var totalTimeMs = Interlocked.Read(ref _totalProcessingTimeMs);
|
|
|
| var avgTimeMs = totalProcessed > 0 ? (double)totalTimeMs / totalProcessed : 0.0;
|
| var efficiency = totalProcessed > 0 ? (double)totalEmojisRemoved / totalProcessed * 100 : 0.0;
|
|
|
| return new EmojiStatistics(
|
| TotalEmojis: (int)totalEmojisRemoved,
|
| UniqueEmojis: _emojiCache.Values.SelectMany(v => v).Distinct().Count(),
|
| ProcessingTime: TimeSpan.FromMilliseconds(avgTimeMs),
|
| CategoryBreakdown: new Dictionary<string, int>(),
|
| EfficiencyScore: efficiency,
|
| Success: true
|
| );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private ProcessingResult CreateEmptyResult(string content, string message)
|
| {
|
| return new ProcessingResult
|
| {
|
| OriginalContent = content ?? string.Empty,
|
| CleanedContent = content ?? string.Empty,
|
| FoundEmojis = Array.Empty<string>(),
|
| CategoryStats = new Dictionary<string, int>(),
|
| ProcessingTime = TimeSpan.Zero,
|
| Success = false,
|
| ErrorMessage = message,
|
| ProcessorName = Name
|
| };
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private ProcessingResult CreateErrorResult(string content, string error, TimeSpan elapsed)
|
| {
|
| return new ProcessingResult
|
| {
|
| OriginalContent = content,
|
| CleanedContent = content,
|
| FoundEmojis = Array.Empty<string>(),
|
| CategoryStats = new Dictionary<string, int>(),
|
| ProcessingTime = elapsed,
|
| Success = false,
|
| ErrorMessage = error,
|
| ProcessorName = Name
|
| };
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private void LogMessage(string message)
|
| {
|
| var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
|
| Console.WriteLine($"[{timestamp}] 🕒 {Name}: {message}");
|
| }
|
|
|
|
|
|
|
|
|
| public void Dispose()
|
| {
|
| Dispose(true);
|
| GC.SuppressFinalize(this);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| protected virtual void Dispose(bool disposing)
|
| {
|
| if (!_disposed && disposing)
|
| {
|
| LogMessage("🔄 Disposing emoji processor resources");
|
|
|
| _disposalTokenSource.Cancel();
|
| _semaphore?.Dispose();
|
| _disposalTokenSource?.Dispose();
|
| _emojiCache.Clear();
|
|
|
| _disposed = true;
|
| LogMessage("✅ Emoji processor disposed successfully");
|
| }
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public static class EmojiUtilities
|
| {
|
|
|
| private static readonly Regex AllEmojisPattern = new(
|
| @"[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{2600}-\u{26FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{1F900}-\u{1F9FF}]",
|
| RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static Dictionary<string, int> CountEmojiFrequency(string text)
|
| {
|
| if (string.IsNullOrEmpty(text)) return new Dictionary<string, int>();
|
|
|
| return AllEmojisPattern.Matches(text)
|
| .Cast<Match>()
|
| .GroupBy(m => m.Value)
|
| .ToDictionary(g => g.Key, g => g.Count());
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static List<string> ExtractEmojis(string text)
|
| {
|
| if (string.IsNullOrEmpty(text)) return new List<string>();
|
|
|
| return AllEmojisPattern.Matches(text)
|
| .Cast<Match>()
|
| .Select(m => m.Value)
|
| .Distinct()
|
| .OrderBy(emoji => emoji)
|
| .ToList();
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static bool ContainsEmojis(string text)
|
| {
|
| return !string.IsNullOrEmpty(text) && AllEmojisPattern.IsMatch(text);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static int LengthWithoutEmojis(string text)
|
| {
|
| if (string.IsNullOrEmpty(text)) return 0;
|
|
|
| var cleanText = AllEmojisPattern.Replace(text, string.Empty);
|
| return cleanText.Length;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static double CalculateEmojiDensity(string text)
|
| {
|
| if (string.IsNullOrEmpty(text)) return 0.0;
|
|
|
| var emojiCount = AllEmojisPattern.Matches(text).Count;
|
| return (double)emojiCount / text.Length * 100.0;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static string GenerateAnalysisReport(string text)
|
| {
|
| if (string.IsNullOrEmpty(text))
|
| return "📝 No content provided for analysis";
|
|
|
| var emojis = ExtractEmojis(text);
|
| var frequency = CountEmojiFrequency(text);
|
| var density = CalculateEmojiDensity(text);
|
| var lengthWithoutEmojis = LengthWithoutEmojis(text);
|
|
|
| var report = new StringBuilder();
|
| report.AppendLine("🎯 COMPREHENSIVE EMOJI ANALYSIS");
|
| report.AppendLine("===============================");
|
| report.AppendLine();
|
| report.AppendLine($"📝 Total characters: {text.Length:N0}");
|
| report.AppendLine($"🔍 Total emojis: {frequency.Values.Sum():N0}");
|
| report.AppendLine($"🎯 Unique emojis: {emojis.Count:N0}");
|
| report.AppendLine($"📏 Length without emojis: {lengthWithoutEmojis:N0}");
|
| report.AppendLine($"📈 Emoji density: {density:F2}%");
|
| report.AppendLine($"✅ Contains emojis: {(emojis.Count > 0 ? "Yes" : "No")}");
|
| report.AppendLine();
|
|
|
| if (frequency.Count > 0)
|
| {
|
| report.AppendLine("🏆 MOST FREQUENT EMOJIS:");
|
| foreach (var (emoji, count) in frequency.OrderByDescending(x => x.Value).Take(10))
|
| {
|
| var percentage = (double)count / frequency.Values.Sum() * 100;
|
| report.AppendLine($" {emoji}: {count:N0} times ({percentage:F1}%)");
|
| }
|
| report.AppendLine();
|
| }
|
|
|
| if (emojis.Count > 0)
|
| {
|
| report.AppendLine("📋 ALL DETECTED EMOJIS:");
|
| report.AppendLine($" {string.Join(" ", emojis)}");
|
| }
|
|
|
| return report.ToString();
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| [EmojiTest("🧪 Main test runner class", "🎪 Testing")]
|
| public class EmojiProcessorTestRunner
|
| {
|
|
|
|
|
|
|
|
|
|
|
| public static async Task Main(string[] args)
|
| {
|
| Console.WriteLine("🎉 Starting Chahuadev C# Emoji Cleaner Test Suite! 🧪\n");
|
|
|
|
|
| using var processor = new AdvancedEmojiProcessor(maxConcurrency: 4);
|
|
|
| try
|
| {
|
|
|
| await RunBasicTests(processor);
|
| await RunAdvancedTests(processor);
|
| await RunPerformanceTests(processor);
|
| await RunBatchTests(processor);
|
| await RunUtilityTests();
|
|
|
|
|
| await DisplayFinalStatistics(processor);
|
| }
|
| catch (Exception ex)
|
| {
|
| Console.WriteLine($"❌ Test suite failed: {ex.Message}");
|
| }
|
|
|
| Console.WriteLine("\n🎉 All tests completed successfully! ✅");
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private static async Task RunBasicTests(IEmojiProcessor processor)
|
| {
|
| Console.WriteLine("🧪 Running basic emoji processing tests...\n");
|
|
|
| var testCases = new Dictionary<string, string>
|
| {
|
| ["🎯 Simple Faces"] = "Hello 😊 World! 😀 This is a test 🙂 with basic emojis 😃!",
|
| ["❤️ Hearts and Love"] = "I love ❤️ programming! 💕 C# is amazing 💖 for development 💘!",
|
| ["🚀 Objects and Tools"] = "Check out this rocket 🚀! We use tools 🔧 and technology 💻 daily ⚡!",
|
| ["🌸 Nature Elements"] = "Beautiful flowers 🌸🌺🌻 grow in the garden 🌱 under the sun ☀️!",
|
| ["🎪 Mixed Content"] = "🎉 Celebration time! 🚀 Let's code! 😊 Happy programming 💻 with emojis 🎨!"
|
| };
|
|
|
| foreach (var (testName, content) in testCases)
|
| {
|
| Console.WriteLine($"Testing: {testName}");
|
| var result = await processor.ProcessContentAsync(content);
|
|
|
| Console.WriteLine($" 📝 Original: {TruncateString(content, 50)}");
|
| Console.WriteLine($" 🧹 Cleaned: {TruncateString(result.CleanedContent, 50)}");
|
| Console.WriteLine($" 🔍 Emojis found: {result.FoundEmojis.Count}");
|
| Console.WriteLine($" ⏱️ Time: {result.ProcessingTime.TotalMilliseconds:F2} ms");
|
| Console.WriteLine($" ✅ Success: {result.Success}");
|
| Console.WriteLine();
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private static async Task RunAdvancedTests(IEmojiProcessor processor)
|
| {
|
| Console.WriteLine("🔬 Running advanced emoji processing tests...\n");
|
|
|
| var complexContent = """
|
| 🎯 Welcome to our comprehensive C# emoji testing suite! 🧪
|
|
|
| This content includes various emoji categories:
|
| • 😀 Facial expressions: 😊 😂 🤣 😍 🥰 😘 😎 🤓 😴 😇 🙃 😉
|
| • ❤️ Hearts and emotions: 💕 💖 💗 💘 💝 💞 💟 💔 ❣️ 💋 😍 🥰
|
| • 🚀 Technology objects: 💻 📱 ⌨️ 🖥️ 🖨️ 📡 💾 💿 📀 🔌 🔋 💡
|
| • 🌸 Nature elements: 🌱 🌿 🍀 🌾 🌳 🌲 🌴 🌵 🌺 🌻 🌼 🌷
|
| • 🎯 Symbols and signs: ⭐ 🌟 ✨ 💫 🌙 ☀️ ⛅ 🌈 ⚡ 🔥 💧 🌊
|
|
|
| Advanced unicode sequences:
|
| 👨💻 Developer coding in C# 💻 with Visual Studio 🎯
|
| 👩🚀 Astronaut exploring 🌍 space with advanced 🚀 technology
|
| 🏳️🌈 Rainbow flag representing 🌈 diversity in tech community
|
| 👨👩👧👦 Family enjoying 🎪 technology conference together
|
|
|
| Skin tone modifiers and variations:
|
| 👋🏻 👋🏼 👋🏽 👋🏾 👋🏿 (greeting with skin tone diversity)
|
| 👍🏻 👍🏼 👍🏽 👍🏾 👍🏿 (approval across all backgrounds)
|
| 👨🏻💻 👨🏼💻 👨🏽💻 👨🏾💻 👨🏿💻 (diverse developers)
|
|
|
| Multilingual content with emojis:
|
| English: Hello 👋 World! 🌍 Welcome to C# programming! 💻
|
| ไทย: สวัสดี 🙏 ชาวโลก! 🌎 ยินดีต้อนรับสู่การเขียนโปรแกรม C#! 👨💻
|
| 日本語: こんにちは 👋 世界! 🌏 C# プログラミングへようこそ! 🎯
|
| Español: ¡Hola 👋 Mundo! 🌍 ¡Bienvenido a la programación C#! 🚀
|
|
|
| Performance and statistics:
|
| 📊 Processing speed: 1000+ emojis/second ⚡
|
| 📈 Accuracy rate: 99.8% detection success ✅
|
| ⏰ Response time: < 100ms average 🎯
|
| 💾 Memory usage: Optimized for efficiency 🧠
|
| 🔧 Concurrent processing: Multi-threaded support 🧵
|
|
|
| Special characters and edge cases:
|
| Unicode combinations: 🤦♀️ 🤷♂️ 💁♀️ 🙋♂️ 🙎♀️ 🙍♂️
|
| Food and drinks: ☕ 🍕 🍔 🍟 🌭 🥪 🌮 🌯 🥙 🍗 🍖 🥓
|
| Sports and activities: ⚽ 🏀 🏈 ⚾ 🎾 🏐 🏉 🎱 🏓 🏸 🥅
|
| Transportation: 🚗 🚕 🚙 🚌 🚎 🏎️ 🚓 🚑 🚒 🚐 🛻 🚚
|
|
|
| 🎉 End of advanced testing content! 🧪✨
|
| """;
|
|
|
| Console.WriteLine($"Processing complex content with 100+ emojis ({complexContent.Length:N0} characters)...");
|
|
|
| var result = await processor.ProcessContentAsync(complexContent);
|
| Console.WriteLine(result.GenerateDetailedReport());
|
|
|
|
|
| Console.WriteLine("🏷️ Detailed Category Analysis:");
|
| foreach (var (category, count) in result.CategoryStats.OrderByDescending(x => x.Value))
|
| {
|
| var percentage = (double)count / result.FoundEmojis.Count * 100;
|
| Console.WriteLine($" {category}: {count:N0} emojis ({percentage:F1}%)");
|
| }
|
| Console.WriteLine();
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private static async Task RunPerformanceTests(IEmojiProcessor processor)
|
| {
|
| Console.WriteLine("⚡ Running performance tests...\n");
|
|
|
|
|
| var emojiSamples = new[]
|
| {
|
| "😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃",
|
| "😉", "😊", "😇", "🥰", "😍", "🤩", "😘", "😗", "😚", "😙",
|
| "🚀", "⚡", "🔥", "💧", "🌟", "✨", "💫", "⭐", "🌙", "☀️",
|
| "❤️", "🧡", "💛", "💚", "💙", "💜", "🤎", "🖤", "🤍", "💔",
|
| "📊", "📈", "📉", "📋", "📌", "📍", "📎", "📏", "📐", "📑"
|
| };
|
|
|
| var contentBuilder = new StringBuilder();
|
| var random = new Random(42);
|
|
|
|
|
| for (int i = 0; i < 2000; i++)
|
| {
|
| contentBuilder.Append($"Sample text {i} ");
|
| contentBuilder.Append(emojiSamples[i % emojiSamples.Length]);
|
| contentBuilder.Append(" ");
|
|
|
| if (i % 20 == 0) contentBuilder.AppendLine();
|
| }
|
|
|
| var testContent = contentBuilder.ToString();
|
| Console.WriteLine($"📊 Generated performance test content: {testContent.Length:N0} characters");
|
|
|
|
|
| var results = new List<ProcessingResult>();
|
| var totalStopwatch = Stopwatch.StartNew();
|
|
|
| for (int run = 0; run < 5; run++)
|
| {
|
| var runResult = await processor.ProcessContentAsync(testContent);
|
| results.Add(runResult);
|
| Console.WriteLine($" 🔄 Run {run + 1}: {runResult.FoundEmojis.Count} emojis in {runResult.ProcessingTime.TotalMilliseconds:F2} ms");
|
| }
|
|
|
| totalStopwatch.Stop();
|
|
|
|
|
| var avgTime = results.Average(r => r.ProcessingTime.TotalMilliseconds);
|
| var avgEmojis = results.Average(r => r.FoundEmojis.Count);
|
| var avgThroughput = avgEmojis / (avgTime / 1000.0);
|
| var successRate = results.Count(r => r.Success) / (double)results.Count * 100;
|
|
|
| Console.WriteLine("\n⚡ PERFORMANCE SUMMARY:");
|
| Console.WriteLine($" 📊 Average processing time: {avgTime:F2} ms");
|
| Console.WriteLine($" 🔍 Average emojis processed: {avgEmojis:F0}");
|
| Console.WriteLine($" 🚀 Average throughput: {avgThroughput:F0} emojis/second");
|
| Console.WriteLine($" ✅ Success rate: {successRate:F1}%");
|
| Console.WriteLine($" ⏱️ Total test time: {totalStopwatch.Elapsed.TotalSeconds:F2} seconds");
|
| Console.WriteLine();
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private static async Task RunBatchTests(IEmojiProcessor processor)
|
| {
|
| Console.WriteLine("📦 Running batch processing tests...\n");
|
|
|
| var batchContent = new List<string>
|
| {
|
| "🎯 First batch item with various emojis 😊 and text content 📝",
|
| "🚀 Second item containing rockets 🚀 and stars ⭐✨ for testing",
|
| "❤️ Third piece with hearts 💕 and love 💖 symbols everywhere",
|
| "🌸 Fourth content about nature 🌿 flowers 🌺 and growth 🌱",
|
| "🎪 Fifth document mixing celebration 🎉 and fun 🎈 activities",
|
| "💻 Sixth item about technology 📱 coding 👨💻 and innovation",
|
| "🍎 Seventh piece with food 🍕 drinks ☕ and culinary 🍳 emojis",
|
| "🏠 Eighth content about places 🏢 travel ✈️ and exploration 🗺️",
|
| "🎨 Ninth document with art 🖼️ creativity 🎭 and design 🎪",
|
| "🧪 Tenth item for scientific 🔬 testing 📊 and research 📚 purposes",
|
| "🎵 Eleventh content with music 🎶 entertainment 🎬 and media 📺",
|
| "🏆 Twelfth item celebrating achievements 🥇 success ✅ and victory 🎉"
|
| };
|
|
|
| Console.WriteLine($"Processing batch of {batchContent.Count:N0} items...");
|
|
|
| var batchStopwatch = Stopwatch.StartNew();
|
| var batchResults = await processor.ProcessBatchAsync(batchContent);
|
| batchStopwatch.Stop();
|
|
|
| var resultsList = batchResults.ToList();
|
| var totalEmojis = resultsList.Sum(r => r.FoundEmojis.Count);
|
| var successCount = resultsList.Count(r => r.Success);
|
| var avgTimePerItem = resultsList.Average(r => r.ProcessingTime.TotalMilliseconds);
|
|
|
| Console.WriteLine("📦 BATCH PROCESSING RESULTS:");
|
| Console.WriteLine($" 📊 Items processed: {resultsList.Count:N0}");
|
| Console.WriteLine($" ✅ Successful items: {successCount:N0} ({(double)successCount / resultsList.Count * 100:F1}%)");
|
| Console.WriteLine($" 🔍 Total emojis removed: {totalEmojis:N0}");
|
| Console.WriteLine($" ⏱️ Total batch time: {batchStopwatch.Elapsed.TotalMilliseconds:F2} ms");
|
| Console.WriteLine($" 📈 Average per item: {avgTimePerItem:F2} ms");
|
| Console.WriteLine($" 🚀 Batch throughput: {totalEmojis / batchStopwatch.Elapsed.TotalSeconds:F0} emojis/second");
|
| Console.WriteLine();
|
| }
|
|
|
|
|
|
|
|
|
| private static async Task RunUtilityTests()
|
| {
|
| Console.WriteLine("🛠️ Running utility function tests...\n");
|
|
|
| var testText = "🎯 Sample text with emojis! 😊 Testing utilities 🧪 for analysis 📊 and reporting 📋! ⚡✨🎉";
|
|
|
| Console.WriteLine("Testing EmojiUtilities functions:");
|
| Console.WriteLine($" 📝 Test text: {testText}");
|
| Console.WriteLine();
|
|
|
|
|
| var emojis = EmojiUtilities.ExtractEmojis(testText);
|
| var frequency = EmojiUtilities.CountEmojiFrequency(testText);
|
| var containsEmojis = EmojiUtilities.ContainsEmojis(testText);
|
| var lengthWithoutEmojis = EmojiUtilities.LengthWithoutEmojis(testText);
|
| var density = EmojiUtilities.CalculateEmojiDensity(testText);
|
|
|
| Console.WriteLine("🔍 UTILITY FUNCTION RESULTS:");
|
| Console.WriteLine($" 📋 Extracted emojis: {string.Join(" ", emojis)}");
|
| Console.WriteLine($" 📊 Emoji frequency: {frequency.Count} unique, {frequency.Values.Sum()} total");
|
| Console.WriteLine($" ✅ Contains emojis: {containsEmojis}");
|
| Console.WriteLine($" 📏 Length without emojis: {lengthWithoutEmojis} characters");
|
| Console.WriteLine($" 📈 Emoji density: {density:F2}%");
|
| Console.WriteLine();
|
|
|
|
|
| var analysisReport = EmojiUtilities.GenerateAnalysisReport(testText);
|
| Console.WriteLine("📋 COMPREHENSIVE ANALYSIS REPORT:");
|
| Console.WriteLine(analysisReport);
|
|
|
| await Task.Delay(10);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| private static async Task DisplayFinalStatistics(IEmojiProcessor processor)
|
| {
|
| Console.WriteLine("📊 FINAL PROCESSOR STATISTICS");
|
| Console.WriteLine("=============================\n");
|
|
|
| var stats = processor.Statistics;
|
| Console.WriteLine(stats.GenerateReport());
|
|
|
|
|
| Console.WriteLine("🔧 PROCESSOR INFORMATION:");
|
| Console.WriteLine($" 🏷️ Name: {processor.Name}");
|
| Console.WriteLine($" ⚙️ Type: {processor.GetType().Name}");
|
| Console.WriteLine($" 🧵 Thread-safe: Yes");
|
| Console.WriteLine($" 💾 Caching: Enabled");
|
| Console.WriteLine($" ⚡ Async support: Full");
|
| Console.WriteLine();
|
|
|
| await Task.Delay(10);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| private static string TruncateString(string text, int maxLength)
|
| {
|
| if (string.IsNullOrEmpty(text) || text.Length <= maxLength)
|
| return text;
|
|
|
| return text[..maxLength] + "...";
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public static class EmojiTestDataFactory
|
| {
|
| private static readonly Random Random = new(Environment.TickCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| public static string GenerateTestContent(int wordCount, double emojiDensity)
|
| {
|
| var words = new[]
|
| {
|
| "test", "content", "sample", "example", "demonstration", "validation",
|
| "processing", "analysis", "performance", "optimization", "efficiency",
|
| "technology", "innovation", "development", "programming", "software"
|
| };
|
|
|
| var emojis = new[]
|
| {
|
| "😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃",
|
| "🚀", "⚡", "🔥", "💧", "🌟", "✨", "💫", "⭐", "🌙", "☀️",
|
| "❤️", "🧡", "💛", "💚", "💙", "💜", "🤎", "🖤", "🤍", "💔",
|
| "📊", "📈", "📉", "📋", "📌", "📍", "📎", "📏", "📐", "📑",
|
| "🎯", "🎪", "🎨", "🎵", "🎶", "🎬", "🎭", "🎮", "🎲", "🎸"
|
| };
|
|
|
| var content = new StringBuilder();
|
|
|
| for (int i = 0; i < wordCount; i++)
|
| {
|
| if (Random.NextDouble() < emojiDensity)
|
| {
|
| content.Append(emojis[Random.Next(emojis.Length)]);
|
| }
|
| else
|
| {
|
| content.Append(words[Random.Next(words.Length)]);
|
| }
|
|
|
| if (i < wordCount - 1) content.Append(" ");
|
| }
|
|
|
| return content.ToString();
|
| }
|
|
|
|
|
|
|
|
|
|
|
| public static Dictionary<string, string> CreateTestScenarios()
|
| {
|
| return new Dictionary<string, string>
|
| {
|
| ["🧪 Light Usage"] = GenerateTestContent(50, 0.15),
|
| ["🎯 Medium Usage"] = GenerateTestContent(75, 0.30),
|
| ["🔥 Heavy Usage"] = GenerateTestContent(100, 0.50),
|
| ["🎪 Extreme Usage"] = GenerateTestContent(40, 0.75),
|
| ["📊 Mixed Content"] = GenerateTestContent(200, 0.25)
|
| };
|
| }
|
| }
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |