-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVenueTest.cpp
106 lines (89 loc) · 3.67 KB
/
VenueTest.cpp
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
#include <crow.h>
#include <string>
#include "Venue.h"
TEST_CASE("Testing Venue class functionality")
{
SUBCASE("Blank Parameter Constructor should throw an exception")
{
CHECK_THROWS_AS(Venue emptyCity("", "290 Blvd", 1.0), std::invalid_argument);
CHECK_THROWS_AS(Venue emptyAddress("Toronto ON", "", 1.0), std::invalid_argument);
CHECK_THROWS_AS(Venue negCost("Toronto ON", "290 Blvd", -1.0), std::invalid_argument);
}
SUBCASE("Blank Json Constructor should throw an exception")
{
CHECK_THROWS_AS(Venue emptyJCity(crow::json::load(R"({"city":"","address":"Music","cost":1.0})")), std::invalid_argument);
CHECK_THROWS_AS(Venue emptyJAddress(crow::json::load(R"({"city":"Band","address":"","cost":1.0})")), std::invalid_argument);
CHECK_THROWS_AS(Venue negJCost(crow::json::load(R"({"city":"Band","address":"Music","cost":-1.0})")), std::invalid_argument);
}
Venue pVenue("Toronto ON", "290 Blvd", 5.0);
Venue jVenue(crow::json::load(R"({"city":"Toronto ON","address":"290 Blvd","cost":5.0})"));
SUBCASE("getCity should return the set city")
{
CHECK(pVenue.getCity() == "Toronto ON");
CHECK(jVenue.getCity() == "Toronto ON");
}
SUBCASE("setCity should change the city")
{
CHECK(pVenue.setCity("Richmond VA") == "Richmond VA");
CHECK(pVenue.getCity() == "Richmond VA");
CHECK(jVenue.setCity("Roanoke VA") == "Roanoke VA");
CHECK(jVenue.getCity() == "Roanoke VA");
}
SUBCASE("setCity to blank should throw an exception")
{
CHECK_THROWS_AS(pVenue.setCity(""), std::invalid_argument);
CHECK_THROWS_AS(jVenue.setCity(""), std::invalid_argument);
}
SUBCASE("getAddress should return the set address")
{
CHECK(pVenue.getAddress() == "290 Blvd");
CHECK(jVenue.getAddress() == "290 Blvd");
}
SUBCASE("setAddress should change the address")
{
CHECK(pVenue.setAddress("1629 Rd") == "1629 Rd");
CHECK(pVenue.getAddress() == "1629 Rd");
CHECK(jVenue.setAddress("302 St") == "302 St");
CHECK(jVenue.getAddress() == "302 St");
}
SUBCASE("setAddress to blank should throw an exception")
{
CHECK_THROWS_AS(pVenue.setAddress(""), std::invalid_argument);
CHECK_THROWS_AS(jVenue.setAddress(""), std::invalid_argument);
}
SUBCASE("getCost should return the set cost")
{
CHECK(pVenue.getCost() == 5.0);
CHECK(jVenue.getCost() == 5.0);
}
SUBCASE("setCost should change the cost")
{
CHECK(pVenue.setCost(5.0) == 5.0);
CHECK(pVenue.getCost() == 5.0);
CHECK(jVenue.setCost(6.0) == 6.0);
CHECK(jVenue.getCost() == 6.0);
}
SUBCASE("setCost to negative should throw an exception")
{
CHECK_THROWS_AS(pVenue.setCost(-1.0), std::invalid_argument);
CHECK_THROWS_AS(pVenue.setCost(-1.0), std::invalid_argument);
}
SUBCASE("Testing the convertToJson Method")
{
crow::json::wvalue jsonOutput = pVenue.convertToJson();
crow::json::rvalue jsonReadValue = crow::json::load(jsonOutput.dump());
CHECK(jsonReadValue["city"].s() == "Toronto ON");
CHECK(jsonReadValue["address"].s() == "290 Blvd");
CHECK(jsonReadValue["cost"].d() == 5.0);
}
SUBCASE("Testing updateFromJson Method")
{
crow::json::rvalue updateJson = crow::json::load(R"({"city":"One","address":"Two","cost":20.0})");
pVenue.updateFromJson(updateJson);
CHECK(pVenue.getCity() == "One");
CHECK(pVenue.getAddress() == "Two");
CHECK(pVenue.getCost() == 20.0);
}
}