-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvessel_tests.cpp
More file actions
114 lines (94 loc) · 3.08 KB
/
Copy pathvessel_tests.cpp
File metadata and controls
114 lines (94 loc) · 3.08 KB
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
//
// Created by jskad on 10-06-2024.
//
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "vessel.h"
#include "pretty_printer.h"
#include <fstream>
using namespace stochastic;
// Requirement 9
TEST_CASE("Vessel")
{
// Create a new Vessel to hold reactants and reactions
auto vessel = stochastic::Vessel{"Test"};
// Add initial reactants
const auto a = vessel.add("a", 1);
const auto b = vessel.add("b", 0);
const auto c = vessel.add("c", 2);
//Create pretty printer
auto pp = pretty_printer(vessel);
SUBCASE("Initial values for reactants")
{
CHECK((vessel.get("a") == 1));
CHECK((vessel.get("b") == 0));
CHECK((vessel.get("c") == 2));
}
SUBCASE("Getting nonexistent reactant throws error (Case a)")
{
CHECK_THROWS(vessel.get("d"));
}
SUBCASE("Adding existing reactant throws error (Case b)")
{
CHECK_THROWS(vessel.add("a", 0));
}
SUBCASE("Adding reactions to Vessel")
{
vessel.add(a >> 10.0 >>= b);
auto r1 = vessel.reactions[0];
CHECK((r1.inputs[0] == "a"));
CHECK((r1.rate == 10.0));
CHECK((r1.products[0] == "b"));
}
SUBCASE("Adding Reaction with unknown reactant throws error")
{
const std::string d = "d";
CHECK_THROWS(vessel.add(d >> 10 >>= a));
CHECK_THROWS(vessel.add(a >> 10 >>= d));
}
SUBCASE("Printing a single Reaction in human readable format")
{
vessel.add(a >> 10.0 >>= b);
auto oss = std::ostringstream();
auto r1 = vessel.reactions[0];
oss << r1;
CHECK(oss.str() == "a -[10]-> b");
}
SUBCASE("Printing Reaction network in human readable format")
{
vessel.add(a >> 10.0 >>= b);
vessel.add(a + b >> 0.5 >>= b + c);
auto oss = std::ostringstream();
std::streambuf* old_cout_buf = std::cout.rdbuf(oss.rdbuf());
pp.print_reactions();
std::cout.rdbuf(old_cout_buf);
CHECK(oss.str() == "a -[10]-> b\na + b -[0.5]-> b + c\n");
}
SUBCASE("Printing Reaction network as DOT graph")
{
vessel.add(a >> 10.0 >>= b);
vessel.add(a + b >> 0.5 >>= b + c);
pp.generate_network_graph("test_graph");
std::ifstream dotFile("test_graph.dot");
if (!dotFile.is_open()) {
std::cerr << "Error opening the file!" << std::endl;
CHECK(FALSE);
}
std::string content((std::istreambuf_iterator<char>(dotFile)), std::istreambuf_iterator<char>());
auto expected = "digraph {\n"
" c[shape=box];\n"
" b[shape=box];\n"
" a[shape=box];\n"
" r0[label=10,shape=oval];\n"
" a -> r0;\n"
" r0 -> b;\n"
" r1[label=0.5,shape=oval];\n"
" a -> r1;\n"
" b -> r1;\n"
" r1 -> b;\n"
" r1 -> c;\n"
"}\n";
CHECK((content == expected));
dotFile.close();
}
}