-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple unit tests to check output length for both encode
and decode.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import unittest | ||
|
||
from G722 import G722 | ||
|
||
class TestDecoder(unittest.TestCase): | ||
def test_decode_len(self): | ||
bitrates = [48000, 56000, 64000] | ||
sample_rates = [8000, 16000] | ||
|
||
for bitrate in bitrates: | ||
for sample_rate in sample_rates: | ||
with self.subTest(bitrate=bitrate, sample_rate=sample_rate): | ||
g722 = G722(sample_rate, bitrate) | ||
encoded_data = b"0123" # Example encoded data | ||
decoded_data = g722.decode(encoded_data) | ||
got = len(decoded_data) | ||
want = 4 if sample_rate == 8000 else 8 | ||
self.assertEqual(want, got) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
|
||
from G722 import G722 | ||
|
||
class TestEncoder(unittest.TestCase): | ||
def test_encode_len(self): | ||
bitrates = [48000, 56000, 64000] | ||
sample_rates = [8000, 16000] | ||
|
||
for bitrate in bitrates: | ||
for sample_rate in sample_rates: | ||
with self.subTest(bitrate=bitrate, sample_rate=sample_rate): | ||
g722 = G722(sample_rate, bitrate) | ||
audio_data = b"\x00\x01\x02\x03" # Example raw audio data | ||
encoded_data = g722.encode(audio_data) | ||
got = len(encoded_data) | ||
want = 4 if sample_rate == 8000 else 2 | ||
self.assertEqual(want, got) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |