Audacity 3.2.0
Functions
AudioSegmentSampleViewTest.cpp File Reference
#include "AudioSegmentSampleView.h"
#include <catch2/catch.hpp>
Include dependency graph for AudioSegmentSampleViewTest.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("AudioSegmentSampleView", "Copy returns expected values when")
 

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "AudioSegmentSampleView"  ,
"Copy returns expected values when"   
)

Audacity: A Digital Audio Editor

AudioSegmentSampleViewTest.cpp

Matthieu Hodgkinson

Definition at line 15 of file AudioSegmentSampleViewTest.cpp.

16{
17 SECTION("AudioSegmentSampleView is silent")
18 {
19 AudioSegmentSampleView sut { 3 };
20 std::vector<float> buffer(4);
21 std::fill(buffer.begin(), buffer.end(), 1.f);
22 SECTION("and asked MORE values than it holds.")
23 {
24 sut.Copy(buffer.data(), 4u);
25 REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 0.f, 0.f });
26 }
27 SECTION("and asked FEWER values than it holds.")
28 {
29 sut.Copy(buffer.data(), 2u);
30 REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 1.f, 1.f });
31 }
32 }
33
34 SECTION("AudioSegmentSampleView is NOT silent")
35 {
36 const auto segment1 = std::make_shared<std::vector<float>>(
37 std::vector<float> { 1.f, 2.f, 3.f });
38 const auto segment2 = std::make_shared<std::vector<float>>(
39 std::vector<float> { 4.f, 5.f, 6.f });
40 constexpr auto start = 2u;
41 constexpr auto length = 3u;
42 AudioSegmentSampleView sut { { segment1, segment2 }, start, length };
43
44 SECTION("and asked MORE values than it holds.")
45 {
46 std::vector<float> out(4u);
47 std::fill(out.begin(), out.end(), 123.f);
48 sut.Copy(out.data(), out.size());
49 REQUIRE(out == std::vector<float> { 3.f, 4.f, 5.f, 0.f });
50 }
51 SECTION("and asked FEWER values than it holds.")
52 {
53 std::vector<float> out(2u);
54 sut.Copy(out.data(), out.size());
55 REQUIRE(out == std::vector<float> { 3.f, 4.f });
56 }
57 }
58}