{%- import 'macros.tex' as macros %}
{%- include 'unittest_head.tex' %}
{%- include 'unittest_titlepage.tex' %}
\tableofcontents
\newpage

\section{Test Information}
\subsection{Test Candidate Information}
{%- with testobject_information = data.testobject_information %}
  {%- include 'information/candidate.tex' %}
{%- endwith %}
\subsection{Unittest Information}
{%- with unittest_information = data.unittest_information %}
  {%- include 'information/unittest.tex' %}
{%- endwith %}
\subsection{Test System Information}
{%- with system_information = data.system_information %}
  {%- include 'information/system.tex' %}
{%- endwith %}

\section{Statistic}
{%- for testrun in data.testrun_list %}
  \subsection{\textcolor{% if testrun.number_of_failed_tests > 0%}{red}{% else %}{% if testrun.number_of_possibly_failed_tests > 0%}{orange}{% else %}{green}{% endif %}{% endif %}{Test-Statistic for testrun with {{testrun.interpreter}}}}
  {%- include 'test/run_statistic.tex' %}
{%- endfor %}
\subsection{Coverage Statistic}
{%- with coverage_information = data.coverage_information %}
  {%- include 'coverage/statistic.tex' %}
{%- endwith %}

\newpage
{%- if data.specification.get('item_dict', {})|length >0 %}
  \section{Tested Requirements}
  {%- for item_id in data.specification.uid_list_sorted %}
    {%- if item_id not in data.lost_souls.item_list %}
      {%- with item = data.specification.item_dict[item_id] %}
        {%- if item.system_type_uid == '_4-K5EHYYEem_kd-7nxt1sg' %}
          {%- with sectype = 'subsection' %}
            {%- include 'reqif/heading.tex' %}
          {%- endwith %}
        {%- elif item.system_type_uid == '_MR7eNHYYEem_kd-7nxt1sg' %}
          {%- with sectype = 'subsubsection', labeltype = 'item:' %}
            {%- include 'reqif/requirement.tex' %}
          {%- endwith %}
          {%- if item_id not in data.lost_souls.item_list %}
            {%- for testrun in data.testrun_list %}
              {%- if item.system_uid in testrun.testcases %}
                {%- with testcase = testrun.testcases[item.system_uid] %}
                  {%- include 'test/case_short.tex' %}
                {%- endwith %}
              {%- else %}
                \textcolor{orange}{\bf No testresults available!}
              {%- endif %}
            {%- endfor %}
          {%- endif %}
        {%- endif %}
      {%- endwith %}
    {%- endif %}
  {%- endfor %}
{%- endif %}

{% if data.lost_souls.item_list|length > 0 %}
  \newpage
  \section{\textcolor{red}{Requirements with no corresponding Testcase}}
  {% for item_id in data.specification.uid_list_sorted %}
    {% with item = data.specification.item_dict[item_id] %}
      {% if item.system_type_uid == '_MR7eNHYYEem_kd-7nxt1sg' and item_id in data.lost_souls.item_list %}
        {%- with sectype = 'subsection', labeltype = 'lost_soul:' %}
          {% include 'reqif/requirement.tex' %}
        {%- endwith %}
      {% endif %}
    {% endwith %}
  {% endfor %}
{% endif %}

{% if data.lost_souls.testcase_list|length > 0 %}
  \newpage
  \section{\textcolor{orange}{Testcases with no corresponding Requirement}}
  {%- for testrun in data.testrun_list %}
    \subsection{Summary for testrun with {{ testrun.interpreter }}}
    {% for lost_soul_id in data.lost_souls.testcase_list %}
      {% if lost_soul_id in testrun.testcases %}
        {% with testcase = testrun.testcases[lost_soul_id] %}
          \subsubsection{ {{macros.latex_filter(testcase.message)}} }
          {% include 'test/case_short.tex' %}
        {% endwith %}
      {% endif %}
    {% endfor %}
  {% endfor %}
{% endif %}

\newpage
\appendix
{%- for testrun in data.testrun_list %}
  \section{Trace for testrun with {{ testrun.interpreter }}}
  {%- for max_level, absmax_level, num_tests in ( (40, 1000, testrun.number_of_failed_tests), (30, 39, testrun.number_of_possibly_failed_tests), (0, 29, testrun.number_of_successfull_tests) ) %}
    {% if num_tests > 0 %}
      \subsection{Tests with status {{ macros.result(max_level) }} ({{num_tests}})}
      {%- for testcase_id in testrun.uid_list_sorted %}
        {% with testcase = testrun.testcases[testcase_id], item = data.specification.get('item_dict', {}).get(testrun.testcases[testcase_id].message) %}
          {%- if testcase.levelno >= max_level and testcase.levelno <= absmax_level%}
            {%- if item %}
              {%- with sectype = 'subsubsection', labeltype = 'testcase:' + testrun.testrun_id + '__' %}
                {%- include 'reqif/requirement.tex' %}
              {%- endwith %}
            {%- else %}
              \subsubsection{ {{ macros.latex_filter(testcase.message) }} }\label{testcase:{{testrun.testrun_id}}__{{testcase.message}}}
            {%- endif %}
            {% include "test/case_long.tex" %}
          {%- endif %}
        {%- endwith %}
      {%- endfor %}
    {%- endif %}
  {% endfor %}
{%- endfor %}

{% with coverage_information = data.coverage_information %}
  {% include 'coverage/report.tex' %}
{% endwith %}
{% include 'unittest_foot.tex' %}
