dtas.git  about / heads / tags
duct tape audio suite for *nix
blob fe2e0346d42342787c3b4aed95f3b927a43ea900 1551 bytes (raw)
$ git show mpd:test/test_format.rb	# shows this blob on the CLI

 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
 
# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require './test/helper'
require 'tempfile'
require 'dtas/format'

class TestFormat < Testcase
  def test_initialize
    fmt = DTAS::Format.new
    assert_equal %w(-ts32 -c2 -r44100), fmt.to_sox_arg
    hash = fmt.to_hsh
    assert_equal({}, hash)
  end

  def test_equal
    fmt = DTAS::Format.new
    assert_equal fmt, fmt.dup
  end

  def test_nonstandard
    fmt = DTAS::Format.new
    fmt.type = "s16"
    fmt.rate = 48000
    fmt.channels = 4
    hash = fmt.to_hsh
    assert_kind_of Hash, hash
    assert_equal %w(channels rate type), hash.keys.sort
    assert_equal "s16", hash["type"]
    assert_equal 48000, hash["rate"]
    assert_equal 4, hash["channels"]

    # back to stereo
    fmt.channels = 2
    hash = fmt.to_hsh
    assert_equal %w(rate type), hash.keys.sort
    assert_equal "s16", hash["type"]
    assert_equal 48000, hash["rate"]
    assert_nil hash["channels"]
  end

  def test_bytes_per_sample
    fmt = DTAS::Format.new
    assert_equal 4, fmt.bytes_per_sample
    fmt.type = "f64"
    assert_equal 8, fmt.bytes_per_sample
    fmt.type = "f32"
    assert_equal 4, fmt.bytes_per_sample
    fmt.type = "s16"
    assert_equal 2, fmt.bytes_per_sample
  end

  def test_valid_type
    fmt = DTAS::Format.new
    %w(s16 s24 s32 f32 f64).each do |t|
      assert fmt.valid_type?(t)
    end
    %w(flac wav wtf).each do |t|
      refute fmt.valid_type?(t)
    end
  end
end

git clone git://80x24.org/dtas.git
git clone https://80x24.org/dtas.git