//#####################################################################
// Copyright 2013.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#ifndef __Diff_Function_Test__
#define __Diff_Function_Test__
#include <Core/Arrays/ARRAY.h>
#include <Core/Log/LOG.h>
#include <Core/Random_Numbers/RANDOM_NUMBERS.h>
#include <functional>
namespace PhysBAM{
template<class T>
struct TEST_DIFF_OPTS
{
    mutable RANDOM_NUMBERS<T> rand;
    T eps=(T)1e-6;
    T zero_eps=(T)1e-20;
    bool test_e=true;
    bool test_de=true;

    const char* e_str="diff test e";
    const char* de_str="diff test de";
};

template<class T> void
Diff_Function_Test(std::ostream& os,const ARRAY<T>& x,
    std::function<void(const ARRAY<T>& x,const ARRAY<T>& dx,
        T& e,ARRAY<T>& de,ARRAY<T>& dde_dx)> compute,
    const TEST_DIFF_OPTS<T>& opt,
    std::function<void(ARRAY<T>& x)> make_feasible=0);
template<class T> void
Diff_Function_Test(const ARRAY<T>& x,
    std::function<void(const ARRAY<T>& x,const ARRAY<T>& dx,
        T& e,ARRAY<T>& de,ARRAY<T>& dde_dx)> compute,
    const TEST_DIFF_OPTS<T>& opt,
    std::function<void(ARRAY<T>& x)> make_feasible)
{Diff_Function_Test(LOG::cout,x,compute,opt,make_feasible);}
}
#endif
