main.cpp 3.31 KB
Newer Older
刘乐's avatar
刘乐 committed
1 2
#include <iostream>
#include <libpq-fe.h>
刘乐's avatar
刘乐 committed
3
#include "CivHydrFuncInter.h"
4 5
#include "iostream"
#include "time.h"
刘乐's avatar
刘乐 committed
6
#include <time.h>
7
#include "string.h"
刘乐's avatar
刘乐 committed
8 9
#include "CivTestContext.h"
#include "CivHydrTest.h"
刘乐's avatar
刘乐 committed
10 11
#include <vector>
#include <string>
刘乐's avatar
刘乐 committed
12
#include <stdlib.h>
刘乐's avatar
刘乐 committed
13

刘乐's avatar
刘乐 committed
14 15
#include <windows.h>
#include <consoleapi2.h>
刘乐's avatar
刘乐 committed
16

刘乐's avatar
刘乐 committed
17
#include "JsonParseObject.h"
刘乐's avatar
刘乐 committed
18

19
using namespace std;
刘乐's avatar
刘乐 committed
20

刘乐's avatar
刘乐 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
double random(int min, int max)
{
	double m1 = (double)(rand() % 101) / 101;                        // 计算 0,1之间的随机小数,得到的值域近似为(0,1)
	min++;                                                                             //将 区间变为(min+1,max),
	double m2 = (double)((rand() % (max - min + 1)) + min);    //计算 min+1,max 之间的随机整数,得到的值域为[min+1,max]
	m2 = m2 - 1;       //令值域为[min,max-1]

	double dd = (m1 + m2) * 100;
	double res = (int)dd;
	return res / 100;                                                                //返回值域为(min,max),为所求随机浮点
}
// 测试json解析字符出
void testJson()
{
	std::string jsonstr = "{\"监测点1\":{\"min\":20,\"max\":30},\"监测点2\":{\"min\":28.5,\"max\":32.4},\"雄楚大道\":{\"min\":23,\"max\":31.9}}";
	JsonParseObject parseObj;
	parseObj.parse(jsonstr);

	map<string, vector<double>> resMap;
	parseObj.read(resMap);

	parseObj.clear();
}

刘乐's avatar
刘乐 committed
45 46
int main(int argc, char* argv[])
{
刘乐's avatar
刘乐 committed
47 48 49
	double res = random(0, 1);
	std::cout<< res <<std::endl;
	// testJson();
刘乐's avatar
刘乐 committed
50 51
	while (true)
	{
刘乐's avatar
刘乐 committed
52
		const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
刘乐's avatar
刘乐 committed
53
		char* findUri = const_cast<char*>(uri);
刘乐's avatar
刘乐 committed
54

刘乐's avatar
刘乐 committed
55
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
刘乐's avatar
刘乐 committed
56
		cout << "水力模型接口测试,请输入对应的测试号:(输入0退出)\n";
刘乐's avatar
刘乐 committed
57 58 59 60 61 62
		cout << "\t1.水力接口测试\n";
		cout << "\t2.水质计算接口测试\n";
		cout << "\t3.追踪测试\n";
		cout << "\t4.上游追踪\n";
		cout << "\t5.下游追踪\n";
		cout << "\t6.水源供水范围分析\n";
刘乐's avatar
刘乐 committed
63
		cout << "\t7.方案模拟\n";
刘乐's avatar
刘乐 committed
64
		cout << "\t8.优化调度测试\n";
刘乐's avatar
刘乐 committed
65

刘乐's avatar
刘乐 committed
66 67 68 69 70 71
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
		int test_no;
		cout << "请输入:";
		cin >> test_no;
		cout << "你选择的测试号是:" << test_no << endl;
		CivTestContext context;
刘乐's avatar
刘乐 committed
72

刘乐's avatar
刘乐 committed
73 74 75
		clock_t start, end;
		start = clock();
		
刘乐's avatar
刘乐 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
		switch (test_no)
		{
		case 0://退出
			exit(0);
			break;
		case 1://1.测试水力
			context.setHydrTest(new CivConHydrTest());
			context.contextTest(findUri);
			break;
		case 2://测试水质
			context.setHydrTest(new CivConQuaTest());
			context.contextTest(findUri);
			break;
		case 3://3.测试追踪
			context.setHydrTest(new CivConTrackTest());
			context.contextTest(findUri);
			break;
		case 4://4.测试上游追踪
			context.setHydrTest(new CivUpstreamTrackingTest());
			context.contextTest(findUri);
			break;
		case 5://5.测试下游追踪
			context.setHydrTest(new CivDownStreamTrackingTest());
			context.contextTest(findUri);
			break;
		case 6://6.测试水源供水范围
			context.setHydrTest(new CivWaterSupplyScopeTest());
			context.contextTest(findUri);
			break;
105

刘乐's avatar
刘乐 committed
106 107 108 109
		case 7://6.测试水源供水范围
			context.setHydrTest(new CivProjSimulationTest());
			context.contextTest(findUri);
			break;
刘乐's avatar
刘乐 committed
110 111

		case 8: // 8 优化调度测试
刘乐's avatar
刘乐 committed
112 113
			context.setHydrTest(new CivOptSchedulingTest());
			context.contextTest(findUri);
刘乐's avatar
刘乐 committed
114
			break;
刘乐's avatar
刘乐 committed
115 116 117 118
		default:
			cout << "输入测试号错误!" << endl;
			break;
		}
刘乐's avatar
刘乐 committed
119 120
		end = clock();
		cout << (end - start)/1000 << endl;
刘乐's avatar
刘乐 committed
121
	}
刘乐's avatar
刘乐 committed
122
  
123
    return 0;
刘乐's avatar
刘乐 committed
124
}