//+------------------------------------------------------------------+
//|                                              ReportFormatter.mqh |
//| CReportFormatter: formats and prints structured pass/fail        |
//| output from STestResult arrays to the terminal's Experts tab.    |
//+------------------------------------------------------------------+
#ifndef REPORTFORMATTER_MQH
#define REPORTFORMATTER_MQH

#include "TestStatus.mqh"

//+------------------------------------------------------------------+
//| Class CReportFormatter                                           |
//| Purpose: Formats and outputs aggregated unit test results to the |
//|          MetaTrader terminal's Experts tab                       |
//+------------------------------------------------------------------+
class CReportFormatter
  {
public:
   //--- Core reporting interface methods
   void              PrintReport(STestResult &results[], int count);
   void              PrintSummary(int total, int passed, int failed);
  };

//+------------------------------------------------------------------+
//| PrintReport                                                      |
//| Purpose: Iterates through the collection of captured assertion   |
//|          results and displays a formatted Experts tab record.    |
//+------------------------------------------------------------------+
void CReportFormatter::PrintReport(STestResult &results[], int count)
  {
//--- Visual header styling for test logging boundaries
   Print("==========================================");
   Print("=== Unit Test Report                   ===");
   Print("==========================================");

//--- Process individual assertion outcomes sequentially
   for(int i = 0; i < count; i++)
     {
      switch(results[i].status)
        {
         case TEST_PASS:
            Print("[PASS] " + results[i].test_name +
                  " | Suite: " + results[i].suite_name);
            break;

         case TEST_FAIL:
            Print("[FAIL] " + results[i].test_name +
                  " | Suite: " + results[i].suite_name +
                  " | Expected=" + results[i].expected +
                  " | Actual=" + results[i].actual +
                  " | File=" + results[i].file +
                  " | Line=" + IntegerToString(results[i].line));
            break;

         case TEST_ERROR:
            Print("[ERROR] " + results[i].test_name +
                  " | Suite: " + results[i].suite_name +
                  " | " + results[i].actual +
                  " | Line=" + IntegerToString(results[i].line));
            break;
        }
     }
  }

//+-------------------------------------------------------------------+
//| PrintSummary                                                      |
//| Purpose: Computes aggregate success metrics, including absolute   |
//|          pass percentages, and appends a conclusive summary block |
//+-------------------------------------------------------------------+
void CReportFormatter::PrintSummary(int total, int passed, int failed)
  {
//--- Prevent division-by-zero runtime errors on empty test sets
   double pass_rate = (total > 0) ? ((double)passed / total) * 100.0 : 0.0;

   Print("------------------------------------------");
   Print("Total Tests : " + IntegerToString(total));
   Print("Passed      : " + IntegerToString(passed));
   Print("Failed      : " + IntegerToString(failed));
   Print("Pass Rate   : " + DoubleToString(pass_rate, 2) + "%");
   Print("------------------------------------------");
  }

#endif // REPORTFORMATTER_MQH
//+------------------------------------------------------------------+