#include <amscppnarray/amscppnarray.hpp>

namespace ams
{
namespace narray
{


void test_narray1()
{
    int I;
    narray<float> a;
    narray<float> *b = NULL;
    narray<float> tmp;

    b = new(std::nothrow) narray<float>();
    a.resize(100);
    b->resize(100000);
    a.setall(2.5f);
    b->setall(3.0f);

    for(I=0;I<100000;I++)
    {
        if(b->at(I)!=3.0f)
        {
            printf("Error: b[%d]=%1.3f, not %1.3f\n",I,b->at(I),3.0f);
            break;
        }
    }

    a.resize(100000);

    tmp = a;
    a = *b;
    *b = tmp;

    *b = tmp+a;
    for(I=0;I<b->length;I++)
    {
        if(b->at(I) != tmp[I] + a[I])
        {
            printf("addition error in index %d",I);
        }
    }

    printf("threaded boolean test: %d\n", (*b==(a+tmp)));



    delete b;

    return;
}

void test_narray2()
{
    int I;
    narray<float> a,b,c,d;

    a.resize(100000); a.setall(1.0f);
    b.resize(100000); for(I=0;I<b.length;I++) b[I] = 0.5f*I;
    c.resize(100000); c.setall(2.0f);

    d = -a*(b+c);
    for(I=0;I<5;I++)
    {
        printf("d[%d]=%1.3f\n",I,d[I]);

    }

    printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
    d[50000] = 0.0f;
    printf("d==-a*(b+c):%d\n",d==(-a*(b+c)));
    
}


void test_narray3()
{
    int I;
    narray<float> a,b,c,d;

    a.resize(5); a.setall(1.0f);
    b = {0,0.25,0.5,0.675,0.8675};
    c.resize(5); c.setall(2.0f);

    d = -a*(b+c*2+2);
    for(I=0;I<5;I++)
    {
        printf("d[%d]=%1.3f\n",I,d[I]);

    }

    printf("d==-a*(b+c*2+2):%d\n",d==(-a*(b+c*2+2)));
    d[4] = 0.0f;
    printf("d==-a*(b+c*2+2):%d\n",d==(-a*(b+c*2+2)));
    d = d.applyfn(::sinf);

    for(I=0;I<5;I++)
    {
        printf("d[%d]=%1.3f\n",I,d[I]);

    }

    d = d.subarray(0,1);
    for(I=0;I<d.length;I++)
    {
        printf("d[%d]=%1.3f\n",I,d[I]);

    }
}


}; //end namespace narray
}; //end namespace ams