File: AudioSegmentSampleViewTest.cpp

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (58 lines) | stat: -rw-r--r-- 1,886 bytes parent folder | download | duplicates (2)
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
/*  SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************

  Audacity: A Digital Audio Editor

  AudioSegmentSampleViewTest.cpp

  Matthieu Hodgkinson

**********************************************************************/
#include "AudioSegmentSampleView.h"

#include <catch2/catch.hpp>

TEST_CASE("AudioSegmentSampleView", "Copy returns expected values when")
{
   SECTION("AudioSegmentSampleView is silent")
   {
      AudioSegmentSampleView sut { 3 };
      std::vector<float> buffer(4);
      std::fill(buffer.begin(), buffer.end(), 1.f);
      SECTION("and asked MORE values than it holds.")
      {
         sut.Copy(buffer.data(), 4u);
         REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 0.f, 0.f });
      }
      SECTION("and asked FEWER values than it holds.")
      {
         sut.Copy(buffer.data(), 2u);
         REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 1.f, 1.f });
      }
   }

   SECTION("AudioSegmentSampleView is NOT silent")
   {
      const auto segment1 = std::make_shared<std::vector<float>>(
         std::vector<float> { 1.f, 2.f, 3.f });
      const auto segment2 = std::make_shared<std::vector<float>>(
         std::vector<float> { 4.f, 5.f, 6.f });
      constexpr auto start = 2u;
      constexpr auto length = 3u;
      AudioSegmentSampleView sut { { segment1, segment2 }, start, length };

      SECTION("and asked MORE values than it holds.")
      {
         std::vector<float> out(4u);
         std::fill(out.begin(), out.end(), 123.f);
         sut.Copy(out.data(), out.size());
         REQUIRE(out == std::vector<float> { 3.f, 4.f, 5.f, 0.f });
      }
      SECTION("and asked FEWER values than it holds.")
      {
         std::vector<float> out(2u);
         sut.Copy(out.data(), out.size());
         REQUIRE(out == std::vector<float> { 3.f, 4.f });
      }
   }
}