testdriver.cc

来自「CxxTester是一个用于C++代码的通用测试框。它支持测试库系统、有一套方法」· CC 代码 · 共 121 行

CC
121
字号
//----------------------------------------------------------------------////                                                                      //// TestDriver.cpp                                                       ////                                                                      //// this listing is a small example for the implementation of drivers    //// with more complex test interfaces.                                   ////----------------------------------------------------------------------//#include "CxxTester.h"//----------------------------------------------------------------------//// startup for linux                // startup for windows              ////----------------------------------------------------------------------//int main(int argc, char** argv)     //  BOOL CxxMain::InitInstance() {                                   //  {    return cxxloop(argc,argv);      //      return cxxloop();}                                   //  }//----------------------------------------------------------------------//// handling with arrays                                                 ////----------------------------------------------------------------------//cxxcall(average){    int x = 0;    int y = 0;    int ctr = 0;    int column = 0;    double sum = 0;    // check end of x dimension    while(DIN["array"][x][0].getType() == DS_INT)    {        // check end of y dimension        while(DIN["array"][x][y].getType() == DS_INT)        {            int val = DIN["array"][x][y];            column += val;            ctr++;            y++;        }        DOUT["column"][x] = column;        sum += column;        column = 0;        y = 0;        x++;    }    DOUT["sum"] = sum;    DOUT["ctr"] = ctr;    if(ctr > 0)    {         DOUT["avg"] = sum/ctr;    }}//----------------------------------------------------------------------//// handling with structs                                                ////----------------------------------------------------------------------//cxxcall(linecheck){    int xstart = DIN["start"]["x"];    int ystart = DIN["start"]["y"];    int xend   = DIN["end"]["x"];    int yend   = DIN["end"]["y"];    double dx = (xstart - xend)*(xstart - xend);    double dy = (ystart - yend)*(ystart - yend);    double length = sqrt(dx+dy);    DOUT["length"] = length;    int val;    val = xstart;    if(xend < xstart)    {        val = xend;    }    DOUT["min"]["x"] = val;    val = ystart;    if(yend < ystart)    {        val = yend;    }    DOUT["min"]["y"] = val;}//----------------------------------------------------------------------//// handling with combinations of structs and arrays                     ////----------------------------------------------------------------------//cxxcall(mixcolor){    int red   = 0;    int green = 0;    int blue  = 0;    int i = 0;    while(DIN["colors"][i]["name"].getType() == DS_STR)    {       int r = DIN["colors"][i]["red"];       int g = DIN["colors"][i]["green"];       int b = DIN["colors"][i]["blue"];       red   += r;       green += g;       blue  += b;       i++;    }    if(i > 0)    {        DOUT["mix"]["red"]   = red/i;        DOUT["mix"]["green"] = green/i;        DOUT["mix"]["blue"]  = blue/i;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?