/* Siconos is a program dedicated to modeling, simulation and control
 * of non smooth dynamical systems.
 *
 * Copyright 2020 INRIA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <stdio.h>           // for printf
#include <string.h>          // for strcmp
#include "mlcp_cst.h"         // for SICONOS_MLCP_...
#include "mlcp_test_utils.h"  // for mlcp_test_function
#include "test_utils.h"      // for TestCase, build_test_collection_generic
#include "SiconosConfig.h"   // for HAVE_GAMS_C_API // IWYU pragma: keep

// Set TEST_LCP_COLLECTION_XX value (XX = 1,2,3,4 or 5, depending on cmake test setup).
#define @PROBLEM_COLLECTION@ 1

int main(void)
{
  // Remind that data_collection depends on current PROBLEM_COLLECTION value.
  const char ** _data_collection = data_collection();
  int n_data = 0;
  while (strcmp(_data_collection[n_data], "---") !=0)
    n_data++;

  // Set solvers list for each collection of data.
#if defined(TEST_MLCP_COLLECTION_1) || defined(TEST_MLCP_COLLECTION_4)
  // same solvers for data collections 1 and 2
  int solvers[] = {SICONOS_MLCP_PGS,
                   SICONOS_MLCP_RPGS,
                   SICONOS_MLCP_PSOR,
                   SICONOS_MLCP_ENUM,
                   SICONOS_MLCP_DIRECT_ENUM,
                   SICONOS_MLCP_FB,
                   SICONOS_MLCP_DIRECT_FB,
                   SICONOS_MLCP_LCP_LEMKE};

#elif TEST_MLCP_COLLECTION_2
  int solvers[] = {SICONOS_MLCP_PGS,
                   SICONOS_MLCP_RPGS,
                   SICONOS_MLCP_PSOR,
                   SICONOS_MLCP_FB,
                   SICONOS_MLCP_DIRECT_FB,
                   SICONOS_MLCP_LCP_LEMKE};

#elif TEST_MLCP_COLLECTION_3
  int solvers[] = {SICONOS_MLCP_PGS,
                   SICONOS_MLCP_RPGS,
                   SICONOS_MLCP_PSOR,
                   SICONOS_MLCP_LCP_LEMKE};

#endif

  int n_solvers = (int)(sizeof(solvers) / sizeof(solvers[0]));

  printf("Test %i data files with %i solvers.\n", n_data, n_solvers);

  TestCase * collection = build_test_collection_generic(n_data, _data_collection, n_solvers, solvers);

#ifdef TEST_MLCP_COLLECTION_1
  // some solvers are expected to fail ...

  int failed_test[]=  {1, 2, 3, 4, 8, 9, 10, 11, 12, 13,
                       15, 16, 17, 18, 22, 23, 24, 25, 26, 27,
                       28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
                       38, 39, 40, 41, 65, 106, 107, 108, 109};

  int n_failed_test=  (int)(sizeof(failed_test) / sizeof(failed_test[0]));

  for (int t =0; t< n_failed_test; t++)
  {
    collection[failed_test[t]].will_fail = 1;
  }
  // some others are unstable */
  /* collection[10].will_fail = 2; */
#elif TEST_MLCP_COLLECTION_2

  int failed_test[]=  {0, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 17};
  int n_failed_test=  (int)(sizeof(failed_test) / sizeof(failed_test[0]));

  for (int t =0; t< n_failed_test; t++)
  {
    collection[failed_test[t]].will_fail = 1;
  }
#elif TEST_MLCP_COLLECTION_3

  int failed_test[]=  {0, 1, 2, 3, 4, 5, 7};
  int n_failed_test=  (int)(sizeof(failed_test) / sizeof(failed_test[0]));

  for (int t =0; t< n_failed_test; t++)
  {
    collection[failed_test[t]].will_fail = 1;
  }

#elif TEST_MLCP_COLLECTION_4
  collection[0].will_fail = 1;
#endif


  int number_of_tests = n_data * n_solvers;
  int out = run_test_collection(collection, number_of_tests, mlcp_test_function);
  free_test_collection(collection, number_of_tests);


  return out;
}
