connection_m.fun 2.61 KB
Newer Older
1
2
3
4
5
6
!> Unit test suite for connections (synapses)
!! in neural networks.
!!
!! @author Martin Beseda
!! @author Martin Mrovec
!! @date 2017
Martin Mrovec's avatar
Martin Mrovec committed
7
8
test_suite connection_m

Martin Mrovec's avatar
Martin Mrovec committed
9
! Global variables declaration
10

11
12
class(neuron_t), pointer :: n1_p
class(neuron_t), pointer :: n2_p
13

14
class(neuron_t), pointer :: dummy_p
15

16
type(connection_t), pointer :: con
17

Martin Mrovec's avatar
Martin Mrovec committed
18
19
20
21
22
23
24
!------------------------!---------------------------------------------------------------
! Setup before each test !
!------------------------!
setup
  write(*,*) '+------------------------+'
  write(*,*) '| SETUP BEFORE UNIT TEST |'
  write(*,*) '+------------------------+'
25
  write(*,*) 'Creating instances of the class mock_neuron_t...'
26
27
  n1_p => mock_neuron_t()
  n2_p => mock_neuron_t()
Martin Mrovec's avatar
Martin Mrovec committed
28
  write(*,*) 'Creating an instance of the class interval_connection_t...'
29
  con => connection_t(n1_p, n2_p, 5.25)
Martin Mrovec's avatar
Martin Mrovec committed
30
31
32
  nullify(dummy_p)
  write(*,*) 'Ready for test.'
end setup
33

Martin Mrovec's avatar
Martin Mrovec committed
34
35
36
37
38
39
40
41
42
43
44
45
!-------------------------!--------------------------------------------------------------
! Cleanup after each test !
!-------------------------!
teardown
  write(*,*) '+-------------------------+'
  write(*,*) '| CLEANUP AFTER UNIT TEST |'
  write(*,*) '+-------------------------+'
  write(*,*) 'Deallocating everything.'
  deallocate(con)
  nullify(dummy_p)
  write(*,*) 'Cleaned succesfully.'
end teardown
46

Martin Mrovec's avatar
Martin Mrovec committed
47
48
49
!-------!--------------------------------------------------------------------------------
! Tests !
!-------!
50
51


Martin Mrovec's avatar
Martin Mrovec committed
52
53
54
55
56
57
58
59
60
61
62
63
!-----------------------------!
! Test of getters and setters !
!-----------------------------!
test getters_setters
  write(*,*) '+++ Test of getters and setters ...'
  ! Test of get_weight
  assert_real_equal(con%get_weight(), 5.25e+0)
  ! Test of adjust_weight
  call con%adjust_weight(1.0)
  assert_real_equal(con%get_weight(), 6.25e+0)
  write(*,*) '... finished +++'
end test
64

Martin Mrovec's avatar
Martin Mrovec committed
65
66
67
68
69
70
71
!----------------------------------!
! Test of input and output neurons !
!----------------------------------!
test input_and_output_neurons
  write(*,*) '+++ Test of input and output neurons ...'
  ! Input neuron
  dummy_p => con%get_input_neuron()
72
  assert_real_equal(dummy_p%get_state(),15.0e+0)
Martin Mrovec's avatar
Martin Mrovec committed
73
74
  ! Output neuron
  dummy_p => con%get_output_neuron()
75
  assert_real_equal(dummy_p%get_state(),15.0e+0)
Martin Mrovec's avatar
Martin Mrovec committed
76
77
  write(*,*) '... finished +++'
end test
78

Martin Mrovec's avatar
Martin Mrovec committed
79
80
81
82
83
84
85
!--------------------------!
! Test of passing a signal !
!--------------------------!
test pass_signal
   write(*,*) '+++ Test of passing a signal ...'
   dummy_p => con%get_output_neuron()
   call con%pass_signal()
86
   assert_real_equal(dummy_p%get_potential(), 78.75e+0)
Martin Mrovec's avatar
Martin Mrovec committed
87
88
   write(*,*) '... finished +++'
end test
89

Martin Mrovec's avatar
Martin Mrovec committed
90
91

end test_suite