forked from scicomp-durham/gray-scott-sim
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c321a5c
commit d1f5472
Showing
1 changed file
with
34 additions
and
27 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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
#include "gs/gs.h" | ||
#include <gtest/gtest.h> | ||
|
||
TEST(GSTests, CountElementsAboveThreshold) { | ||
double threshold = 0.5; | ||
double count = countElementsAboveThreshold(threshold); | ||
ASSERT_GE(count, 0.0); | ||
ASSERT_LE(count, 1.0); | ||
// Test 0.1: Check that the type of the model parameters (F, k) matches that of the element type of the u and v vectors. | ||
TEST(GSTests, CheckParameterTypes) { | ||
// Check if types of F and k match the type of elements in u and v | ||
ASSERT_TRUE((std::is_same<decltype(F), double>::value)); | ||
ASSERT_TRUE((std::is_same<decltype(k), double>::value)); | ||
using UElementType = decltype(u[0][0]); | ||
using VElementType = decltype(v[0][0]); | ||
ASSERT_TRUE(typeid(F).name() == typeid(UElementType).name() && typeid(k).name() == typeid(VElementType).name()); | ||
// std::cout << "Test1 Passed!" << std::endl; | ||
} | ||
|
||
TEST(GSTests, GridInitializationTest) { | ||
|
||
const int width = 256; | ||
const int height = 256; | ||
|
||
init(); | ||
// Test 0.2: Check that the variables u and v are the same size. | ||
TEST(GSTests, CheckSameSize) { | ||
// Check if u and v have the same dimensions | ||
EXPECT_EQ(u.size(), v.size()); | ||
for (size_t i = 0; i < u.size(); ++i) { | ||
EXPECT_EQ(u[i].size(), v[i].size()); | ||
} | ||
} | ||
|
||
for (int x = 0; x < width; ++x) { | ||
for (int y = 0; y < height; ++y) { | ||
EXPECT_EQ(u[x][y], 1.0); | ||
// Test 0.3: Check that the simulation produces the mathematically correct answer when u = 0 and v = 0. | ||
TEST(GSTests, writeVTKFile) { | ||
for (auto &row : u) | ||
std::fill(row.begin(), row.end(), 0.0); | ||
for (auto &row : v) | ||
std::fill(row.begin(), row.end(), 0.0); | ||
|
||
if (x >= 100 && x <= 200 && y >= 100 && y <= 150){ | ||
EXPECT_GE(v[x][y], 0.0); | ||
EXPECT_LE(v[x][y], 1.0); | ||
} | ||
else { | ||
EXPECT_EQ(v[x][y], 0.0); | ||
} | ||
simulateStep(); | ||
for (size_t x = 1; x < width - 1; ++x) { | ||
for (size_t y = 1; y < height - 1; ++y) { | ||
// When both u and v are 0, the result should stay 0 (assuming no external feed or kill rates) | ||
EXPECT_DOUBLE_EQ(0.0018, u[x][y]); | ||
EXPECT_DOUBLE_EQ(0.0, v[x][y]); | ||
} | ||
} | ||
std::cout << "Simulation check successful: u increases to 0.0018 and v remains at 0." << std::endl; | ||
} | ||
|
||
TEST(GSTests, writeVTKFile) { | ||
// Your code here, modify the following lines | ||
int iteration = 0; | ||
writeVTKFile(iteration); | ||
EXPECT_EQ(1.0, 1.0); | ||
} | ||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |