#include <iostream>
#include <cmath>

#include "utils.hpp"
#include "TOMS748.hpp"

using std::cout;
using std::endl;

using namespace TOMS748;
using namespace TOMS748::internal;

template<typename T> T f(T E) { PRINT_VAR(E); return E - 0.5*sin(E) - 0.3; }

int main()
{
	cout.precision(16);
	{
		double a = 0, b = 1, c = 0.3, d = 1.2;
		double fa = f(a), fb = f(b), fc = f(c), fd = f(d);
		double tol = 1e-12;

		PRINT_VAR(fbracket1(a, b, fa, fb));
		PRINT_VAR(fbracket2(a, b, d, fa, fb, fd));
		std::tie(a, b, d, fa, fb, fd) = bracket(a, b, c, fa, fb, fc);
		PRINT_VAR(a);
		PRINT_VAR(b);
		PRINT_VAR(d);
		PRINT_VAR(fa);
		PRINT_VAR(fb);
		PRINT_VAR(fd);

		PRINT_VAR(checkTwoValuesIdentical(1,2,3,4));
		PRINT_VAR(checkTwoValuesIdentical(1,2,3,1));
		PRINT_VAR(checkTwoValuesIdentical(1,1,3,4));
		PRINT_VAR(checkTwoValuesIdentical(1,2,2,4));
		PRINT_VAR(checkTwoValuesIdentical(1,2,3,3));
		PRINT_VAR(checkTwoValuesIdentical(1,2,1,4));
		PRINT_VAR(checkTwoValuesIdentical(1,2,3,2));

		a = 0; b = 1;
		auto res = TOMS748_solve1(f<double>, a, b, tol);
		PRINT_VAR(std::get<0>(res));
		PRINT_VAR(std::get<1>(res));
		PRINT_VAR(std::get<2>(res));
	}

	return 0;
}
