-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the Geojson writer (#47)
- Loading branch information
1 parent
f892c45
commit 5e69055
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* TestGeojsonWriter.cpp | ||
* | ||
* Created on: Nov 04, 2019 | ||
* Author: Franziska Wegner | ||
*/ | ||
|
||
#include "TestGeojsonWriter.hpp" | ||
#include "IO/Writer/GeojsonWriter.hpp" | ||
|
||
#include "Auxiliary/Types.hpp" | ||
#include "Helper/TestHelper.hpp" | ||
|
||
#include <fstream> | ||
#include <sstream> | ||
|
||
namespace egoa::test { | ||
|
||
TEST_F ( TestGeojsonExample, FilenameWriteTest ) | ||
{ | ||
if ( ! egoa::PowerGridIO<TGraph>::write ( network_ | ||
, TestCaseSmallExampleOutputFile_ | ||
, TPowerGridIO::WriteGeoJson ) ) | ||
{ | ||
ASSERT_TRUE(false); | ||
} | ||
} | ||
|
||
TEST_F ( TestGeojsonExample, OutputStreamWriteTest ) | ||
{ | ||
std::ofstream file; | ||
file.open(TestCaseSmallExampleOutputFile_, std::ofstream::trunc); | ||
if (!file.is_open()) return; | ||
file.seekp(0, std::ios::end); // file is empty | ||
|
||
if ( ! egoa::PowerGridIO<TGraph>::write ( network_ | ||
, file | ||
, TPowerGridIO::WriteGeoJson ) ) | ||
{ | ||
ASSERT_TRUE(false); | ||
} | ||
} | ||
|
||
TEST_F ( TestGeojsonExample, CompareGeneratedStringWithFile ) | ||
{ | ||
// Comparison string | ||
std::stringstream genfileStream; | ||
if ( ! egoa::PowerGridIO<TGraph>::write ( network_ | ||
, genfileStream | ||
, TPowerGridIO::WriteGeoJson ) ) | ||
{ | ||
EXPECT_TRUE(false); | ||
} | ||
Types::string genfile = genfileStream.str(); | ||
|
||
// Expected output converted to string | ||
std::ifstream inFile; inFile.open(TestCaseSmallExampleExpectedOutput_); | ||
std::stringstream expectedOutputStream; | ||
expectedOutputStream << inFile.rdbuf(); | ||
Types::string expectedOutput = expectedOutputStream.str(); | ||
|
||
EXPECT_EQ(expectedOutput,genfile); | ||
} | ||
|
||
} //namespace egoa::test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* TestGeojsonWriter.hpp | ||
* | ||
* Created on: Nov 04, 2019 | ||
* Author: Franziska Wegner | ||
*/ | ||
|
||
#ifndef EGOA___TESTS___IO___TEST_GEO_JSON_WRITER_HPP | ||
#define EGOA___TESTS___IO___TEST_GEO_JSON_WRITER_HPP | ||
|
||
#include "gtest/gtest.h" | ||
#include "gmock/gmock.h" | ||
|
||
#include "IO/PowerGridIO.hpp" | ||
|
||
#include "DataStructures/Networks/PowerGrid.hpp" | ||
|
||
#include "DataStructures/Graphs/StaticGraph.hpp" | ||
#include "DataStructures/Graphs/DynamicGraph.hpp" | ||
|
||
namespace egoa::test { | ||
|
||
class TestGeojsonWriter : public ::testing::Test { | ||
protected: | ||
// Vertices | ||
using TVertex = Vertices::Vertex<Vertices::ElectricalProperties<>>; | ||
using TVertexType = typename TVertex::TProperties::TVertexType; | ||
using TVertexProperties = typename TVertex::TProperties; | ||
// Edges | ||
using TEdge = Edges::Edge<Edges::ElectricalProperties>; | ||
using TEdgeProperties = typename TEdge::TProperties; | ||
// Network specific types | ||
using TGraph = StaticGraph< Vertices::ElectricalProperties<> | ||
, Edges::ElectricalProperties>; | ||
// Network specific types | ||
using TGeneratorProperties = Vertices::GeneratorProperties<>; | ||
using TLoadProperties = Vertices::LoadProperties<Vertices::IeeeBusType>; | ||
using TNetwork = PowerGrid<TGraph>; | ||
// IO | ||
using TPowerGridIO = PowerGridIO<TGraph>; | ||
|
||
protected: | ||
TestGeojsonWriter() | ||
: network_(){} | ||
|
||
TestGeojsonWriter( TNetwork & network ) | ||
: network_(){} | ||
|
||
// You can do clean-up work that doesn't throw exceptions here. | ||
virtual ~TestGeojsonWriter(){} | ||
|
||
protected: | ||
TGraph graph_; | ||
TGraph const & graphConst_ = graph_; | ||
TNetwork network_; | ||
TNetwork const & networkConst_ = network_; | ||
}; | ||
|
||
class TestGeojsonExample : public TestGeojsonWriter { | ||
protected: | ||
TestGeojsonExample () | ||
: TestGeojsonWriter () | ||
{} | ||
|
||
virtual void SetUp () override | ||
{ | ||
if ( ! egoa::PowerGridIO<TGraph>::read( network_ | ||
, graph_ | ||
, TestCaseSmallExampleInput_ | ||
, TPowerGridIO::ReadPyPsa ) ) | ||
{ | ||
std::cerr << "Expected file " | ||
<< TestCaseSmallExampleInput_ | ||
<< " does not exist!"; | ||
ASSERT_TRUE(false); | ||
} | ||
} | ||
|
||
Types::string const TestCaseSmallExampleInput_ = "../../framework/tests/Data/PowerGrids/PyPsaExampleGeoJsonWriter"; | ||
Types::string const TestCaseSmallExampleExpectedOutput_ = "../../framework/tests/Data/Output/PyPsaExampleJsonWriterExpectedOutput.json"; | ||
Types::string const TestCaseSmallExampleOutputFile_ = "../../framework/tests/Data/Output/PyPsaExampleJsonWriter.json"; | ||
}; | ||
|
||
|
||
} // namespace egoa::test | ||
|
||
#endif // EGOA___TESTS___IO___TEST_GEO_JSON_WRITER_HPP |