From 8083d5eb3b0f80d42a21e957a5c77113d5ad21ea Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 31 Oct 2023 20:11:48 +0100 Subject: [PATCH] Implement tests for initializing the model --- src/test_suite.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/test_suite.cpp b/src/test_suite.cpp index b36d9e7..4d3437d 100644 --- a/src/test_suite.cpp +++ b/src/test_suite.cpp @@ -6,18 +6,32 @@ class IsingModelTest { public: - void test_constructor() + void test_init_functions() { - IsingModel test(3, 1.); + IsingModel test; + test.L = 3; + test.T = 1.; - arma::Mat a(3, 3); + // Test that initializing the lattice only yields 1s and -1s. + test.initialize_lattice(); std::function f = [](int x) { return x == 1 || x == -1; }; - // unmangled - int status = 0; - char *demangled = abi::__cxa_demangle(typeid(f).name(), 0, 0, &status); - std::cout << "Type: " << demangled << std::endl; - ASSERT(assert_each(f, test.lattice), - "Testing that lattices contain only 1 and -1"); + ASSERT(assert_each(f, test.lattice), "Test lattice initialization."); + + test.initialize_neighbors(); + arma::Mat neighbor_matrix("2, 1 ; 0, 2 ; 1, 0"); + ASSERT(is_equal(neighbor_matrix, test.neighbors), + "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; - test.test_constructor(); + test.test_init_functions(); }