Skip to content

Commit 9f7d7a6

Browse files
committed
Add more tests for set()
1 parent 036914b commit 9f7d7a6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/audioBuffer.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,53 @@ TEST_CASE("AudioBuffer")
166166
std::unique_ptr<float[]> raw = std::make_unique<float[]>(bufferSize);
167167
AudioBuffer buf(raw.get(), bufferSize, numChannels);
168168
}
169+
170+
SECTION("test set")
171+
{
172+
constexpr int numChannels = 2;
173+
174+
AudioBuffer src(BUFFER_SIZE, numChannels); // Filled with 0.0f's by default
175+
AudioBuffer dest(BUFFER_SIZE, numChannels);
176+
fillBufferWithData(src);
177+
178+
SECTION("total")
179+
{
180+
dest.set(src, 0, 0);
181+
dest.set(src, 1, 1);
182+
183+
for (int i = 0; i < dest.countFrames(); i++)
184+
for (int k = 0; k < dest.countChannels(); k++)
185+
REQUIRE(dest[i][k] == static_cast<float>(i));
186+
}
187+
188+
SECTION("partial")
189+
{
190+
constexpr int framesToCopy = BUFFER_SIZE / 2;
191+
192+
dest.set(src, framesToCopy, 0, 0, 0, 0);
193+
dest.set(src, framesToCopy, 0, 0, 1, 1);
194+
195+
for (int i = 0; i < dest.countFrames(); i++)
196+
for (int k = 0; k < dest.countChannels(); k++)
197+
REQUIRE(dest[i][k] == (i < framesToCopy ? static_cast<float>(i) : 0.0f));
198+
}
199+
200+
SECTION("partial with offset")
201+
{
202+
constexpr int framesToCopy = BUFFER_SIZE / 2;
203+
constexpr int offset = 1;
204+
205+
dest.set(src, framesToCopy, offset, offset, 0, 0);
206+
dest.set(src, framesToCopy, offset, offset, 1, 1);
207+
208+
for (int i = 0; i < dest.countFrames(); i++)
209+
for (int k = 0; k < dest.countChannels(); k++)
210+
{
211+
if (i == 0)
212+
REQUIRE(dest[i][k] == 0.0f);
213+
else
214+
REQUIRE(dest[i][k] == (i < framesToCopy + offset ? static_cast<float>(i) : 0.0f));
215+
}
216+
}
217+
}
169218
}

0 commit comments

Comments
 (0)