Implement tests for initializing the model
This commit is contained in:
parent
1219b8c513
commit
8083d5eb3b
@ -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<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; };
|
||||
// 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<uint> 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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user