File: test_token.rb

package info (click to toggle)
whisper.cpp 1.8.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 32,228 kB
  • sloc: cpp: 188,765; ansic: 121,729; lisp: 10,221; sh: 4,272; objc: 2,159; ruby: 1,682; python: 1,177; javascript: 594; makefile: 144
file content (70 lines) | stat: -rw-r--r-- 2,043 bytes parent folder | download
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
require_relative "helper"

class TestToken < TestBase
  def setup
    @segment = whisper.each_segment.first
    @token = @segment.each_token.first
  end

  def test_n_tokens
    assert_equal 27, @segment.n_tokens
  end

  def test_allocate
    token = Whisper::Token.allocate
    assert_raise  do
      token.id
    end
  end

  def test_each_token
    i = 0
    @segment.each_token do |token|
      i += 1
      assert_instance_of Whisper::Token, token
    end
    assert_equal 27, i
  end

  def test_each_token_without_block
    assert_instance_of Enumerator, @segment.each_token
  end

  def test_token
    assert_instance_of Whisper::Token, @token

    assert_instance_of Integer, @token.id
    assert_instance_of Float, @token.probability
    assert_instance_of Float, @token.log_probability

    assert_instance_of Integer, @token.tid
    assert_instance_of Float, @token.pt
    assert_instance_of Float, @token.ptsum

    assert_instance_of Integer, @token.start_time
    assert_instance_of Integer, @token.end_time

    assert_instance_of Integer, @token.t_dtw

    assert_instance_of Float, @token.voice_length

    assert_instance_of String, @token.text
  end

  def test_text
    assert_equal ["[_BEG_]", " And", " so", " my", " fellow", " Americans", ",", " ask", " not", " what", " your", " country", " can", " do", " for", " you", ",", " ask", " what", " you", " can", " do", " for", " your", " country", ".", "[_TT_550]"],
                 @segment.each_token.collect(&:text)
  end

  def test_deconstruct_keys_with_nil
    keys = %i[id tid probability log_probability pt ptsum t_dtw voice_length start_time end_time text]
    expected = keys.collect {|key| [key, @token.send(key)] }.to_h
    assert_equal(expected, @token.deconstruct_keys(nil))
  end

  def test_deconstruct_keys_with_keys
    keys = %i[id tid probability log_probability pt ptsum t_dtw voice_length start_time end_time text]
    expected = keys.collect {|key| [key, @token.send(key)] }.to_h
    assert_equal expected, @token.deconstruct_keys(keys)
  end
end