-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
python-version: [3.11] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt # If you have any requirements | ||
- name: Run tests | ||
run: python test/test.py |
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,39 @@ | ||
import unittest | ||
from bntrans import Translator | ||
|
||
|
||
def match_percentage(a, b): | ||
return len(set(a) & set(b)) / len(a) | ||
|
||
|
||
class TestTranslator(unittest.TestCase): | ||
def test_translate(self): | ||
translator = Translator(src="en", dest="bn") | ||
|
||
tests = [ | ||
("Hello world!", "হ্যালো বিশ্ব!"), | ||
("Who are you?", "তুমি কে?"), | ||
("I am fine", "আমি ঠিক আছি"), | ||
] | ||
|
||
for test in tests: | ||
# match percentage should be at least 70% | ||
result = match_percentage(translator.translate(test[0]), test[1]) | ||
self.assertGreaterEqual(result, 0.7) | ||
|
||
translator = Translator(src="bn", dest="en") | ||
|
||
tests = [ | ||
("হ্যালো বিশ্ব!", "Hello world!"), | ||
("তুমি কে?", "Who are you?"), | ||
("আমি ঠিক আছি", "I am fine"), | ||
] | ||
|
||
for test in tests: | ||
# match percentage should be at least 70% | ||
result = match_percentage(translator.translate(test[0]), test[1]) | ||
self.assertGreaterEqual(result, 0.7) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |