-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleCircularBufferTests.mm
120 lines (94 loc) · 3.4 KB
/
SampleCircularBufferTests.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
// -*- Mode: ObjC -*-
// -*- Mode: ObjC -*-
//
// Copyright (C) 2011, Brad Howes. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
#import "SampleCircularBuffer.h"
@interface SampleCircularBufferTests : SenTestCase {
}
@end
@implementation SampleCircularBufferTests
- (void)testOne
{
SampleCircularBuffer* obj = [SampleCircularBuffer bufferWithCapacity:3 initialValue:1.0f];
STAssertEquals(1.0f, [obj valueAt:0], @"");
STAssertEquals(1.0f, [obj valueAt:1], @"");
STAssertEquals(1.0f, [obj valueAt:2], @"");
[obj addSample:0.0f];
STAssertEquals(1.0f, [obj valueAt:0], @"");
STAssertEquals(1.0f, [obj valueAt:1], @"");
STAssertEquals(0.0f, [obj valueAt:2], @"");
[obj addSample:0.5f];
STAssertEquals(1.0f, [obj valueAt:0], @"");
STAssertEquals(0.0f, [obj valueAt:1], @"");
STAssertEquals(0.5f, [obj valueAt:2], @"");
[obj addSample:0.2f];
STAssertEquals(0.0f, [obj valueAt:0], @"");
STAssertEquals(0.5f, [obj valueAt:1], @"");
STAssertEquals(0.2f, [obj valueAt:2], @"");
[obj addSample:0.4f];
STAssertEquals(0.5f, [obj valueAt:0], @"");
STAssertEquals(0.2f, [obj valueAt:1], @"");
STAssertEquals(0.4f, [obj valueAt:2], @"");
STAssertEquals(0.5f, [obj valueAt:3], @"");
STAssertEquals(0.5f, [obj valueAt:27], @"");
[obj clear];
STAssertEquals(1.0f, [obj valueAt:0], @"");
STAssertEquals(1.0f, [obj valueAt:1], @"");
STAssertEquals(1.0f, [obj valueAt:2], @"");
}
- (void)testTwo
{
SampleCircularBuffer* obj = [SampleCircularBuffer bufferWithCapacity:3 initialValue:1.0f];
[obj addSample:0.1f];
[obj addSample:0.2f];
[obj addSample:0.3f];
NSUInteger count;
Float32* p = [obj valuesStartingAt:0 count:&count];
STAssertEquals(count, 3u, @"");
STAssertEquals(0.1f, *p++, @"");
STAssertEquals(0.2f, *p++, @"");
STAssertEquals(0.3f, *p++, @"");
p = [obj valuesStartingAt:3 count:&count];
STAssertEquals(count, 0u, @"");
STAssertEquals(p, (Float32*)0, @"");
[obj addSample:0.4f];
p = [obj valuesStartingAt:0 count:&count];
STAssertEquals(count, 2u, @"");
STAssertEquals(0.2f, *p++, @"");
STAssertEquals(0.3f, *p++, @"");
p = [obj valuesStartingAt:2 count:&count];
STAssertEquals(count, 1u, @"");
STAssertEquals(0.4f, *p++, @"");
p = [obj valuesStartingAt:3 count:&count];
STAssertEquals(count, 0u, @"");
STAssertEquals(p, (Float32*)0, @"");
[obj addSample:0.5f];
p = [obj valuesStartingAt:0 count:&count];
STAssertEquals(count, 1u, @"");
STAssertEquals(0.3f, *p++, @"");
p = [obj valuesStartingAt:1 count:&count];
STAssertEquals(count, 2u, @"");
STAssertEquals(0.4f, *p++, @"");
STAssertEquals(0.5f, *p++, @"");
p = [obj valuesStartingAt:3 count:&count];
STAssertEquals(count, 0u, @"");
STAssertEquals(p, (Float32*)0, @"");
}
- (void)testThree
{
SampleCircularBuffer* obj = [SampleCircularBuffer bufferWithCapacity:3 initialValue:1.0f];
NSArray* spans = [obj valueSpans];
STAssertEquals(1u, [spans count], @"");
[obj addSample:0.1f];
spans = [obj valueSpans];
STAssertEquals(2u, [spans count], @"");
[obj addSample:0.2f];
spans = [obj valueSpans];
STAssertEquals(2u, [spans count], @"");
[obj addSample:0.3f];
spans = [obj valueSpans];
STAssertEquals(1u, [spans count], @"");
}
@end