Implement tests for initializing the model

This commit is contained in:
Cory Balaton 2023-10-31 20:11:48 +01:00
parent 1219b8c513
commit 8083d5eb3b
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B

View File

@ -6,18 +6,32 @@
class IsingModelTest { class IsingModelTest {
public: public:
void test_constructor() void test_init_functions()
{ {
IsingModel test(3, 1.); IsingModel test;
test.L = 3;
test.T = 1.;
arma::Mat<int> a(3, 3); // Test that initializing the lattice only yields 1s and -1s.
test.initialize_lattice();
std::function<bool(int)> f = [](int x) { return x == 1 || x == -1; }; std::function<bool(int)> f = [](int x) { return x == 1 || x == -1; };
// unmangled ASSERT(assert_each(f, test.lattice), "Test lattice initialization.");
int status = 0;
char *demangled = abi::__cxa_demangle(typeid(f).name(), 0, 0, &status); test.initialize_neighbors();
std::cout << "Type: " << demangled << std::endl; arma::Mat<uint> neighbor_matrix("2, 1 ; 0, 2 ; 1, 0");
ASSERT(assert_each(f, test.lattice), ASSERT(is_equal(neighbor_matrix, test.neighbors),
"Testing that lattices contain only 1 and -1"); "Test neighbor matrix.");
// Fill the lattice with 1s to be able to test the next functions.
test.lattice.fill(1);
// Test the initial magnetization.
test.initialize_magnetization();
ASSERT(test.M == 9, "Test intial magnetization");
// Test that the initial energy is correct
test.initialize_energy();
ASSERT(test.E == -18, "Test initial energy.");
} }
}; };
@ -25,5 +39,5 @@ int main()
{ {
IsingModelTest test; IsingModelTest test;
test.test_constructor(); test.test_init_functions();
} }