-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling local test files is added. Matrices comparison is now separa…
…te rotine that can be reused.
- Loading branch information
Showing
8 changed files
with
154 additions
and
74 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
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
76 changes: 15 additions & 61 deletions
76
src/SingleLayerOptics/tst/units/VenetianUniformShadeMatrix.unit.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,59 @@ | ||
#include <iomanip> | ||
|
||
#include "csvHandlers.hpp" | ||
|
||
namespace Helper | ||
{ | ||
void writeVectorToCSV(const std::vector<std::vector<double>> & data, | ||
const std::string & filename) | ||
{ | ||
std::ofstream file(filename); | ||
if(!file.is_open()) | ||
{ | ||
throw std::runtime_error("Could not open file to write"); | ||
} | ||
|
||
file << std::fixed << std::setprecision(9); // Set precision to 9 decimal places | ||
|
||
for(const auto & row : data) | ||
{ | ||
for(size_t i = 0; i < row.size(); ++i) | ||
{ | ||
file << row[i]; | ||
if(i < row.size() - 1) | ||
{ | ||
file << ","; // Add comma if not the last element | ||
} | ||
} | ||
file << "\n"; | ||
} | ||
file.close(); | ||
} | ||
|
||
std::vector<std::vector<double>> readVectorFromCSV(const std::string & filename) | ||
{ | ||
std::ifstream file(filename); | ||
if(!file.is_open()) | ||
{ | ||
throw std::runtime_error("Could not open file to read"); | ||
} | ||
|
||
std::vector<std::vector<double>> data; | ||
std::string line; | ||
|
||
while(std::getline(file, line)) | ||
{ | ||
std::vector<double> row; | ||
std::stringstream ss(line); | ||
std::string value; | ||
|
||
while(std::getline(ss, value, ',')) | ||
{ | ||
row.push_back(std::stod(value)); // Convert string to double and add to row | ||
} | ||
data.push_back(row); | ||
} | ||
file.close(); | ||
return data; | ||
} | ||
} // namespace Helper |
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,18 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <stdexcept> | ||
#include <iostream> | ||
|
||
namespace Helper | ||
{ | ||
// Function to write a 2D vector to a CSV file | ||
void writeVectorToCSV(const std::vector<std::vector<double>> & data, | ||
const std::string & filename); | ||
|
||
// Function to read a 2D vector from a CSV file | ||
std::vector<std::vector<double>> readVectorFromCSV(const std::string & filename); | ||
} // namespace Helper |
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,19 @@ | ||
#include "matrixTesting.hpp" | ||
|
||
namespace Helper | ||
{ | ||
void compareMatrices(const std::vector<std::vector<double>> & expected, | ||
const std::vector<std::vector<double>> & actual, | ||
double tolerance) | ||
{ | ||
ASSERT_EQ(expected.size(), actual.size()); | ||
for(size_t i = 0; i < expected.size(); ++i) | ||
{ | ||
ASSERT_EQ(expected[i].size(), actual[i].size()); | ||
for(size_t j = 0; j < expected[i].size(); ++j) | ||
{ | ||
EXPECT_NEAR(expected[i][j], actual[i][j], tolerance); | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include "gtest/gtest.h" | ||
|
||
namespace Helper | ||
{ | ||
void compareMatrices(const std::vector<std::vector<double>> & expected, | ||
const std::vector<std::vector<double>> & actual, | ||
double tolerance = 1e-6); | ||
} |