Skip to content

Commit 7abb3b7

Browse files
committed
Refactor and add test
1 parent 54b7b93 commit 7abb3b7

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

include/inch/dripline.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ class DripLine
259259
*/
260260
[[nodiscard]] virtual std::string TearDown() const = 0;
261261

262+
/**
263+
* Write a comment into the file to say what is about to be done
264+
*
265+
* \param Nothing
266+
*
267+
* \return The string that can be written to file
268+
*/
269+
[[nodiscard]] virtual std::string Header() const = 0;
270+
262271
/**
263272
* Read the necessary file for data and output eps code into the chart being created
264273
*

include/inch/eps_dripline.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ class EPSDripLine : public DripLine
7070
"gr\n");
7171
}
7272

73+
/**
74+
* Write a comment into the file to say what is about to be done
75+
*
76+
* \param Nothing
77+
*
78+
* \return The string that can be written to file
79+
*/
80+
[[nodiscard]] inline std::string Header() const override
81+
{
82+
switch (the_line)
83+
{
84+
case LineType::singleneutron:
85+
default:
86+
return "\n%Neutron Drip Line\n";
87+
case LineType::doubleneutron:
88+
return "\n%Two Neutron Drip Line\n";
89+
case LineType::singleproton:
90+
return "\n%Proton Drip Line\n";
91+
case LineType::doubleproton:
92+
return "\n%Two Proton Drip Line\n";
93+
}
94+
}
95+
7396
/**
7497
* Read the necessary file for data and output eps code into the chart being created
7598
*

src/eps_dripline.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,7 @@ int EPSDripLine::WriteLine(std::ostream& outFile) const
2424

2525
fmt::print("Reading {} and drawing the drip line", drip_file);
2626

27-
const std::string header = [&]() {
28-
switch (the_line)
29-
{
30-
case LineType::singleneutron:
31-
default:
32-
return "\n%Neutron Drip Line\n";
33-
case LineType::doubleneutron:
34-
return "\n%Two Neutron Drip Line\n";
35-
case LineType::singleproton:
36-
return "\n%Proton Drip Line\n";
37-
case LineType::doubleproton:
38-
return "\n%Two Proton Drip Line\n";
39-
}
40-
}();
41-
42-
fmt::print(outFile, "{}{}", header, Setup());
27+
fmt::print(outFile, "{}{}", Header(), Setup());
4328

4429
// We make the file that is read and it always has
4530
// - one line as a header

tests/dripline_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class DripLineForTest : public DripLine
2323

2424
[[nodiscard]] inline std::string Setup() const override { return std::string(); }
2525
[[nodiscard]] inline std::string TearDown() const override { return std::string(); }
26+
[[nodiscard]] inline std::string Header() const override { return std::string(); }
2627
inline int WriteLine(std::ostream& /*outFile*/) const override { return 0; }
2728
};
2829

tests/eps_dripline_test.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const Limits limits;
88

9-
TEST_CASE("EPS dripline setup is correct", "[EPSDripLine]")
9+
TEST_CASE("EPS dripline setup", "[EPSDripLine]")
1010
{
1111
const EPSDripLine dripline(1.0, 2.0, limits, LineType::singleproton, "green");
1212
const auto setup{ "gs\n"
@@ -17,7 +17,7 @@ TEST_CASE("EPS dripline setup is correct", "[EPSDripLine]")
1717
}
1818

1919

20-
TEST_CASE("EPS dripline teardown is correct", "[EPSDripLine]")
20+
TEST_CASE("EPS dripline teardown", "[EPSDripLine]")
2121
{
2222
const EPSDripLine dripline(1.0, 2.0, limits, LineType::doubleneutron, "black");
2323

@@ -27,6 +27,33 @@ TEST_CASE("EPS dripline teardown is correct", "[EPSDripLine]")
2727
REQUIRE_THAT(teardown, Catch::Equals(dripline.TearDown()));
2828
}
2929

30+
31+
TEST_CASE("EPS dripline comment", "[EPSDripLine]")
32+
{
33+
EPSDripLine dripline(1.0, 2.0, limits, LineType::doubleneutron, "black");
34+
35+
SECTION("Double neutron") { REQUIRE_THAT("\n%Two Neutron Drip Line\n", Catch::Equals(dripline.Header())); }
36+
37+
SECTION("Single proton")
38+
{
39+
dripline.the_line = LineType::singleproton;
40+
REQUIRE_THAT("\n%Proton Drip Line\n", Catch::Equals(dripline.Header()));
41+
}
42+
43+
SECTION("Single neutron")
44+
{
45+
dripline.the_line = LineType::singleneutron;
46+
REQUIRE_THAT("\n%Neutron Drip Line\n", Catch::Equals(dripline.Header()));
47+
}
48+
49+
SECTION("Double proton")
50+
{
51+
dripline.the_line = LineType::doubleproton;
52+
REQUIRE_THAT("\n%Two Proton Drip Line\n", Catch::Equals(dripline.Header()));
53+
}
54+
}
55+
56+
3057
TEST_CASE("EPS dripline create file if necessary", "[EPSDripLine]")
3158
{
3259
EPSDripLine dripline(1.0, 2.0, limits, LineType::singleneutron, "black");

0 commit comments

Comments
 (0)