Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
shhossain committed Aug 27, 2023
1 parent af7fca7 commit 92bbc8a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
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
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bntrans import Translator


translator = Translator(src="en", dest="bn", use_cloud=True, huggingface_token="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")
translator = Translator(src="bn", dest="en", use_cloud=True, huggingface_token="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")

while True:
text = input("Enter text: ")
Expand Down
39 changes: 39 additions & 0 deletions test/test.py
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()

0 comments on commit 92bbc8a

Please sign in to comment.