Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IO tests for writing a Geojson from a EGOA network #47

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/IO/TestGeojsonWriter.cpp
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
87 changes: 87 additions & 0 deletions tests/IO/TestGeojsonWriter.hpp
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