Add tests for Parakeet::Context#full
This commit is contained in:
parent
fd550f77ce
commit
a5a6884d65
|
|
@ -14,6 +14,71 @@ class TestParakeetContext < TestBase
|
|||
assert_instance_of Parakeet::Context, @parakeet
|
||||
end
|
||||
|
||||
sub_test_case "full" do
|
||||
def setup
|
||||
super
|
||||
@samples = File.read(AUDIO, nil, 78).unpack("s<*").collect {|i| i.to_f / 2**15}
|
||||
end
|
||||
|
||||
def test_full
|
||||
@parakeet.full @params, @samples, @samples.length
|
||||
|
||||
segments = @parakeet.each_segment.to_a
|
||||
assert_equal 2, segments.length
|
||||
assert_match /ask not what your country can do for you, ask what you can do for your/, segments.first.text
|
||||
end
|
||||
|
||||
def test_full_without_length
|
||||
@parakeet.full(@params, @samples)
|
||||
|
||||
segments = @parakeet.each_segment.to_a
|
||||
assert_equal 2, segments.length
|
||||
assert_match /ask not what your country can do for you, ask what you can do for your/, @parakeet.each_segment.first.text
|
||||
end
|
||||
|
||||
def test_full_enumerator
|
||||
samples = @samples.each
|
||||
@parakeet.full @params, samples, @samples.length
|
||||
|
||||
segments = @parakeet.each_segment.to_a
|
||||
assert_equal 2, segments.length
|
||||
assert_match /ask not what your country can do for you, ask what you can do for your/, @parakeet.each_segment.first.text
|
||||
end
|
||||
|
||||
def test_full_enumerator_without_length
|
||||
samples = @samples.each
|
||||
assert_raise ArgumentError do
|
||||
@parakeet.full @params, samples
|
||||
end
|
||||
end
|
||||
|
||||
def test_full_enumerator_with_too_large_length
|
||||
samples = @samples.each.take(10).to_enum
|
||||
assert_raise StopIteration do
|
||||
@parakeet.full @params, samples, 11
|
||||
end
|
||||
end
|
||||
|
||||
def test_full_with_memory_view
|
||||
samples = JFKReader.new(AUDIO)
|
||||
@parakeet.full @params, samples
|
||||
|
||||
segments = @parakeet.each_segment.to_a
|
||||
assert_equal 2, segments.length
|
||||
assert_match /ask not what your country can do for you, ask what you can do for your/, @parakeet.each_segment.first.text
|
||||
end
|
||||
|
||||
def test_full_with_memroy_view_gc
|
||||
samples = JFKReader.new(AUDIO)
|
||||
@parakeet.full(@params, samples)
|
||||
GC.start
|
||||
require "fiddle"
|
||||
Fiddle::MemoryView.export samples do |view|
|
||||
assert_equal 176000, view.to_s.unpack("#{view.format}*").length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_transcribe
|
||||
assert_nothing_raised do
|
||||
@parakeet.transcribe AUDIO, @params
|
||||
|
|
|
|||
Loading…
Reference in New Issue