-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrequencyDetectorTests.mm
123 lines (96 loc) · 3.94 KB
/
FrequencyDetectorTests.mm
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
// -*- Mode: ObjC -*-
//
// Copyright (C) 2011, Brad Howes. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
#import "FrequencyDetector.h"
@interface FrequencyDetectorTests : SenTestCase<BitDetectorObserver> {
NSString* lastBitValue;
}
@end
@implementation FrequencyDetectorTests
- (void)nextBitValue:(NSString*)value
{
lastBitValue = value;
}
- (void)test1
{
FrequencyDetector* fd = [FrequencyDetector createForSampleRate:44100 bitRate:150 lowFreq:4000 highFreq:8000];
fd.observer = self;
STAssertEquals(fd.nominalLowWaveLength, 11.025f, @"");
STAssertEquals(fd.nominalHighWaveLength, 5.5125f, @"");
STAssertEquals(fd.nominalHalfBitLength, 147.0f, @"");
lastBitValue = nil;
WaveCycleDetectorInfo* info = [[WaveCycleDetectorInfo alloc] init];
info.sampleCount = 11;
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"0"], @"");
STAssertEquals(fd.currentBitLength, 11.0f, @"");
info.sampleCount = 11;
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"0"], @"");
STAssertEquals(fd.currentBitLength, 22.0f, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
[fd waveCycleDetected:info];
STAssertTrue(lastBitValue == nil, @"");
STAssertEquals(fd.currentBitLength, 143.0f, @"");
[fd waveCycleDetected:info];
[[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
STAssertEquals(fd.currentBitLength, -140.0f, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"0"], @"");
STAssertTrue(lastBitValue != nil, @"");
[fd reset];
lastBitValue = nil;
info.sampleCount = 5;
while (fd.currentBitLength >= 0.0) {
[fd waveCycleDetected:info];
}
[[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
STAssertEquals(fd.currentBitLength, -144.0f, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"1"], @"");
STAssertTrue([lastBitValue isEqualToString:@"1"], @"");
lastBitValue = nil;
while (fd.currentBitLength <= 0.0) {
[fd waveCycleDetected:info];
}
while (fd.currentBitLength >= 0.0) {
[fd waveCycleDetected:info];
}
[[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
STAssertEquals(fd.currentBitLength, -143.0f, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"1"], @"");
STAssertTrue([lastBitValue isEqualToString:@"1"], @"");
lastBitValue = nil;
while (fd.currentBitLength <= 0.0) {
[fd waveCycleDetected:info];
}
while (fd.currentBitLength >= 0.0) {
[fd waveCycleDetected:info];
}
[[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
STAssertEquals(fd.currentBitLength, -147.0f, @"");
STAssertTrue([fd.currentBitState isEqualToString:@"1"], @"");
STAssertTrue([lastBitValue isEqualToString:@"1"], @"");
}
@end