def above_two(n): foo = None if n < -1: foo = False if n == 0: foo = False if n <= 2: foo = False else: foo = True return foo
def above_two(n):return n > 2- def above_two(n):
- foo = None
- if n < -1:
- foo = False
- if n == 0:
- foo = False
- if n <= 2:
- foo = False
- else:
- foo = True
- return foo
import codewars_test as test from solution import above_two # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(above_two(0), False) test.assert_equals(above_two(1), False) test.assert_equals(above_two(2), False) test.assert_equals(above_two(3), True) test.assert_equals(above_two(4), True) test.assert_equals(above_two(5), True)
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import above_two
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(above_two(0), False)
- test.assert_equals(above_two(1), False)
- test.assert_equals(above_two(2), False)
- test.assert_equals(above_two(3), True)
- test.assert_equals(above_two(4), True)
- test.assert_equals(above_two(5), True)
seraph776vs.user3525445last month
Prebrojavanje samoglasnika
def count(text: str) -> int: ctr = 0 for letter in text: if letter == 'A' or letter == 'a': ctr += 1 elif letter == 'E' or letter == 'e': ctr += 1 elif letter == 'I' or letter == 'i': ctr += 1 elif letter == 'O' or letter == 'o': ctr += 1 elif letter == 'U' or letter == 'u': ctr += 1 return ctr
- def count(text: str) -> int:
return sum(1 for char in text if char in "AEIOUaeiou")- ctr = 0
- for letter in text:
- if letter == 'A' or letter == 'a':
- ctr += 1
- elif letter == 'E' or letter == 'e':
- ctr += 1
- elif letter == 'I' or letter == 'i':
- ctr += 1
- elif letter == 'O' or letter == 'o':
- ctr += 1
- elif letter == 'U' or letter == 'u':
- ctr += 1
- return ctr
import codewars_test as test from solution import count # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(count('123'), 0) test.assert_equals(count('hi'), 1) test.assert_equals(count('seraph'), 2) test.assert_equals(count('codewarz'), 3) test.assert_equals(count('MissISsIpPi'), 4)
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import count
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(1 + 1, 2)- test.assert_equals(count('123'), 0)
- test.assert_equals(count('hi'), 1)
- test.assert_equals(count('seraph'), 2)
- test.assert_equals(count('codewarz'), 3)
- test.assert_equals(count('MissISsIpPi'), 4)
import os class BitBlender: """BitBlender class""" def __init__(self, target_file, num=7, deletion=False): self.target_file = target_file self.num = num # number of times to overwrite file self.deletion = deletion self.file_size = os.path.getsize(self.target_file) if os.path.exists(self.target_file): self.file_size = os.path.getsize(self.target_file) else: raise FileNotFoundError(f"The file '{self.target_file}' does not exist.") def execute(self): try: # Overwrite the file with random data with open(self.target_file, "wb") as f: # Repeat this process num times for i in range(self.num): f.write(os.urandom(self.file_size)) # If you choose to delete: if self.deletion: os.remove(self.target_file) except Exception as e: print(f"Error: {e}")
- import os
- class BitBlender:
- """BitBlender class"""
- def __init__(self, target_file, num=7, deletion=False):
- self.target_file = target_file
- self.num = num # number of times to overwrite file
- self.deletion = deletion
- self.file_size = os.path.getsize(self.target_file)
- if os.path.exists(self.target_file):
- self.file_size = os.path.getsize(self.target_file)
- else:
- raise FileNotFoundError(f"The file '{self.target_file}' does not exist.")
- def execute(self):
pass- try:
- # Overwrite the file with random data
- with open(self.target_file, "wb") as f:
- # Repeat this process num times
- for i in range(self.num):
- f.write(os.urandom(self.file_size))
- # If you choose to delete:
- if self.deletion:
- os.remove(self.target_file)
- except Exception as e:
- print(f"Error: {e}")
import codewars_test as test import os import filecmp # used for file comparison import shutil # used to copy files from solution import BitBlender, fake_data # Create fake sample files fake_data('sample_01.txt') fake_data('sample_02.txt') fake_data('sample_03.txt') # Create copies of sample file for comparison shutil.copy('sample_01.txt', 'sample_01_copy.txt') shutil.copy('sample_02.txt', 'sample_02_copy.txt') shutil.copy('sample_03.txt', 'sample_03_copy.txt') samples = [('sample_01.txt', 'sample_01_copy.txt'), ('sample_02.txt', 'sample_02_copy.txt'), ('sample_03.txt', 'sample_03_copy.txt'), ] .describe("Test BitBlender") def test_group(): .it("Overwrite Sample Data") def test_case(): for sample in samples: # overwrite the sample files BitBlender(target_file=sample[0]).execute() # Compare orignal files with overwritten files for sample in samples: result = filecmp.cmp(sample[0], sample[1], shallow=False) test.assert_equals(result, False) .it("Delete Sample Data") def test_case(): for sample in samples: # overwrite the sample files + deletion BitBlender(target_file=sample[0], deletion=True).execute() # Check if file exists for sample in samples: result = os.path.exists(sample[0]) test.assert_equals(result, False) # Remove copied sample data for s in samples: os.remove(s[1])
- import codewars_test as test
- import os
- import filecmp # used for file comparison
- import shutil # used to copy files
- from solution import BitBlender, fake_data
- # Create fake sample files
- fake_data('sample_01.txt')
- fake_data('sample_02.txt')
- fake_data('sample_03.txt')
- # Create copies of sample file for comparison
- shutil.copy('sample_01.txt', 'sample_01_copy.txt')
- shutil.copy('sample_02.txt', 'sample_02_copy.txt')
- shutil.copy('sample_03.txt', 'sample_03_copy.txt')
- samples = [('sample_01.txt', 'sample_01_copy.txt'),
- ('sample_02.txt', 'sample_02_copy.txt'),
- ('sample_03.txt', 'sample_03_copy.txt'),
- ]
- @test.describe("Test BitBlender")
- def test_group():
- @test.it("Overwrite Sample Data")
- def test_case():
- for sample in samples:
# overwritte the sample files- # overwrite the sample files
- BitBlender(target_file=sample[0]).execute()
- # Compare orignal files with overwritten files
- for sample in samples:
- result = filecmp.cmp(sample[0], sample[1], shallow=False)
- test.assert_equals(result, False)
- @test.it("Delete Sample Data")
- def test_case():
- for sample in samples:
# overwritte the sample files- # overwrite the sample files + deletion
- BitBlender(target_file=sample[0], deletion=True).execute()
- # Check if file exists
- for sample in samples:
- result = os.path.exists(sample[0])
- test.assert_equals(result, False)
- # Remove copied sample data
- for s in samples:
- os.remove(s[1])
This program is designed to overwrite and delete files by:
- Creating an erroneous file of equal file size
- Overwriting file numm times
- Optionally deleting file
I chose to make deletion
optional incase one wanted to use a more secure deletion program like CCleaner
, Eraser
, or BleachBit
...
import os
class BitBlender:
"""BitBlender class"""
def __init__(self, target_file, num=7, deletion=False):
self.target_file = target_file
self.num = num # number of times to overwrite file
self.deletion = deletion
self.file_size = os.path.getsize(self.target_file)
if os.path.exists(self.target_file):
self.file_size = os.path.getsize(self.target_file)
else:
raise FileNotFoundError(f"The file '{self.target_file}' does not exist.")
def execute(self):
pass
import codewars_test as test
import os
import filecmp # used for file comparison
import shutil # used to copy files
from solution import BitBlender, fake_data
# Create fake sample files
fake_data('sample_01.txt')
fake_data('sample_02.txt')
fake_data('sample_03.txt')
# Create copies of sample file for comparison
shutil.copy('sample_01.txt', 'sample_01_copy.txt')
shutil.copy('sample_02.txt', 'sample_02_copy.txt')
shutil.copy('sample_03.txt', 'sample_03_copy.txt')
samples = [('sample_01.txt', 'sample_01_copy.txt'),
('sample_02.txt', 'sample_02_copy.txt'),
('sample_03.txt', 'sample_03_copy.txt'),
]
.describe("Test BitBlender")
def test_group():
.it("Overwrite Sample Data")
def test_case():
for sample in samples:
# overwritte the sample files
BitBlender(target_file=sample[0]).execute()
# Compare orignal files with overwritten files
for sample in samples:
result = filecmp.cmp(sample[0], sample[1], shallow=False)
test.assert_equals(result, False)
.it("Delete Sample Data")
def test_case():
for sample in samples:
# overwritte the sample files
BitBlender(target_file=sample[0], deletion=True).execute()
for sample in samples:
result = os.path.exists(sample[0])
test.assert_equals(result, False)
# Remove copied sample data
for s in samples:
os.remove(s[1])
seraph776vs.ThatOneGuyWhoCodes2 months ago
Proche de 0: (Close to 0)
- Trimmed down the function name for minimum characters
ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
ClosestToZero=lambda n:type("",(),{"execute":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})- ClosestToZero=lambda n:type("",(),{"e":lambda v=min(n,key=abs,default=0):dict(zip(n,n)).get(abs(v),v),"n":n})
import codewars_test as test from solution import ClosestToZero .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).e(), 1) test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).e(), -2) test.assert_equals(ClosestToZero([-5, -5]).e(), -5) test.assert_equals(ClosestToZero([]).e(), 0) test.assert_equals(ClosestToZero([-5, 0, 1, 5]).e(), 0) test.assert_equals(ClosestToZero([-5, -1, 1, 5]).e(), 1)
- import codewars_test as test
- from solution import ClosestToZero
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).execute(), 1)test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).execute(), -2)test.assert_equals(ClosestToZero([-5, -5]).execute(), -5)test.assert_equals(ClosestToZero([]).execute(), 0)test.assert_equals(ClosestToZero([-5, 0, 1, 5]).execute(), 0)test.assert_equals(ClosestToZero([-5, -1, 1, 5]).execute(), 1)- test.assert_equals(ClosestToZero([7, 5, 9, 1, 4]).e(), 1)
- test.assert_equals(ClosestToZero([7,-4, -3, -12, 5, 9, -2, 4]).e(), -2)
- test.assert_equals(ClosestToZero([-5, -5]).e(), -5)
- test.assert_equals(ClosestToZero([]).e(), 0)
- test.assert_equals(ClosestToZero([-5, 0, 1, 5]).e(), 0)
- test.assert_equals(ClosestToZero([-5, -1, 1, 5]).e(), 1)
- Botched the indents
class MaxDigit: def __init__(s, n):s.n = n def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))
- class MaxDigit:
def __init__(s, n):s.n = ndef execute(s):return int(''.join(sorted(str(s.n), reverse=True)))- def __init__(s, n):s.n = n
- def execute(s): return int(''.join(sorted(str(s.n), reverse=True)))
seraph776vs.ThatOneGuyWhoCodes2 months ago
Proche de 0: (Close to 0)
- Fixed the indents
class ClosestToZero: def __init__(s,p): s.p=p def execute(s): v=min(s.p,key=abs,default=0) a=abs(v) return a if a in s.p else v
- class ClosestToZero:
def __init__(s,p):s.p=pdef execute(s):v=min(s.p,key=abs,default=0)a=abs(v)return a if a in s.p else v- def __init__(s,p):
- s.p=p
- def execute(s):
- v=min(s.p,key=abs,default=0)
- a=abs(v)
- return a if a in s.p else v
class MaxDigit: def __init__(self, n): self.n = n def execute(self): return int(''.join((sorted([n for n in str(self.n)], reverse=True))))
import java.util.Arrays;- class MaxDigit:
- def __init__(self, n):
- self.n = n
public class MaxNumber {public static long print(long number) {String num = "" + number;char[] array = num.toCharArray();Arrays.sort(array);StringBuilder builder = new StringBuilder();builder.append(array);builder.reverse();return Long.parseLong(builder.toString());}}- def execute(self):
- return int(''.join((sorted([n for n in str(self.n)], reverse=True))))
import codewars_test as test from solution import MaxDigit # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case") def test_case(): samples = [(12, 21), (677, 776), (101, 110), (400000005000007000, 754000000000000000), (307778062924466824,988777666444322200)] for s, e in samples: test.assert_equals(MaxDigit(s).execute(), e)
import static org.junit.Assert.assertEquals;import org.junit.Test;import java.util.Random;- import codewars_test as test
- from solution import MaxDigit
public class MaxNumberTest {@Testpublic void testFour() {assertEquals(4, MaxNumber.print(4));}@Testpublic void testTwelve() {assertEquals(21, MaxNumber.print(12));}@Testpublic void testOneHundred() {assertEquals(110, MaxNumber.print(101));}@Testpublic void testHuge1() {assertEquals(754000000000000000L, MaxNumber.print(400000005000007000L));}@Testpublic void testHuge2() {assertEquals(988777666444322200L, MaxNumber.print(307778062924466824L));}}- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- samples = [(12, 21), (677, 776), (101, 110), (400000005000007000, 754000000000000000), (307778062924466824,988777666444322200)]
- for s, e in samples:
- test.assert_equals(MaxDigit(s).execute(), e)
seraph776vs.pearcebasmanm2 months ago
Is my password strong?
- Converted to python 🐍
import string PUNCTUATION = string.punctuation def test_password(password): # password must be no less than 8 characters long c1 = len(password) >= 8 # password must have at least 1 capital letter c2 = len([1 for t in password if t == t.upper()]) >= 1 # password must have at least 1 number c3 = len([1 for t in password if t.isdigit()]) >= 1 # password must have at least 1 special character c4 = len([1 for t in password if t in PUNCTUATION]) >= 1 # Return True if all conditions are True return all([c1,c2,c3,c4])
fn test_password(password: &str) -> bool {password.len() >= 8&& password.chars().any(|c| c.is_ascii_uppercase())&& password.chars().any(|c| c.is_ascii_digit())&& password.chars().any(|c| "!\"#$%&'()*+'-./;:<>=?".contains(c))}- import string
- PUNCTUATION = string.punctuation
- def test_password(password):
- # password must be no less than 8 characters long
- c1 = len(password) >= 8
- # password must have at least 1 capital letter
- c2 = len([1 for t in password if t == t.upper()]) >= 1
- # password must have at least 1 number
- c3 = len([1 for t in password if t.isdigit()]) >= 1
- # password must have at least 1 special character
- c4 = len([1 for t in password if t in PUNCTUATION]) >= 1
- # Return True if all conditions are True
- return all([c1,c2,c3,c4])
import codewars_test as test from solution import test_password # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case: True") def test_case(): test.assert_equals(test_password("Pas$word1"), True) test.assert_equals(test_password("ALLTH3TH!NGS"), True) .it("test case: False") def test_case(): test.assert_equals(test_password("password"), False) test.assert_equals(test_password("WodT$m1"), False)
#[test]fn test_good() {assert!(test_password("Pas$word1"));assert!(test_password("ALLTH3TH!NGS"));}- import codewars_test as test
- from solution import test_password
#[test]fn test_bad() {assert!(!test_password("password"));assert!(!test_password("WodT$m1"));}- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case: True")
- def test_case():
- test.assert_equals(test_password("Pas$word1"), True)
- test.assert_equals(test_password("ALLTH3TH!NGS"), True)
- @test.it("test case: False")
- def test_case():
- test.assert_equals(test_password("password"), False)
- test.assert_equals(test_password("WodT$m1"), False)
- Class version
class ClosetToZero: """Return the integer in the params closest to zero""" def __init__(self, params:list): self.params = params def execute(self): if not self.params: return 0 if min(self.params, key=abs) < 0 and abs(min(self.params, key=abs)) in self.params: return abs(min(self.params, key=abs)) return min(self.params, key=abs)
def closest_to_zero(nums):return 0 if not nums else abs(min(nums, key=abs)) if min(nums, key=abs) < 0 and abs(min(nums, key=abs)) in nums else min(nums, key=abs)- class ClosetToZero:
- """Return the integer in the params closest to zero"""
- def __init__(self, params:list):
- self.params = params
- def execute(self):
- if not self.params:
- return 0
- if min(self.params, key=abs) < 0 and abs(min(self.params, key=abs)) in self.params:
- return abs(min(self.params, key=abs))
- return min(self.params, key=abs)
import codewars_test as test from solution import ClosetToZero .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(ClosetToZero([7, 5, 9, 1, 4]).execute(), 1) test.assert_equals(ClosetToZero([7,-4, -3, -12, 5, 9, -2, 4]).execute(), -2) test.assert_equals(ClosetToZero([-5, -5]).execute(), -5) test.assert_equals(ClosetToZero([]).execute(), 0) test.assert_equals(ClosetToZero([-5, 0, 1, 5]).execute(), 0) test.assert_equals(ClosetToZero([-5, -1, 1, 5]).execute(), 1)
- import codewars_test as test
from solution import closest_to_zero- from solution import ClosetToZero
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(closest_to_zero([7, 5, 9, 1, 4]), 1)test.assert_equals(closest_to_zero([7,-4, -3, -12, 5, 9, -2, 4]), -2)test.assert_equals(closest_to_zero([-5, -5]), -5)test.assert_equals(closest_to_zero([]), 0)test.assert_equals(closest_to_zero([-5, 0, 1, 5]), 0)test.assert_equals(closest_to_zero([-5, -1, 1, 5]), 1)- test.assert_equals(ClosetToZero([7, 5, 9, 1, 4]).execute(), 1)
- test.assert_equals(ClosetToZero([7,-4, -3, -12, 5, 9, -2, 4]).execute(), -2)
- test.assert_equals(ClosetToZero([-5, -5]).execute(), -5)
- test.assert_equals(ClosetToZero([]).execute(), 0)
- test.assert_equals(ClosetToZero([-5, 0, 1, 5]).execute(), 0)
- test.assert_equals(ClosetToZero([-5, -1, 1, 5]).execute(), 1)
- Changed for loop to list comprehension
def closest_to_zero(nums): return 0 if not nums else abs(min(nums, key=abs)) if min(nums, key=abs) < 0 and abs(min(nums, key=abs)) in nums else min(nums, key=abs)
def closest_to_zero(nums):if not nums:return 0n = min(nums, key=abs)if n < 0 and abs(n) in nums:return abs(n)return n- def closest_to_zero(nums):
- return 0 if not nums else abs(min(nums, key=abs)) if min(nums, key=abs) < 0 and abs(min(nums, key=abs)) in nums else min(nums, key=abs)
seraph776vs.LucasLaurens2 months ago
Proche de 0: (Close to 0)
- Converted to Python 🐍
Original Instructions Translated:
Implement the closestToZero function to return the integer in the $ints array closest to zero.
If there are two integers equally close to zero, consider the positive integer to be closest to zero (e.g. if $ints contains -5 and 5, return 5). If $ints is empty, return 0 (zero).
If there is a zero in the list, return zero
Data: Integers in $ints have values ranging from -2147483647 to 2147483647.
`
def closest_to_zero(nums): if not nums: return 0 n = min(nums, key=abs) if n < 0 and abs(n) in nums: return abs(n) return n
// Could implement a contractfinal class Closest{private int $closest = 0;public function __construct(private array $nbrs) {}public function __invoke(): int{if (empty($this->nbrs) or in_array(0, $this->nbrs)) {return 0;}foreach ($this->nbrs as $nbr) {if (!is_int($nbr)) {continue;}if (0 === $this->closest|| abs($nbr) < abs($this->closest) // e.g. 2 < 3|| (abs($nbr) === abs($this->closest) && $nbr > $this->closest) // e.g. 2 === 2 && 2 > -2) {$this->closest = $nbr;}}return $this->closest;}}function closestToZero(array $nbrs): int {return (new Closest($nbrs))();}- def closest_to_zero(nums):
- if not nums:
- return 0
- n = min(nums, key=abs)
- if n < 0 and abs(n) in nums:
- return abs(n)
- return n
import codewars_test as test from solution import closest_to_zero .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(closest_to_zero([7, 5, 9, 1, 4]), 1) test.assert_equals(closest_to_zero([7,-4, -3, -12, 5, 9, -2, 4]), -2) test.assert_equals(closest_to_zero([-5, -5]), -5) test.assert_equals(closest_to_zero([]), 0) test.assert_equals(closest_to_zero([-5, 0, 1, 5]), 0) test.assert_equals(closest_to_zero([-5, -1, 1, 5]), 1)
<?phpuse PHPUnit\Framework\TestCase;- import codewars_test as test
- from solution import closest_to_zero
class ExampleTest extends TestCase{public function testSimple() {echo "Test [7, 5, 9, 1, 4]";$this->assertEquals(1, closestToZero([7, 5, 9, 1, 4]));}public function testNegative() {echo "Test [7,-4, -3, -12, 5, 9, -2, 4]";$this->assertEquals(-2, closestToZero([7,-4, -3, -12, 5, 9, -2, 4]));}public function testSame() {echo "Test [-5, -5]";$this->assertEquals(-5, closestToZero([-5, -5]));}public function testEmpty() {echo "Test []";$this->assertEquals(0, closestToZero([]));}public function testWithZero() {echo "Test [-5, 0, 1, 5]";$this->assertEquals(0, closestToZero([-5, 0, 1, 5]));}public function testSameDistance() {echo "Test [-5, -1, 1, 5]";$this->assertEquals(1, closestToZero([-5, -1, 1, 5]));}}- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(closest_to_zero([7, 5, 9, 1, 4]), 1)
- test.assert_equals(closest_to_zero([7,-4, -3, -12, 5, 9, -2, 4]), -2)
- test.assert_equals(closest_to_zero([-5, -5]), -5)
- test.assert_equals(closest_to_zero([]), 0)
- test.assert_equals(closest_to_zero([-5, 0, 1, 5]), 0)
- test.assert_equals(closest_to_zero([-5, -1, 1, 5]), 1)
- Converted to Python 🐍
class Kumite: def __init__(self, name1, name2): self.name1 = name1 self.name2 = name2 def solve(self): return None if not self.name1 or not self.name2 else ( sum([ord(t)for t in self.name1]) == sum([ord(t) for t in self.name2]))
class Kata {- class Kumite:
- def __init__(self, name1, name2):
- self.name1 = name1
- self.name2 = name2
public static String verifySum(String nameOne, String nameTwo) {if(nameOne == null || nameTwo == null) {return "NULL";}int sum = 0, lengthOne = nameOne.length(), lengthTwo = nameTwo.length();for(int i = 0; i < lengthOne; i++) {char c = nameOne.charAt(i);sum += c > 96 ? c - 32 : c;}for(int i = 0; i < lengthTwo; i++) {char c = nameTwo.charAt(i);sum -= c > 96 ? c - 32 : c;}return sum == 0 ? "TRUE" : "FALSE";}}- def solve(self):
- return None if not self.name1 or not self.name2 else (
- sum([ord(t)for t in self.name1]) == sum([ord(t) for t in self.name2]))
import codewars_test as test from solution import Kumite # test.assert_equals(actual, expected, [optional] message) .describe("Example") def test_group(): .it("test case") def test_case(): test.assert_equals(Kumite("Sebastian", "Patricia").solve(), False) test.assert_equals(Kumite("Anna", "Nana").solve(), True) test.assert_equals(Kumite("seraph776", None).solve(), None) test.assert_equals(Kumite("", "codewarz").solve(), None)
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;- import codewars_test as test
public class SolutionTest {@Testpublic void testName() {assertEquals("FALSE", Kata.verifySum("Sebastian", "Patricia"));assertEquals("TRUE", Kata.verifySum("Anna", "Nana"));assertEquals("NULL", Kata.verifySum("John", null));}}- from solution import Kumite
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(Kumite("Sebastian", "Patricia").solve(), False)
- test.assert_equals(Kumite("Anna", "Nana").solve(), True)
- test.assert_equals(Kumite("seraph776", None).solve(), None)
- test.assert_equals(Kumite("", "codewarz").solve(), None)
seraph776vs.pearcebasmanm2 months ago
Oseguera's Reverse Integer Kumite
- Converted to Python 🐍
def reverse_int(n): return int(str(n)[::-1])
fn reverse(mut n: u32) -> u32 {let mut reversed = 0;while n > 0 {reversed *= 10;reversed += n % 10;n /= 10;}reversed}- def reverse_int(n):
- return int(str(n)[::-1])
import codewars_test as test from solution import reverse_int .describe("Example") def test_group(): .it("test case") def test_case(): test_samples = ( (776,677), (12345,54321), (3121534312,2134351213), (726376882009597984841891,198148489795900288673627), ) for s, e in test_samples: test.assert_equals(reverse_int(s), e)
#[test]fn test() {assert_eq!(reverse(12345), 54321);}- import codewars_test as test
- from solution import reverse_int
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test_samples = (
- (776,677),
- (12345,54321),
- (3121534312,2134351213),
- (726376882009597984841891,198148489795900288673627),
- )
- for s, e in test_samples:
- test.assert_equals(reverse_int(s), e)
class IsPrimeNumber: """Returns True if n is a prime number, False otherwise""" def __init__(self, n): self.n = n def calculate(self): if self.n > 1: for i in range(2, int(self.n ** 0.5) + 1): if self.n % i == 0: return False return True # If no divisors found, it's prime else: return False class Fizz: """Returns True if n is divisible by 3, False otherwise""" def __init__(self, n): self.n = n def calculate(self): return self.n % 3 == 0 class Buzz: """Returns True if n is divisible by 5, False otherwise""" def __init__(self, n): self.n = n def calculate(self): return self.n % 5 == 0 class FizzBuzz: """Returns True if n is divisible by 3 and 5, False otherwise""" def __init__(self, n): self.n = n def calculate(self): return Fizz(self.n).calculate() and Buzz(self.n).calculate() class CodeWarKata776: """Executes the Fizz, Bizz, FizzBuzz Prime sequence.""" def __init__(self, n): self.n = n def calculate_prime(self): return IsPrimeNumber(self.n).calculate() def calculate_fizz(self): return Fizz(self.n).calculate() def calculate_buzz(self): return Buzz(self.n).calculate() def calculate_fizzbuzz(self): return FizzBuzz(self.n).calculate() def execute(self): if IsPrimeNumber(self.n).calculate(): return 'Prime' if FizzBuzz(self.n).calculate(): return 'FizzBuzz' elif Fizz(self.n).calculate(): return 'Fizz' elif Buzz(self.n).calculate(): return 'Buzz' else: return self.n
- class IsPrimeNumber:
- """Returns True if n is a prime number, False otherwise"""
- def __init__(self, n):
- self.n = n
- def calculate(self):
pass- if self.n > 1:
- for i in range(2, int(self.n ** 0.5) + 1):
- if self.n % i == 0:
- return False
- return True # If no divisors found, it's prime
- else:
- return False
- class Fizz:
- """Returns True if n is divisible by 3, False otherwise"""
- def __init__(self, n):
- self.n = n
- def calculate(self):
pass- return self.n % 3 == 0
- class Buzz:
- """Returns True if n is divisible by 5, False otherwise"""
- def __init__(self, n):
- self.n = n
- def calculate(self):
pass- return self.n % 5 == 0
- class FizzBuzz:
- """Returns True if n is divisible by 3 and 5, False otherwise"""
- def __init__(self, n):
- self.n = n
- def calculate(self):
pass- return Fizz(self.n).calculate() and Buzz(self.n).calculate()
- class CodeWarKata776:
- """Executes the Fizz, Bizz, FizzBuzz Prime sequence."""
- def __init__(self, n):
- self.n = n
- def calculate_prime(self):
pass- return IsPrimeNumber(self.n).calculate()
- def calculate_fizz(self):
pass- return Fizz(self.n).calculate()
- def calculate_buzz(self):
pass- return Buzz(self.n).calculate()
- def calculate_fizzbuzz(self):
pass- return FizzBuzz(self.n).calculate()
- def execute(self):
pass- if IsPrimeNumber(self.n).calculate():
- return 'Prime'
- if FizzBuzz(self.n).calculate():
- return 'FizzBuzz'
- elif Fizz(self.n).calculate():
- return 'Fizz'
- elif Buzz(self.n).calculate():
- return 'Buzz'
- else:
- return self.n