File: test_atomlist.f90

package info (click to toggle)
xtb 6.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,348 kB
  • sloc: f90: 139,236; fortran: 2,948; ansic: 2,215; makefile: 71; sh: 17; csh: 7; tcl: 7
file content (156 lines) | stat: -rw-r--r-- 4,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
! This file is part of xtb.
! SPDX-Identifier: LGPL-3.0-or-later
!
! xtb is free software: you can redistribute it and/or modify it under
! the terms of the GNU Lesser General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! xtb is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public License
! along with xtb.  If not, see <https://www.gnu.org/licenses/>.

module test_atomlist
   use testdrive, only : new_unittest, unittest_type, error_type, check, test_failed
   use xtb_mctc_accuracy, only : wp
   use xtb_mctc_io, only : stderr
   use xtb_type_atomlist
   implicit none
   private

   public :: collect_atomlist

   integer, parameter :: atoms(9) = [3,1,1,5,8,1,1,2,5]
   logical, parameter :: lpar(9) = [.true., .false., .true., .true., .true., &
      &                             .false., .false., .true., .false.]
   integer, parameter :: ipar(5) = [1, 3, 4, 5, 8]
   character(len=*), parameter :: cpar = '1,3-5,8'

contains

!> Collect all exported unit tests
subroutine collect_atomlist(testsuite)
   !> Collection of tests
   type(unittest_type), allocatable, intent(out) :: testsuite(:)

   testsuite = [ &
      new_unittest("defaults", test_atomlist_defaults), &
      new_unittest("constr1", test_atomlist_constr1), &
      new_unittest("constr2", test_atomlist_constr2), &
      new_unittest("constr3", test_atomlist_constr3), &
      new_unittest("constr4", test_atomlist_constr4), &
      new_unittest("manip1", test_atomlist_manip1), &
      new_unittest("manip2", test_atomlist_manip2) &
      ]

end subroutine collect_atomlist


subroutine test_atomlist_defaults(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   call check(error, atl%get_truth() .eqv. .true.)
   call atl%switch_truth
   call check(error, atl%get_truth() .eqv. .false.)
   call check(error, size(atl), 0)

end subroutine test_atomlist_defaults

subroutine test_atomlist_constr1(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   atl = TAtomList(list=lpar, truth=.true.)
   call check(error, size(atl), 9)
   call check(error, len(atl), 5)

end subroutine test_atomlist_constr1

subroutine test_atomlist_constr2(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   atl = TAtomList(list=lpar, truth=.false.)
   call check(error, size(atl), 9)
   call check(error, len(atl), 4)

end subroutine test_atomlist_constr2

subroutine test_atomlist_constr3(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   atl = TAtomList(list=ipar, truth=.true.)
   call check(error, size(atl), 8)
   call check(error, len(atl), 5)
   call atl%to_list(list)
   call check(error, all(list == ipar))

end subroutine test_atomlist_constr3

subroutine test_atomlist_constr4(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   atl = TAtomList(list=cpar, truth=.false.)
   call check(error, size(atl), 8)
   call check(error, len(atl), 5)
   call atl%to_string(string)
   call check(error, string, cpar)
   call atl%new

end subroutine test_atomlist_constr4

subroutine test_atomlist_manip1(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   call atl%new(lpar)
   call atl%resize(9)
   call atl%switch_truth
   call atl%to_string(string)
   call check(error, string, '2,6-7,9')
   call atl%gather(atoms, list)
   call check(error, all(list == [1,1,1,5]))
   call check(error, size(list), len(atl))
   call atl%new

end subroutine test_atomlist_manip1

subroutine test_atomlist_manip2(error)
   type(error_type), allocatable, intent(out) :: error
   type(TAtomList) :: atl
   character(len=:), allocatable :: string
   integer, allocatable :: list(:)

   atl = TAtomList(list=lpar, truth=.false., delimiter=' ', skip=':')
   call atl%to_string(string)
   call check(error, string, '2 6:7 9')
   call atl%switch_truth
   call atl%to_list(list)
   call atl%switch_truth
   call atl%add(list)
   call check(error, len(atl), size(atl))
   call atl%to_string(string)
   call check(error, string, '1:9')

end subroutine test_atomlist_manip2

end module test_atomlist