summaryrefslogtreecommitdiff
path: root/tests/unit/jtty/test_jtty_message_matching.f90
blob: 1308009a74e3fecc655193cc9e5bd2c0c69383bd (plain)
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
program test_jtty_message_matching
  use jtty_mdec, only: decode,message_assembly,classify_active_candidate
  implicit none

  real, parameter :: frame_period=2.0
  type(message_assembly) :: existing
  type(decode) :: candidate
  logical :: match,is_window_dupe
  integer :: failures,nframes_gap

  failures=0
  existing%f1=1500.0
  existing%tsync=10.0
  existing%decoded='OPEN MESSAGE'

  candidate%f1=1501.0
  candidate%tsync=existing%tsync+frame_period
  candidate%decoded='CONTINUATION'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. .not.is_window_dupe .and. nframes_gap.eq.1, &
       'an active message accepts the next frame',failures)

  candidate%f1=1505.0
  candidate%tsync=existing%tsync+frame_period/4.0
  candidate%decoded='SHIFTED REDISCOVERY'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. is_window_dupe, &
       'an active message rejects a quarter-frame rediscovery',failures)

  candidate%f1=1505.0
  candidate%tsync=existing%tsync+frame_period
  candidate%decoded='WIDE CONTINUATION'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. .not.is_window_dupe, &
       'an active message accepts a 5 Hz next frame',failures)

  candidate%f1=1501.0
  candidate%tsync=existing%tsync+2*frame_period
  candidate%decoded='ONE MISSED FRAME'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. .not.is_window_dupe .and. nframes_gap.eq.2, &
       'an active message bridges one missed frame',failures)

  candidate%f1=1501.0
  candidate%tsync=existing%tsync+3*frame_period
  candidate%decoded='TWO MISSED FRAMES'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. .not.is_window_dupe .and. nframes_gap.eq.3, &
       'an active message bridges two missed frames',failures)

  candidate%f1=1501.0
  candidate%tsync=existing%tsync+4*frame_period
  candidate%decoded='THREE MISSED FRAMES'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(.not.match, &
       'an active message does not bridge beyond the continuation limit', &
       failures)

  candidate%f1=1505.0
  candidate%tsync=existing%tsync+3*frame_period/4.0
  candidate%decoded='LAST RETRO STEP'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(match .and. is_window_dupe, &
       'the final actual retro step is classified as rediscovery',failures)

  candidate%tsync=existing%tsync+5*frame_period/4.0
  candidate%decoded='OUTSIDE RETRO HORIZON'
  call classify_active_candidate(existing,candidate,frame_period, &
       match,is_window_dupe,nframes_gap)
  call expect(.not.match, &
       'a later quarter-phase frame is not mistaken for rediscovery',failures)

  if(failures.ne.0) then
     write(*,'(a,i0)') 'test_jtty_message_matching: failures=',failures
     stop 1
  endif
  write(*,'(a)') 'test_jtty_message_matching: all checks passed'

contains

  subroutine expect(condition,description,count)
    logical, intent(in) :: condition
    character(len=*), intent(in) :: description
    integer, intent(inout) :: count

    if(.not.condition) then
       count=count+1
       write(*,'(a)') 'FAIL: '//description
    endif
  end subroutine expect

end program test_jtty_message_matching