QMol_test - fmauger1/QMol-grid GitHub Wiki
QMol_test
Parent class for test-suite units.
Description
QMol_test
defines an abstract class handling the suite of unit tests available to the QMol-grid package.
Class properties
QMol_test
private properties are used internally to keep track of run-time parameters and results. These are of no use to end users or developers.
Class methods
Creation
QMol_test
is an abstract class and cannot be instantiated.
Unit test facilities
QMol_test
defines a series of facilities that can be used when developing unit tests for a component of the QMol-grid package.
showSection
Display a section header in the unit test
obj.showSection('Section name');
This displays the line
* Section name
Section headers are displayed when running the test suite in summary mode.
showResult
Report a successful unit test
obj.showResult('test name',true);
If running the test suite in summary mode no output is produced; otherwise, this displays the line
> test name PASS
with the 'PASS' flag right justified to the width of the test-suite display
Report and unsuccessful unit test
obj.showResult('test name',false);
Irrespective of running the test suite in summary mode or not, this displays the line
> test name *FAIL
and updates the internal counter keeping track of the status of the suite of tests being run.
Support for DFT unit tests
QMol_test
provides a handful of methods commonly used in test units for DFT models. These methods are static and can only be querried by classes overloading QMol_test
(protected).
DFT_1D_LDA_eps_x
Compute the exchange-energy per particle for one-dimensional local-density approximation (LDA) Slater exchange
Ex = DFT_1D_LDA_eps_x(funV,rho);
funV
is a handle function describing the electron-electron interaction potential for which the exchange-energy per particle should be computedrho
is a scalar, vector, matrix, or array containing the values of the one-body density for which the exchange-energy per particle should be computed- The output
Ex
has the same shape asrho
and contains the result exchange-energy per particle - For a given electron-electron interaction potential $
{\mathcal{V}}_{{\mathrm{e}\mathrm{e}}}
$ , the exchange-energy per particle for the 1D LDA Slater exchange is defined as
$$ \varepsilon_{{\mathrm{X}}} (\rho )=-\int_0^{\infty } \frac{\sin^2 u}{\pi u^2 }{\mathcal{V}}_{{\mathrm{e}\mathrm{e}}} \left(\frac{2u}{\pi \rho }\right)~du. $$
DFT_1D_LDA_d_eps_x
Compute the derivative of the exchange-energy per particle for one-dimensional local-density approximation (LDA) Slater exchange
Ex = DFT_1D_LDA_d_eps_x(funDV,rho);
funDV
is a handle function describing the derivative of the electron-electron interaction potential for which the exchange-energy per particle should be computedrho
is a scalar, vector, matrix, or array containing the values of the one-body density for which the derivative of the exchange-energy per particle should be computed- The output
Ex
has the same shape asrho
and contains the result exchange-energy per particle - For a given electron-electron interaction potential ${\mathcal{V}}_{{\mathrm{e}\mathrm{e}}}(r)$ , the exchange-energy per particle for the 1D LDA Slater exchange is defined as
$$ \partial_{\rho } \varepsilon_{{\mathrm{X}}} (\rho )=\int_0^{\infty } \frac{2\sin^2 u}{\pi \rho^2 u}\partial_r {\mathcal{V}}_{{\mathrm{e}\mathrm{e}}} \left(\frac{2u}{\pi \rho }\right)~du. $$
Test suite
For consistency with the rest of the QMol-grid package, QMol_test
defines an associated test suite. Run the test suite for the class in normal or summary mode respectively with
QMol_test.test('test');
QMol_test.test('-summary','test');
For developers
List of unit tests
The available list of unit tests is defined by the showComponents
method. Internally it is outsourced to the QMol_testInfo
class through its testList
method; this is where new test units should be added.
Creating a test suite for a new class
To create a test suite associated with a new class in the QMol-grid package, create a new MATLAB class with the following template
classdef QMol_test_className < QMol_test
%QMol_test_className suite of unit tests for QMol_className
%% Documentation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods (Static,Access=?QMol_test)
function version
QMol_doc.showVersion('xx.xx.xxx','XX/XX/XXX','Developer name')
end
end
methods (Static,Access={?QMol_doc,?QMol_test})
function showInfo
fprintf(' * QMol_test_className\n');
QMol_test_className.version;
end
end
%% Run tests%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods (Access=?QMol_test)
function testUnit(obj)
%testUnit run all unit tests on the class
% Add unite tests here
obj.showResult('example of successful test',true);
obj.showResult('example of failed test',false);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
Note that the names for both the new class and its test suite must follow the name convention for the QMol-grid package:
- For the new class: the name should begin with
QMol_
followed by the specific name for the class -- in the template aboveclassName
to formQMol_className
. - For its associated test suite: the name should begin with
QMol_test_
followed by the same specific name for the class -- formingQMol_test_className
in the template above.
Notes
QMol_test
was introduced in version 01.00.- Run-time documentation features were moved from
QMol_suite
in version 01.10.