Ejemplo n.º 1
0
void test_nans() {

    const char *nans[] = {
        "0/0",
        "1%0",
        "1%(1%0)",
        "(1%0)%1",
    };

    int i;
    for (i = 0; i < sizeof(nans) / sizeof(const char *); ++i) {
        const char *expr = nans[i];

        int err;
        const double r = te_interp(expr, &err);
        lequal(err, 0);
        lok(r != r);

        te_expr *n = te_compile(expr, 0, 0, &err);
        lok(n);
        lequal(err, 0);
        const double c = te_eval(n);
        lok(c != c);
        te_free(n);
    }
}
Ejemplo n.º 2
0
void test_closure() {

    double extra;
    double c[] = {5,6,7,8,9};

    te_variable lookup[] = {
        {"c0", clo0, TE_CLOSURE0, &extra},
        {"c1", clo1, TE_CLOSURE1, &extra},
        {"c2", clo2, TE_CLOSURE2, &extra},
        {"cell", cell, TE_CLOSURE1, c},
    };

    test_case cases[] = {
        {"c0", 6},
        {"c1 4", 8},
        {"c2 (10, 20)", 30},
    };

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_case); ++i) {
        const char *expr = cases[i].expr;
        const double answer = cases[i].answer;

        int err;
        te_expr *ex = te_compile(expr, lookup, sizeof(lookup)/sizeof(te_variable), &err);
        lok(ex);

        extra = 0;
        lfequal(te_eval(ex), answer + extra);

        extra = 10;
        lfequal(te_eval(ex), answer + extra);

        te_free(ex);
    }


    test_case cases2[] = {
        {"cell 0", 5},
        {"cell 1", 6},
        {"cell 0 + cell 1", 11},
        {"cell 1 * cell 3 + cell 4", 57},
    };

    for (i = 0; i < sizeof(cases2) / sizeof(test_case); ++i) {
        const char *expr = cases2[i].expr;
        const double answer = cases2[i].answer;

        int err;
        te_expr *ex = te_compile(expr, lookup, sizeof(lookup)/sizeof(te_variable), &err);
        lok(ex);
        lfequal(te_eval(ex), answer);
        te_free(ex);
    }
}
Ejemplo n.º 3
0
void test_pow() {
#ifdef TE_POW_FROM_RIGHT
    test_equ cases[] = {
        {"2^3^4", "2^(3^4)"},
        {"-2^2", "-(2^2)"},
        {"-(2)^2", "-(2^2)"},
        {"-(2*1)^2", "-(2^2)"},
        {"-2^2", "-4"},
        {"2^1.1^1.2^1.3", "2^(1.1^(1.2^1.3))"},
        {"-a^b", "-(a^b)"},
        {"-a^-b", "-(a^-b)"}
    };
#else
    test_equ cases[] = {
        {"2^3^4", "(2^3)^4"},
        {"-2^2", "(-2)^2"},
        {"-2^2", "4"},
        {"2^1.1^1.2^1.3", "((2^1.1)^1.2)^1.3"},
        {"-a^b", "(-a)^b"},
        {"-a^-b", "(-a)^(-b)"}
    };
#endif

    double a = 2, b = 3;

    te_variable lookup[] = {
        {"a", &a},
        {"b", &b}
    };

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_equ); ++i) {
        const char *expr1 = cases[i].expr1;
        const char *expr2 = cases[i].expr2;

        te_expr *ex1 = te_compile(expr1, lookup, sizeof(lookup)/sizeof(te_variable), 0);
        te_expr *ex2 = te_compile(expr2, lookup, sizeof(lookup)/sizeof(te_variable), 0);

        lok(ex1);
        lok(ex2);

        double r1 = te_eval(ex1);
        double r2 = te_eval(ex2);

        fflush(stdout);
        lfequal(r1, r2);

        te_free(ex1);
        te_free(ex2);
    }

}
Ejemplo n.º 4
0
void AssetDownloadTask::assetFileDownloaded(ResourceDownloadTaskPtr taskptr, Transfer::ChunkRequestPtr request, Transfer::DenseDataPtr response) {
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);

    // Clear from the active download list
    assert(mActiveDownloads.size() == 1);
    mActiveDownloads.erase(taskptr->getIdentifier());
    mFinishedDownloads.push_back(taskptr->getIdentifier());

    // Lack of response data means failure of some sort
    if (!response) {
        SILOG(ogre, warn, "Failed to download resource for " << taskptr->getIdentifier());
        failDownload();
        return;
    }

    // FIXME here we could have another callback which lets them get
    // at the hash to try to use an existing copy. Even with the
    // eventual centralized loading we want, this may still be
    // beneficial since Ogre may have a copy even if we don't have a
    // copy of the raw data any more.

    mParseMeshHandle = mScene->parseMesh(
        request->getMetadata(), request->getMetadata().getFingerprint(),
        response, mIsAggregate,
        std::tr1::bind(&AssetDownloadTask::weakHandleAssetParsed, getWeakPtr(), _1)
    );
}
Ejemplo n.º 5
0
static BOOL run_reg_exe_(unsigned line, const char *cmd, DWORD *rc)
{
    STARTUPINFOA si = {sizeof(STARTUPINFOA)};
    PROCESS_INFORMATION pi;
    BOOL bret;
    DWORD ret;
    char cmdline[256];

    si.dwFlags = STARTF_USESTDHANDLES;
    si.hStdInput  = INVALID_HANDLE_VALUE;
    si.hStdOutput = INVALID_HANDLE_VALUE;
    si.hStdError  = INVALID_HANDLE_VALUE;

    strcpy(cmdline, cmd);
    if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
        return FALSE;

    ret = WaitForSingleObject(pi.hProcess, 10000);
    if (ret == WAIT_TIMEOUT)
        TerminateProcess(pi.hProcess, 1);

    bret = GetExitCodeProcess(pi.hProcess, rc);
    lok(bret, "GetExitCodeProcess failed: %d\n", GetLastError());

    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    return bret;
}
Ejemplo n.º 6
0
void test_optimize() {

    test_case cases[] = {
        {"5+5", 10},
        {"pow(2,2)", 4},
        {"sqrt 100", 10},
        {"pi * 2", 6.2832},
    };

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_case); ++i) {
        const char *expr = cases[i].expr;
        const double answer = cases[i].answer;

        int err;
        te_expr *ex = te_compile(expr, 0, 0, &err);
        lok(ex);

        /* The answer should be know without
         * even running eval. */
        lfequal(ex->value, answer);
        lfequal(te_eval(ex), answer);

        te_free(ex);
    }
}
Ejemplo n.º 7
0
void AssetDownloadTask::textureDownloaded(Transfer::URI uri, ResourceDownloadTaskPtr taskptr, Transfer::TransferRequestPtr request, Transfer::DenseDataPtr response) {
    // This could be triggered by any CDN thread, protect access
    // (mActiveDownloads, mDependencies)
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);

    if (!taskptr) {
        SILOG(ogre, warn, "failed request dependent callback");
        failDownload();
        return;
    }

    if (!request) {
        SILOG(ogre, warn, "failed request dependent callback " << taskptr->getIdentifier());
        failDownload();
        return;
    }

    // Clear the download task
    mActiveDownloads.erase(taskptr->getIdentifier());
    mFinishedDownloads.push_back(taskptr->getIdentifier());

    // Lack of response data means failure of some sort
    if (!response) {
        SILOG(ogre, warn, "failed response dependent callback " << taskptr->getIdentifier());
        failDownload();
        return;
    }

    // Store data for later use
    mDependencies[uri].request = request;
    mDependencies[uri].response = response;

    if (mActiveDownloads.size() == 0)
        mCB();
}
Ejemplo n.º 8
0
void Display(void) {
    if (!gKillGraphics) {
        glViewport(0,0,gDisplayWidth,gDisplayHeight);
        glClear(GL_COLOR_BUFFER_BIT);
        {
            boost::unique_lock<boost::mutex> lok(*gRenderLock);
            gRenderCompleteCondition.notify_one();
            if (gToRender.size()) {
                gRenderCondition.wait(lok);
                int heightPartition=1;
                if (gToRender.size()>3) {
                    heightPartition=2;
                }
                if (gToRender.size()>10) {
                    heightPartition=3;
                }
                int i=0;
                for (int h=0;h<heightPartition;++h) {
                    int wlim=gToRender.size()/heightPartition;
                    if (gToRender.size()%heightPartition) wlim++;
                    for (int w=0;w<wlim;++w,++i) { 
                        glViewport(w*gDisplayWidth/wlim,
                          h*gDisplayHeight/heightPartition,
                          (w+1)*gDisplayWidth/wlim,
                          (h+1)*gDisplayHeight/heightPartition);
                        glMatrixMode(GL_MODELVIEW);
                        glLoadIdentity();
                        glScalef(2*wlim/(float)(gDisplayWidth),2*heightPartition/(float)(gDisplayHeight),1.0);
                        if (i<(int)gToRender.size())
                            gToRender[i]->draw();
                    }
                }
            }
        }
        {
            boost::unique_lock<boost::mutex> lok(*gRenderLock);
            gRenderCompleteCondition.notify_one();
        }
        glFlush();
    }else {
    }
    glutSwapBuffers();
    if (gShutDown ) {
        gInvalidDisplayFunction=true;
        glutDestroyWindow(gGlutWindowId);
    }
}
Ejemplo n.º 9
0
void AssetDownloadTask::startDependentDownloads() {
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);

    // Copy since we could get callbacks as soon as we start the downloads
    ActiveDownloadMap downloads_copy(mActiveDownloads);
    for(ActiveDownloadMap::iterator it = downloads_copy.begin(); it != downloads_copy.end(); it++)
        it->second->start();
}
Ejemplo n.º 10
0
Archivo: reg.c Proyecto: Dietr1ch/wine
static void verify_reg_(unsigned line, HKEY hkey, const char* value,
                        DWORD exp_type, const void *exp_data, DWORD exp_size, DWORD todo)
{
    DWORD type, size;
    BYTE data[256];
    LONG err;

    size = sizeof(data);
    memset(data, 0xdd, size);
    err = RegQueryValueExA(hkey, value, NULL, &type, data, &size);
    lok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
    if (err != ERROR_SUCCESS)
        return;

    if (todo & TODO_REG_TYPE)
        todo_wine lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
    else
        lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
    if (todo & TODO_REG_SIZE)
        todo_wine lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
    else
        lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
    if (todo & TODO_REG_DATA)
        todo_wine lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
    else
        lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
}
Ejemplo n.º 11
0
void test_dynamic() {

    double x, f;
    te_variable lookup[] = {
        {"x", &x},
        {"f", &f},
        {"sum0", sum0, TE_FUNCTION0},
        {"sum1", sum1, TE_FUNCTION1},
        {"sum2", sum2, TE_FUNCTION2},
        {"sum3", sum3, TE_FUNCTION3},
        {"sum4", sum4, TE_FUNCTION4},
        {"sum5", sum5, TE_FUNCTION5},
        {"sum6", sum6, TE_FUNCTION6},
        {"sum7", sum7, TE_FUNCTION7},
    };

    test_case cases[] = {
        {"x", 2},
        {"f+x", 7},
        {"x+x", 4},
        {"x+f", 7},
        {"f+f", 10},
        {"f+sum0", 11},
        {"sum0+sum0", 12},
        {"sum0()+sum0", 12},
        {"sum0+sum0()", 12},
        {"sum0()+(0)+sum0()", 12},
        {"sum1 sum0", 12},
        {"sum1(sum0)", 12},
        {"sum1 f", 10},
        {"sum1 x", 4},
        {"sum2 (sum0, x)", 8},
        {"sum3 (sum0, x, 2)", 10},
        {"sum2(2,3)", 5},
        {"sum3(2,3,4)", 9},
        {"sum4(2,3,4,5)", 14},
        {"sum5(2,3,4,5,6)", 20},
        {"sum6(2,3,4,5,6,7)", 27},
        {"sum7(2,3,4,5,6,7,8)", 35},
    };

    x = 2;
    f = 5;

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_case); ++i) {
        const char *expr = cases[i].expr;
        const double answer = cases[i].answer;

        int err;
        te_expr *ex = te_compile(expr, lookup, sizeof(lookup)/sizeof(te_variable), &err);
        lok(ex);
        lfequal(te_eval(ex), answer);
        te_free(ex);
    }
}
Ejemplo n.º 12
0
SingleStreamProximityConnection::~SingleStreamProximityConnection() {
    for (ObjectStreamMap::iterator i=mObjectStreams.begin(),ie=mObjectStreams.end();i!=ie;++i) {
        delete i->second;
    }
    std::tr1::weak_ptr<Network::Stream> lok(mConnectionStream);
    mConnectionStream=std::tr1::shared_ptr<Network::Stream>();
    while (lok.lock()) {
        //sleep? wait for callback to complete
    }
    mObjectStreams.clear();
}
Ejemplo n.º 13
0
void AssetDownloadTask::addDependentDownload(ResourceDownloadTaskPtr resPtr) {
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);

    // Sometimes we get duplicate references, so make sure we're not already
    // working on this one.
    if (mActiveDownloads.find(resPtr->getIdentifier()) != mActiveDownloads.end()) {
        return;
    }

    mActiveDownloads[resPtr->getIdentifier()] = resPtr;
}
Ejemplo n.º 14
0
void test_syntax() {
    test_case errors[] = {
        {"", 1},
        {"1+", 2},
        {"1)", 2},
        {"(1", 2},
        {"1**1", 3},
        {"1*2(+4", 4},
        {"1*2(1+4", 4},
        {"a+5", 1},
        {"A+5", 1},
        {"Aa+5", 1},
        {"1^^5", 3},
        {"1**5", 3},
        {"sin(cos5", 8},
    };


    int i;
    for (i = 0; i < sizeof(errors) / sizeof(test_case); ++i) {
        const char *expr = errors[i].expr;
        const int e = errors[i].answer;

        int err;
        const double r = te_interp(expr, &err);
        lequal(err, e);
        lok(r != r);

        te_expr *n = te_compile(expr, 0, 0, &err);
        lequal(err, e);
        lok(!n);

        if (err != e) {
            printf("FAILED: %s\n", expr);
        }

        const double k = te_interp(expr, 0);
        lok(k != k);
    }
}
Ejemplo n.º 15
0
void AssetDownloadTask::downloadAssetFile() {
    assert( !mAssetURI.empty() );

    boost::mutex::scoped_lock lok(mDependentDownloadMutex);

    ResourceDownloadTaskPtr dl = ResourceDownloadTask::construct(
        mAssetURI, mScene->transferPool(),
        mPriority,
        std::tr1::bind(&AssetDownloadTask::weakAssetFileDownloaded, getWeakPtr(), _1, _2, _3)
    );
    mActiveDownloads[dl->getIdentifier()] = dl;
    dl->start();
}
Ejemplo n.º 16
0
std::tr1::shared_ptr<Broadcast::BroadcastStream> Broadcast::establishSharedBroadcast(const Network::Address&addy, 
                                                                               const UUID&name,
                                                                               const std::tr1::function<void(const std::tr1::weak_ptr<Broadcast::BroadcastStream>&,
                                                                                                             Network::Stream::ConnectionStatus, 
                                                                                                             const std::string&reason)>& cb) {
    std::tr1::shared_ptr<Broadcast::BroadcastStream> retval;
    Network::Stream*newBroadcastStream=NULL;    
    while(newBroadcastStream==NULL) {
        boost::lock_guard<boost::mutex>lok(*mUniqueLock);
        std::tr1::weak_ptr<Network::Stream>*weak_topLevelStream=&mTopLevelStreams[addy];
        std::tr1::shared_ptr<Network::Stream> topLevelStream;
        if ((topLevelStream=weak_topLevelStream->lock())) {
        }else{
            std::tr1::shared_ptr<Network::Stream> tlstemp(Network::StreamFactory::getSingleton().getDefaultConstructor()(mIOService));
            (topLevelStream=tlstemp)->connect(addy,
                                              &Network::Stream::ignoreSubstreamCallback,
                                              &Network::Stream::ignoreConnectionStatus,
                                              &Network::Stream::ignoreBytesReceived);
            *weak_topLevelStream=tlstemp;
        }
        std::tr1::shared_ptr<Broadcast::BroadcastStream> bs(new BroadcastStream(topLevelStream,NULL));
        std::tr1::shared_ptr<Broadcast::BroadcastStream> weak_bs(bs);
        retval=bs;
        newBroadcastStream=topLevelStream->clone(std::tr1::bind(&BroadcastStreamCallbacks::setBroadcastStreamCallbacksShared,
                                                                weak_bs,
                                                                cb,
                                                                _1,
                                                                _2));
        if (newBroadcastStream){
            *weak_topLevelStream=topLevelStream;
        }else {
            if (mTopLevelStreams.find(addy)!=mTopLevelStreams.end()) {
                mTopLevelStreams.erase(mTopLevelStreams.find(addy));
            }
            SILOG(broadcast,warning,"Toplevel stream failed to clone for address "<<addy.getHostName()<<':'<<addy.getService());
        }
    }
    if (retval)
        initiateHandshake(&*retval,addy,name);
    return retval;
}
Ejemplo n.º 17
0
void myfunc() {
        // Enable Front Face
        //glEnable(GL_CULL_FACE);
    const char *argv[1];
    argv[0]="elysia";
    int argc=1;
    static bool firstTime=true;
    {
        boost::unique_lock<boost::mutex> lok(*Elysia::gRenderLock);
        if (gKillGraphics ){
            gKillGraphics=false;
        }else {
            
        }
        if (firstTime)
            glutInit(&argc, (char**)argv);
        firstTime=false;
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
        glutInitWindowSize(Elysia::gDisplayWidth,Elysia::gDisplayHeight);

        gGlutWindowId=glutCreateWindow("This is the window title");
        glutIdleFunc(Idly);
        glutDisplayFunc(Elysia::Display);
        glutReshapeFunc(Elysia::Reshape);
//        glutTimerFunc(0,Timer,0);
        
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
        Elysia::gRenderCondition.notify_one();
    }
    myfuncInitialized=true;
	glutMainLoop();

    for (int i=0;i<10;++i) {
        printf("Testing thread: %d/10\n",i+1);
    }
    gKillGraphics=false;
}
Ejemplo n.º 18
0
void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
{
    HRESULT r;
    IShellLinkA *sl;
    IPersistFile *pf;

    r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                         &IID_IShellLinkA, (LPVOID*)&sl);
    lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
    if (r != S_OK)
        return;

    if (desc->description)
    {
        r = IShellLinkA_SetDescription(sl, desc->description);
        lok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
    }
    if (desc->workdir)
    {
        r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
        lok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
    }
    if (desc->path)
    {
        r = IShellLinkA_SetPath(sl, desc->path);
        lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
    }
    if (desc->pidl)
    {
        r = IShellLinkA_SetIDList(sl, desc->pidl);
        lok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
    }
    if (desc->arguments)
    {
        r = IShellLinkA_SetArguments(sl, desc->arguments);
        lok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
    }
    if (desc->showcmd)
    {
        r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
        lok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
    }
    if (desc->icon)
    {
        r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
        lok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
    }
    if (desc->hotkey)
    {
        r = IShellLinkA_SetHotkey(sl, desc->hotkey);
        lok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
    }

    r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (void**)&pf);
    lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
    if (r == S_OK)
    {
        LPOLESTR str;

    if (0)
    {
        /* crashes on XP */
        IPersistFile_GetCurFile(pf, NULL);
    }

        /* test GetCurFile before ::Save */
        str = (LPWSTR)0xdeadbeef;
        r = IPersistFile_GetCurFile(pf, &str);
        lok(r == S_FALSE ||
            broken(r == S_OK), /* shell32 < 5.0 */
            "got 0x%08x\n", r);
        lok(str == NULL, "got %p\n", str);

        r = IPersistFile_Save(pf, path, TRUE);
        if (save_fails)
        {
            todo_wine {
            lok(r == S_OK, "save failed (0x%08x)\n", r);
            }
        }
        else
        {
Ejemplo n.º 19
0
void AssetDownloadTask::updatePriority(float64 priority) {
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);
    mPriority = priority;
    for(ActiveDownloadMap::iterator it = mActiveDownloads.begin(); it != mActiveDownloads.end(); it++)
        it->second->updatePriority(priority);
}
Ejemplo n.º 20
0
void AssetDownloadTask::cancel() {
    boost::mutex::scoped_lock lok(mDependentDownloadMutex);
    cancelNoLock();
}
Ejemplo n.º 21
0
void test_results() {
    test_case cases[] = {
        {"1", 1},
        {"1 ", 1},
        {"(1)", 1},

        {"pi", 3.14159},
        {"atan(1)*4 - pi", 0},
        {"e", 2.71828},

        {"2+1", 2+1},
        {"(((2+(1))))", 2+1},
        {"3+2", 3+2},

        {"3+2+4", 3+2+4},
        {"(3+2)+4", 3+2+4},
        {"3+(2+4)", 3+2+4},
        {"(3+2+4)", 3+2+4},

        {"3*2*4", 3*2*4},
        {"(3*2)*4", 3*2*4},
        {"3*(2*4)", 3*2*4},
        {"(3*2*4)", 3*2*4},

        {"3-2-4", 3-2-4},
        {"(3-2)-4", (3-2)-4},
        {"3-(2-4)", 3-(2-4)},
        {"(3-2-4)", 3-2-4},

        {"3/2/4", 3.0/2.0/4.0},
        {"(3/2)/4", (3.0/2.0)/4.0},
        {"3/(2/4)", 3.0/(2.0/4.0)},
        {"(3/2/4)", 3.0/2.0/4.0},

        {"(3*2/4)", 3.0*2.0/4.0},
        {"(3/2*4)", 3.0/2.0*4.0},
        {"3*(2/4)", 3.0*(2.0/4.0)},

        {"asin sin .5", 0.5},
        {"sin asin .5", 0.5},
        {"ln exp .5", 0.5},
        {"exp ln .5", 0.5},

        {"asin sin-.5", -0.5},
        {"asin sin-0.5", -0.5},
        {"asin sin -0.5", -0.5},
        {"asin (sin -0.5)", -0.5},
        {"asin (sin (-0.5))", -0.5},
        {"asin sin (-0.5)", -0.5},
        {"(asin sin (-0.5))", -0.5},

        {"log10 1000", 3},
        {"log10 1e3", 3},
        {"log10 1000", 3},
        {"log10 1e3", 3},
        {"log10(1000)", 3},
        {"log10(1e3)", 3},
        {"log10 1.0e3", 3},
        {"10^5*5e-5", 5},

#ifdef TE_NAT_LOG
        {"log 1000", 6.9078},
        {"log e", 1},
        {"log (e^10)", 10},
#else
        {"log 1000", 3},
#endif

        {"ln (e^10)", 10},
        {"100^.5+1", 11},
        {"100 ^.5+1", 11},
        {"100^+.5+1", 11},
        {"100^--.5+1", 11},
        {"100^---+-++---++-+-+-.5+1", 11},

        {"100^-.5+1", 1.1},
        {"100^---.5+1", 1.1},
        {"100^+---.5+1", 1.1},
        {"1e2^+---.5e0+1e0", 1.1},
        {"--(1e2^(+(-(-(-.5e0))))+1e0)", 1.1},

        {"sqrt 100 + 7", 17},
        {"sqrt 100 * 7", 70},
        {"sqrt (100 * 100)", 100},

        {"1,2", 2},
        {"1,2+1", 3},
        {"1+1,2+2,2+1", 3},
        {"1,2,3", 3},
        {"(1,2),3", 3},
        {"1,(2,3)", 3},
        {"-(1,(2,3))", -3},

        {"2^2", 4},
        {"pow(2,2)", 4},

        {"atan2(1,1)", 0.7854},
        {"atan2(1,2)", 0.4636},
        {"atan2(2,1)", 1.1071},
        {"atan2(3,4)", 0.6435},
        {"atan2(3+3,4*2)", 0.6435},
        {"atan2(3+3,(4*2))", 0.6435},
        {"atan2((3+3),4*2)", 0.6435},
        {"atan2((3+3),(4*2))", 0.6435},

    };


    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_case); ++i) {
        const char *expr = cases[i].expr;
        const double answer = cases[i].answer;

        int err;
        const double ev = te_interp(expr, &err);
        lok(!err);
        lfequal(ev, answer);

        if (err) {
            printf("FAILED: %s (%d)\n", expr, err);
        }
    }
}
Ejemplo n.º 22
0
void test_variables() {

    double x, y, test;
    te_variable lookup[] = {{"x", &x}, {"y", &y}, {"test", &test}};

    int err;

    te_expr *expr1 = te_compile("cos x + sin y", lookup, 2, &err);
    lok(expr1);
    lok(!err);

    te_expr *expr2 = te_compile("x+x+x-y", lookup, 2, &err);
    lok(expr2);
    lok(!err);

    te_expr *expr3 = te_compile("x*y^3", lookup, 2, &err);
    lok(expr3);
    lok(!err);

    te_expr *expr4 = te_compile("test+5", lookup, 3, &err);
    lok(expr4);
    lok(!err);

    for (y = 2; y < 3; ++y) {
        for (x = 0; x < 5; ++x) {
            double ev;

            ev = te_eval(expr1);
            lfequal(ev, cos(x) + sin(y));

            ev = te_eval(expr2);
            lfequal(ev, x+x+x-y);

            ev = te_eval(expr3);
            lfequal(ev, x*y*y*y);

            test = x;
            ev = te_eval(expr4);
            lfequal(ev, x+5);
        }
    }

    te_free(expr1);
    te_free(expr2);
    te_free(expr3);
    te_free(expr4);



    te_expr *expr5 = te_compile("xx*y^3", lookup, 2, &err);
    lok(!expr5);
    lok(err);

    te_expr *expr6 = te_compile("tes", lookup, 3, &err);
    lok(!expr6);
    lok(err);

    te_expr *expr7 = te_compile("sinn x", lookup, 2, &err);
    lok(!expr7);
    lok(err);

    te_expr *expr8 = te_compile("si x", lookup, 2, &err);
    lok(!expr8);
    lok(err);
}