Skip to content
Snippets Groups Projects
Commit 0d8ff5f4 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/container-variable-precision' into 'master'

Feature/container variable precision

See merge request !1553
parents 929be909 af74061f
No related branches found
No related tags found
1 merge request!1553Feature/container variable precision
......@@ -28,6 +28,8 @@
#define DUMUX_IO_CONTAINER_HH
#include <iostream>
#include <ios>
#include <iomanip>
#include <fstream>
#include <iterator>
......@@ -43,9 +45,11 @@ namespace Dumux {
*/
template<typename Container>
void writeContainerToFile(const Container& v,
const std::string& filename)
const std::string& filename,
int floatPrecision = 6)
{
std::ofstream outfile(filename, std::ios::out);
outfile << std::scientific << std::setprecision(floatPrecision);
std::ostream_iterator<typename Container::value_type> it(outfile, "\n");
std::copy(v.begin(),v.end(), it);
}
......
......@@ -38,9 +38,9 @@
namespace Dumux {
template<typename T>
bool testContainerIO(const T& c0)
bool testContainerIO(const T& c0, int floatPrecision = 6)
{
writeContainerToFile(c0, "container.txt");
writeContainerToFile(c0, "container.txt", floatPrecision);
auto c1 = readFileToContainer<T>("container.txt");
return std::equal(c0.begin(), c0.end(), c1.begin());
}
......@@ -80,6 +80,11 @@ int main()
passed = passed && Dumux::testContainerIO<std::deque<double>>(doublei);
if (!passed) return 1;
auto doublepreci = {1.23456789123456, 1.23456789123456, 9.87654321987654};
passed = passed && Dumux::testContainerIO<std::vector<double>>(doublepreci, 15);
passed = passed && !Dumux::testContainerIO<std::vector<double>>(doublepreci, 7);
if (!passed) return 1;
auto inti = {5, 6, 7, 5, 2, 8};
passed = passed && Dumux::testContainerIO<std::vector<int>>(inti);
passed = passed && Dumux::testContainerIO<std::list<int>>(inti);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment