#include <stdio.h>
#include <stdlib.h>
#include "simulated_annealing.h"

/*
 * Simple C Test Suite
 */
double f(void *p)
{
  double *x = (double*) p;
  return pow(0.7*pow(x[0],2)+3.3*pow(x[1],4)+2*pow(x[2],6), 2);
}

void test1() {
    printf("newsimpletest test 1\n");
    srand(time(NULL));

  double p[3];
  p[0] = 2.7;
  p[1] = 3;
  p[2] = -0.5;
  void *data = (void*) p;

  double (*e) (void *);
  e = f;

  sa_param *params = sa_param_alloc(3);
  sa_param_define(params, 0, &p[0]);
  sa_param_define(params, 1, &p[1]);
  sa_param_define(params, 2, &p[2]);
  sa_param_set(params, 0, p[0]);
  sa_param_set(params, 1, p[1]);
  sa_param_set(params, 2, p[2]);

  sa_param_print(params);

  double dmax = 0.1;
  double Tmax = 10;
  double Tmin = 0.01;
  double alfa = 0.05;
  unsigned int kmax = 10;

  sa_algorithm(params, dmax, Tmin, Tmax, kmax, alfa, e, data);

  sa_param_print(params);
}

void test2() {
    printf("newsimpletest test 2\n");
    printf("%%TEST_FAILED%% time=0 testname=test2 (newsimpletest) message=error message sample\n");
}

int main(int argc, char** argv) {
    printf("%%SUITE_STARTING%% newsimpletest\n");
    printf("%%SUITE_STARTED%%\n");

    printf("%%TEST_STARTED%% test1 (newsimpletest)\n");
    test1();
    printf("%%TEST_FINISHED%% time=0 test1 (newsimpletest) \n");

    printf("%%TEST_STARTED%% test2 (newsimpletest)\n");
    test2();
    printf("%%TEST_FINISHED%% time=0 test2 (newsimpletest) \n");

    printf("%%SUITE_FINISHED%% time=0\n");

    return (EXIT_SUCCESS);
}
