ningshuxia
7 天以前 9eb7f4af097fb41b81fbff725d930cd6ab052c97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 ******************************************************************************
 Project:      OWA EPANET
 Version:      2.2
 Module:       test_demand.cpp
 Description:  Tests EPANET toolkit api functions
 Authors:      see AUTHORS
 Copyright:    see AUTHORS
 License:      see LICENSE
 Last Updated: 03/21/2019
 ******************************************************************************
*/
 
#include <boost/test/unit_test.hpp>
 
#include "test_toolkit.hpp"
 
 
BOOST_AUTO_TEST_SUITE (test_demand)
 
 
BOOST_AUTO_TEST_CASE(test_categories_save)
{
    int error = 0;
    int Nindex, ndem;
 
    EN_Project ph = NULL;
 
    error = EN_createproject(&ph);
    error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
 
    error = EN_getnodeindex(ph, (char *)"12", &Nindex);
    BOOST_REQUIRE(error == 0);
    error = EN_getnumdemands(ph, Nindex, &ndem);
    BOOST_REQUIRE(error == 0);
    BOOST_CHECK(ndem == 1);
 
    char demname[31];
    error = EN_getdemandname(ph, Nindex, ndem, demname);
    BOOST_REQUIRE(error == 0);
 
    error = EN_setdemandname(ph, Nindex, ndem, (char *)"CUB_SCOUT_MOTOR_POOL");
    BOOST_REQUIRE(error == 0);
    error = EN_saveinpfile(ph, "net1_dem_cat.inp");
    BOOST_REQUIRE(error == 0);
 
    error = EN_close(ph);
    BOOST_REQUIRE(error == 0);
    error = EN_deleteproject(ph);
    BOOST_REQUIRE(error == 0);
}
 
 
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demand/test_categories_save"))
{
    int error = 0;
    int Nindex, ndem;
 
    EN_Project ph = NULL;
 
    BOOST_TEST_CHECKPOINT("Reopening saved input file");
    error = EN_createproject(&ph);
    BOOST_REQUIRE(error == 0);
    error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
    BOOST_REQUIRE(error == 0);
 
    error = EN_getnodeindex(ph, (char *)"12", &Nindex);
    BOOST_REQUIRE(error == 0);
    error = EN_getnumdemands(ph, Nindex, &ndem);
    BOOST_REQUIRE(error == 0);
    BOOST_CHECK(ndem == 1);
 
    char demname[31];
    error = EN_getdemandname(ph, Nindex, ndem, demname);
    BOOST_CHECK(error == 0);
 
    BOOST_CHECK(check_string(demname, "CUB_SCOUT_MOTOR_POOL"));
 
    error = EN_close(ph);
    BOOST_REQUIRE(error == 0);
    error = EN_deleteproject(ph);
    BOOST_REQUIRE(error == 0);
}
 
BOOST_FIXTURE_TEST_CASE(test_adddemand, FixtureSingleNode)
{
    int Dindex, nD1, nD2;
 
    error = EN_adddemand(ph, node_qhut, 100.0, "PrimaryPattern", "PrimaryDemand");
    BOOST_CHECK(error != 0);
 
    error = EN_addpattern(ph, (char *)"PrimaryPattern");
    BOOST_REQUIRE(error == 0);
 
    error = EN_adddemand(ph, node_qhut, 100.0, "PrimaryPattern", "PrimaryDemand");
    BOOST_CHECK(error == 0);
 
    error = EN_addpattern(ph, (char *)"SecondaryPattern");
    BOOST_REQUIRE(error == 0);
 
    error = EN_adddemand(ph, node_qhut, 10.0, "SecondaryPattern", "SecondaryDemand");
    BOOST_CHECK(error == 0);
 
    error = EN_addpattern(ph, (char *)"TertiaryPattern");
    BOOST_REQUIRE(error == 0);
 
    error = EN_adddemand(ph, node_qhut, 1.0, "TertiaryPattern", "TertiaryDemand");
    BOOST_CHECK(error == 0);
 
    error = EN_getnumdemands(ph, node_qhut, &nD1);
    BOOST_REQUIRE(error == 0);
 
    error = EN_getdemandindex(ph, node_qhut, "TertiaryDemand", &Dindex);
    BOOST_CHECK(error == 0);
    BOOST_CHECK(Dindex == nD1);
 
    error = EN_deletedemand(ph, node_qhut, Dindex);
    BOOST_CHECK(error == 0);
 
    error = EN_getnumdemands(ph, node_qhut, &nD2);
    BOOST_REQUIRE(error == 0);
    BOOST_CHECK(nD1 - nD2 == 1);
}
 
 
BOOST_AUTO_TEST_SUITE_END()