mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Ruff pandas vet (#10281)
* Python linting: Add ruff rules for Pandas-vet and Pytest-style
* updating DIRECTORY.md
---------
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -67,8 +67,8 @@ class TestLeastCommonMultiple(unittest.TestCase):
|
||||
slow_result = least_common_multiple_slow(first_num, second_num)
|
||||
fast_result = least_common_multiple_fast(first_num, second_num)
|
||||
with self.subTest(i=i):
|
||||
self.assertEqual(slow_result, self.expected_results[i])
|
||||
self.assertEqual(fast_result, self.expected_results[i])
|
||||
assert slow_result == self.expected_results[i]
|
||||
assert fast_result == self.expected_results[i]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -28,7 +28,9 @@ def modular_division(a: int, b: int, n: int) -> int:
|
||||
4
|
||||
|
||||
"""
|
||||
assert n > 1 and a > 0 and greatest_common_divisor(a, n) == 1
|
||||
assert n > 1
|
||||
assert a > 0
|
||||
assert greatest_common_divisor(a, n) == 1
|
||||
(d, t, s) = extended_gcd(n, a) # Implemented below
|
||||
x = (b * s) % n
|
||||
return x
|
||||
@@ -86,7 +88,8 @@ def extended_gcd(a: int, b: int) -> tuple[int, int, int]:
|
||||
** extended_gcd function is used when d = gcd(a,b) is required in output
|
||||
|
||||
"""
|
||||
assert a >= 0 and b >= 0
|
||||
assert a >= 0
|
||||
assert b >= 0
|
||||
|
||||
if b == 0:
|
||||
d, x, y = a, 1, 0
|
||||
@@ -95,7 +98,8 @@ def extended_gcd(a: int, b: int) -> tuple[int, int, int]:
|
||||
x = q
|
||||
y = p - q * (a // b)
|
||||
|
||||
assert a % d == 0 and b % d == 0
|
||||
assert a % d == 0
|
||||
assert b % d == 0
|
||||
assert d == a * x + b * y
|
||||
|
||||
return (d, x, y)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def is_prime(number: int) -> bool:
|
||||
"""Checks to see if a number is a prime in O(sqrt(n)).
|
||||
@@ -50,33 +52,31 @@ def is_prime(number: int) -> bool:
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
def test_primes(self):
|
||||
self.assertTrue(is_prime(2))
|
||||
self.assertTrue(is_prime(3))
|
||||
self.assertTrue(is_prime(5))
|
||||
self.assertTrue(is_prime(7))
|
||||
self.assertTrue(is_prime(11))
|
||||
self.assertTrue(is_prime(13))
|
||||
self.assertTrue(is_prime(17))
|
||||
self.assertTrue(is_prime(19))
|
||||
self.assertTrue(is_prime(23))
|
||||
self.assertTrue(is_prime(29))
|
||||
assert is_prime(2)
|
||||
assert is_prime(3)
|
||||
assert is_prime(5)
|
||||
assert is_prime(7)
|
||||
assert is_prime(11)
|
||||
assert is_prime(13)
|
||||
assert is_prime(17)
|
||||
assert is_prime(19)
|
||||
assert is_prime(23)
|
||||
assert is_prime(29)
|
||||
|
||||
def test_not_primes(self):
|
||||
with self.assertRaises(AssertionError):
|
||||
with pytest.raises(AssertionError):
|
||||
is_prime(-19)
|
||||
self.assertFalse(
|
||||
is_prime(0),
|
||||
"Zero doesn't have any positive factors, primes must have exactly two.",
|
||||
)
|
||||
self.assertFalse(
|
||||
is_prime(1),
|
||||
"One only has 1 positive factor, primes must have exactly two.",
|
||||
)
|
||||
self.assertFalse(is_prime(2 * 2))
|
||||
self.assertFalse(is_prime(2 * 3))
|
||||
self.assertFalse(is_prime(3 * 3))
|
||||
self.assertFalse(is_prime(3 * 5))
|
||||
self.assertFalse(is_prime(3 * 5 * 7))
|
||||
assert not is_prime(
|
||||
0
|
||||
), "Zero doesn't have any positive factors, primes must have exactly two."
|
||||
assert not is_prime(
|
||||
1
|
||||
), "One only has 1 positive factor, primes must have exactly two."
|
||||
assert not is_prime(2 * 2)
|
||||
assert not is_prime(2 * 3)
|
||||
assert not is_prime(3 * 3)
|
||||
assert not is_prime(3 * 5)
|
||||
assert not is_prime(3 * 5 * 7)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user