Line data Source code
1 : /* 2 : * Copyright (c) 2017 Sebastian Weber, Henri Menke. All rights reserved. 3 : * 4 : * This file is part of the pairinteraction library. 5 : * 6 : * The pairinteraction library is free software: you can redistribute it and/or modify 7 : * it under the terms of the GNU Lesser General Public License as published by 8 : * the Free Software Foundation, either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * The pairinteraction library is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU Lesser General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU Lesser General Public License 17 : * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : #include "EmbeddedDatabase.hpp" 21 : #include "QuantumDefect.hpp" 22 : #include "SQLite.hpp" 23 : 24 : #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 25 : #include <doctest/doctest.h> 26 : 27 1 : TEST_CASE("qd_test") // NOLINT 28 : { 29 3 : QuantumDefect qd("Rb", 45, 1, 0.5); 30 : 31 : // Check whether the input was stored correctly 32 1 : CHECK(qd.species == "Rb"); 33 1 : CHECK(qd.n == 45); 34 1 : CHECK(qd.l == 1); 35 1 : CHECK(qd.j == 0.5); 36 : 37 : // Check whether values are correctly read from the db 38 2 : EmbeddedDatabase db{}; 39 2 : sqlite::statement stmt(db); 40 1 : stmt.set("select ac,Z,a1,a2,a3,a4,rc from model_potential where ( (element " 41 2 : "= 'Rb') and (L = 1) );"); 42 : // The database should be consistent 43 1 : CHECK_NOTHROW(stmt.prepare()); 44 1 : CHECK_NOTHROW(stmt.step()); 45 : 46 : // Check the retrieved values 47 1 : double ac = stmt.get<double>(0); 48 1 : int Z = stmt.get<double>(1); 49 1 : double a1 = stmt.get<double>(2); 50 1 : double a2 = stmt.get<double>(3); 51 1 : double a3 = stmt.get<double>(4); 52 1 : double a4 = stmt.get<double>(5); 53 1 : double rc = stmt.get<double>(6); 54 : 55 1 : CHECK(qd.ac == ac); 56 1 : CHECK(qd.Z == Z); 57 1 : CHECK(qd.a1 == a1); 58 1 : CHECK(qd.a2 == a2); 59 1 : CHECK(qd.a3 == a3); 60 1 : CHECK(qd.a4 == a4); 61 1 : CHECK(qd.rc == rc); 62 1 : } 63 : 64 1 : TEST_CASE("qd_errors") // NOLINT 65 : { 66 3 : CHECK_THROWS_AS(QuantumDefect("nop", 0, 0, 0), std::exception); 67 3 : CHECK_THROWS_AS(QuantumDefect("Rb", 0, 10000, 0), std::exception); 68 : 69 : try { 70 2 : QuantumDefect qd("nop", 0, 0, 0); 71 2 : } catch (std::exception const &e) { 72 1 : CHECK(e.what()); 73 : } 74 : 75 : try { 76 2 : QuantumDefect qd("Rb", 0, 10000, 0); 77 2 : } catch (std::exception const &e) { 78 1 : CHECK(e.what()); 79 : } 80 1 : }