Skip to content

Commit

Permalink
Тесты теперь работают... УРАААААА
Browse files Browse the repository at this point in the history
  • Loading branch information
koshkar committed Oct 25, 2023
1 parent 2f1cef4 commit 2c0de1b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
Binary file added tests/lab2/.DS_Store
Binary file not shown.
Empty file added tests/lab2/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions tests/lab2/test_caesar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
import os
import sys
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), ".."))
sys.path.append(parent_dir)

from src.lab2.caesar import encrypt_caesar, decrypt_caesar

class TestCaesarCipher(unittest.TestCase):
def test_encrypt_caesar(self):
self.assertEqual(encrypt_caesar("ILOVEBEER"), 'LORYHEHHU')
self.assertEqual(encrypt_caesar("bruuuuuuh"), 'euxxxxxxk')
self.assertEqual(encrypt_caesar("9mm"), '9pp')
self.assertEqual(encrypt_caesar(""), '')

def test_decrypt_caesar(self):
self.assertEqual(decrypt_caesar("LORYHEHHU"), 'ILOVEBEER')
self.assertEqual(decrypt_caesar("euxxxxxxk"), 'bruuuuuuh')
self.assertEqual(decrypt_caesar("9pp"), '9mm')
self.assertEqual(decrypt_caesar(""), '')

if __name__ == '__main__':
unittest.main()
38 changes: 38 additions & 0 deletions tests/lab2/test_rsa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
import os
import sys
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), ".."))
sys.path.append(parent_dir)
from src.lab2.rsa import is_prime, gcd, multiplicative_inverse, generate_keypair

class TestRSAFunctions(unittest.TestCase):

def test_is_prime(self):
self.assertTrue(is_prime(2))
self.assertTrue(is_prime(11))
self.assertFalse(is_prime(8))

def test_gcd(self):
self.assertEqual(gcd(12, 15), 3)
self.assertEqual(gcd(3, 7), 1)

def test_multiplicative_inverse(self):
self.assertEqual(multiplicative_inverse(7, 40), 23)

def test_generate_keypair(self):
p, q = 11, 19
public_key, private_key = generate_keypair(p, q)

# Проверка на то, что оба ключа имеют два элемента
self.assertEqual(len(public_key), 2)
self.assertEqual(len(private_key), 2)

# Проверка, что оба ключа содержат только целые числа
self.assertIsInstance(public_key[0], int)
self.assertIsInstance(public_key[1], int)
self.assertIsInstance(private_key[0], int)
self.assertIsInstance(private_key[1], int)


if __name__ == '__main__':
unittest.main()
21 changes: 21 additions & 0 deletions tests/lab2/test_vigenre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
import os
import sys
parent_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")), ".."))
sys.path.append(parent_dir)

from src.lab2.vigenre import encrypt_vigenere, decrypt_vigenere

class TestVigenereEncryptionDecryption(unittest.TestCase):
def test_encrypt_vigenere(self):
self.assertEqual(encrypt_vigenere("PYTHON", "A"), 'PYTHON')
self.assertEqual(encrypt_vigenere("python", "a"), 'python')
self.assertEqual(encrypt_vigenere("ATTACKATDAWN", "LEMON"), 'LXFOPVEFRNHR')

def test_decrypt_vigenere(self):
self.assertEqual(decrypt_vigenere("PYTHON", "A"), 'PYTHON')
self.assertEqual(decrypt_vigenere("python", "a"), 'python')
self.assertEqual(decrypt_vigenere("LXFOPVEFRNHR", "LEMON"), 'ATTACKATDAWN')

if __name__ == '__main__':
unittest.main()

0 comments on commit 2c0de1b

Please sign in to comment.