return type
shorten a lot
export function reverseInt(n: number): number { return +[...""+n].reverse().join("") }
export function reverseInt(n: number) {return +String(n).replace(/\d/g, (_, i, a) => a.slice(a.length - i - 1, a.length - i))- export function reverseInt(n: number): number {
- return +[...""+n].reverse().join("")
- }
RSpec works as expected with the extra diff
message.
puts # "Uncomment the test cases to see the errors"
puts "Uncomment the test cases to see the errors"- puts # "Uncomment the test cases to see the errors"
describe "Example" do it "Will log error" do # expect(false).to eq(true), "This is an error\nThis is a log" # expect("error").not_to eq("error"), "This is an error\nThis is a log" end end
- describe "Example" do
it "Will log error" doTest.expect(true)# Test.expect(false, "This is an error\nThis is a log")# Test.assert_equals(false, true, "This is an errorThis is a log")# Test.assert_not_equals("error", "error", "This is an errorThis is a log")- it "Will log error" do
- # expect(false).to eq(true), "This is an error
- This is a log"
- # expect("error").not_to eq("error"), "This is an error
- This is a log"
- end
- end
One char less ~~
first time programming in C++ ~~
ruby lambda function
palindrome = ->(x) do x.downcase == x.downcase.reverse end
Palindrome = lambda x: x.lower() == x.lower()[::-1]- palindrome = ->(x) do
- x.downcase == x.downcase.reverse
- end
Test.describe "Basic Tests" do Test.it "should pass fixed tests" do Test.assert_equals(palindrome.("MOM"), true) Test.assert_equals(palindrome.("kAyaK"), true) Test.assert_equals(palindrome.("123454321"), true) Test.assert_equals(palindrome.("n1oo1n"), true) Test.assert_equals(palindrome.("X"), true) Test.assert_equals(palindrome.(""), true) Test.assert_equals(palindrome.("n1oo1n"), true) Test.assert_equals(palindrome.("506050"), false) Test.assert_equals(palindrome.("idEddEddi"), false) end end
Test.describe("Basic Tests")test.assert_equals(Palindrome("MOM"), True)test.assert_equals(Palindrome("kAyaK"), True)test.assert_equals(Palindrome("123454321"), True)test.assert_equals(Palindrome("n1oo1n"), True)test.assert_equals(Palindrome("X"), True)test.assert_equals(Palindrome(""), True)test.assert_equals(Palindrome("n1oo1n"), True)test.assert_equals(Palindrome("rotlor"), False)test.assert_equals(Palindrome("506050"), False)test.assert_equals(Palindrome("idEddEddi"), False)- Test.describe "Basic Tests" do
- Test.it "should pass fixed tests" do
- Test.assert_equals(palindrome.("MOM"), true)
- Test.assert_equals(palindrome.("kAyaK"), true)
- Test.assert_equals(palindrome.("123454321"), true)
- Test.assert_equals(palindrome.("n1oo1n"), true)
- Test.assert_equals(palindrome.("X"), true)
- Test.assert_equals(palindrome.(""), true)
- Test.assert_equals(palindrome.("n1oo1n"), true)
- Test.assert_equals(palindrome.("506050"), false)
- Test.assert_equals(palindrome.("idEddEddi"), false)
- end
- end
Fundamentals
Numbers
Data Types
Integers
I'm just playing with kumite !!!!!
def is_odd(input) input & 1 == 1 end
def is_odd(input):return input & 1- def is_odd(input)
- input & 1 == 1
- end
Test.describe "Fixed tests" do Test.it "should pass fixed tests" do Test.assert_equals(is_odd(1), true) Test.assert_equals(is_odd(2), false) Test.assert_equals(is_odd(13), true) Test.assert_equals(is_odd(18284), false) Test.assert_equals(is_odd(-1), true) end end Test.describe "Random Tests" do Test.it "should pass random tests" do 100.times do n = rand(-(10**rand(1..5))..10 ** rand(1..5)) Test.assert_equals(is_odd(n), n & 1 == 1) end end end
import codewars_test as testfrom solution import is_odd@test.describe("Fixed Tests")def fixed_tests():@test.it('Basic Test Cases')def basic_test_cases():test.assert_equals(is_odd(1), True)test.assert_equals(is_odd(2), False)test.assert_equals(is_odd(13), True)test.assert_equals(is_odd(18284), False)test.assert_equals(is_odd(-1), True)- Test.describe "Fixed tests" do
- Test.it "should pass fixed tests" do
- Test.assert_equals(is_odd(1), true)
- Test.assert_equals(is_odd(2), false)
- Test.assert_equals(is_odd(13), true)
- Test.assert_equals(is_odd(18284), false)
- Test.assert_equals(is_odd(-1), true)
- end
- end
@test.describe("Random Tests")def random_tests():from random import randintfor _ in range(100):n = randint(-(10**randint(1, 5)), 10 ** randint(1, 5))@test.it(f"testing for is_odd({n})")def test_case():test.assert_equals(is_odd(n), n & 1)- Test.describe "Random Tests" do
- Test.it "should pass random tests" do
- 100.times do
- n = rand(-(10**rand(1..5))..10 ** rand(1..5))
- Test.assert_equals(is_odd(n), n & 1 == 1)
- end
- end
- end
Fundamentals
Numbers
Data Types
Integers
I'm just playing around with kumite !!!!!
def is_odd(input): return input & 1
public static class Kata{public static bool IsOdd(int input){return (input & 1) == 1;}}- def is_odd(input):
- return input & 1
import codewars_test as test from solution import is_odd @test.describe("Fixed Tests") def fixed_tests(): @test.it('Basic Test Cases') def basic_test_cases(): test.assert_equals(is_odd(1), True) test.assert_equals(is_odd(2), False) test.assert_equals(is_odd(13), True) test.assert_equals(is_odd(18284), False) test.assert_equals(is_odd(-1), True) @test.describe("Random Tests") def random_tests(): from random import randint for _ in range(100): n = randint(-(10**randint(1, 5)), 10 ** randint(1, 5)) @test.it(f"testing for is_odd({n})") def test_case(): test.assert_equals(is_odd(n), n & 1)
namespace Solution {using NUnit.Framework;using System;- import codewars_test as test
- from solution import is_odd
// TODO: Replace examples and use TDD by writing your own tests[TestFixture]public class SolutionTest{[Test]public void MyTest(){Assert.AreEqual(true, Kata.IsOdd(1));Assert.AreEqual(false, Kata.IsOdd(2));Assert.AreEqual(true, Kata.IsOdd(13));Assert.AreEqual(false, Kata.IsOdd(18284));Assert.AreEqual(true, Kata.IsOdd(-1));}}}- @test.describe("Fixed Tests")
- def fixed_tests():
- @test.it('Basic Test Cases')
- def basic_test_cases():
- test.assert_equals(is_odd(1), True)
- test.assert_equals(is_odd(2), False)
- test.assert_equals(is_odd(13), True)
- test.assert_equals(is_odd(18284), False)
- test.assert_equals(is_odd(-1), True)
- @test.describe("Random Tests")
- def random_tests():
- from random import randint
- for _ in range(100):
- n = randint(-(10**randint(1, 5)), 10 ** randint(1, 5))
- @test.it(f"testing for is_odd({n})")
- def test_case():
- test.assert_equals(is_odd(n), n & 1)
require "prime" def is_prime(n) n.prime? end
is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))- require "prime"
- def is_prime(n)
- n.prime?
- end
Test.describe "Fixed Tests" do Test.it 'Basic Test Cases' do Test.assert_equals(is_prime(2), true) Test.assert_equals(is_prime(3), true) Test.assert_equals(is_prime(5), true) Test.assert_equals(is_prime(3571), true) Test.assert_equals(is_prime(0), false) Test.assert_equals(is_prime(1), false) Test.assert_equals(is_prime(4), false) Test.assert_equals(is_prime(3572), false) Test.assert_equals(is_prime(25), false) end end Test.describe "Random Tests" do Test.it "should pass random tests" do require "prime" sol = ->(n) do n.prime? end 100.times do num = rand(0..10**rand(1..5)) Test.assert_equals(is_prime(num), sol.(num)) end end end
import codewars_test as testfrom solution import is_prime@test.describe("Fixed Tests")def fixed_tests():@test.it('Basic Test Cases')def basic_test_cases():test.assert_equals(is_prime(2), True)test.assert_equals(is_prime(3), True)test.assert_equals(is_prime(5), True)test.assert_equals(is_prime(3571), True)test.assert_equals(is_prime(0), False)test.assert_equals(is_prime(1), False)test.assert_equals(is_prime(4), False)test.assert_equals(is_prime(3572), False)test.assert_equals(is_prime(25), False)- Test.describe "Fixed Tests" do
- Test.it 'Basic Test Cases' do
- Test.assert_equals(is_prime(2), true)
- Test.assert_equals(is_prime(3), true)
- Test.assert_equals(is_prime(5), true)
- Test.assert_equals(is_prime(3571), true)
- Test.assert_equals(is_prime(0), false)
- Test.assert_equals(is_prime(1), false)
- Test.assert_equals(is_prime(4), false)
- Test.assert_equals(is_prime(3572), false)
- Test.assert_equals(is_prime(25), false)
- end
- end
@test.describe("Random Tests")def random_tests():- Test.describe "Random Tests" do
- Test.it "should pass random tests" do
from random import randint- require "prime"
for _ in range(100):num = randint(0, 10**randint(1,5))expected = num == 2 or num > 2 and num % 2 and all(num % i for i in range(3, int(num**.5) + 1, 2))@test.it(f"testing for is_prime({num})")def test_case():test.assert_equals(is_prime(num), expected)- sol = ->(n) do
- n.prime?
- end
- 100.times do
- num = rand(0..10**rand(1..5))
- Test.assert_equals(is_prime(num), sol.(num))
- end
- end
- end
All the previous forks are wrong due to the lack of random test cases !!!
is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1- is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
import codewars_test as test from solution import is_prime @test.describe("Fixed Tests") def fixed_tests(): @test.it('Basic Test Cases') def basic_test_cases(): test.assert_equals(is_prime(2), True) test.assert_equals(is_prime(3), True) test.assert_equals(is_prime(5), True) test.assert_equals(is_prime(3571), True) test.assert_equals(is_prime(0), False) test.assert_equals(is_prime(1), False) test.assert_equals(is_prime(4), False) test.assert_equals(is_prime(3572), False) test.assert_equals(is_prime(25), False) @test.describe("Random Tests") def random_tests(): from random import randint for _ in range(100): num = randint(0, 10**randint(1,5)) expected = num == 2 or num > 2 and num % 2 and all(num % i for i in range(3, int(num**.5) + 1, 2)) @test.it(f"testing for is_prime({num})") def test_case(): test.assert_equals(is_prime(num), expected)
test.assert_equals(is_prime(2), True)test.assert_equals(is_prime(3), True)test.assert_equals(is_prime(5), True)test.assert_equals(is_prime(3571), True)test.assert_equals(is_prime(0), False)test.assert_equals(is_prime(1), False)test.assert_equals(is_prime(4), False)test.assert_equals(is_prime(3572), False)- import codewars_test as test
- from solution import is_prime
- @test.describe("Fixed Tests")
- def fixed_tests():
- @test.it('Basic Test Cases')
- def basic_test_cases():
- test.assert_equals(is_prime(2), True)
- test.assert_equals(is_prime(3), True)
- test.assert_equals(is_prime(5), True)
- test.assert_equals(is_prime(3571), True)
- test.assert_equals(is_prime(0), False)
- test.assert_equals(is_prime(1), False)
- test.assert_equals(is_prime(4), False)
- test.assert_equals(is_prime(3572), False)
- test.assert_equals(is_prime(25), False)
- @test.describe("Random Tests")
- def random_tests():
- from random import randint
- for _ in range(100):
- num = randint(0, 10**randint(1,5))
- expected = num == 2 or num > 2 and num % 2 and all(num % i for i in range(3, int(num**.5) + 1, 2))
- @test.it(f"testing for is_prime({num})")
- def test_case():
- test.assert_equals(is_prime(num), expected)