Move History

Rooted by: Is it odd?
Fork Selected
  • Fundamentals
    Numbers
    Data Types
    Integers
    Description

    I'm just playing with kumite !!!!!

    Code
    def is_odd(input)
      input & 1 == 1
    end
    
    Test Cases
    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
      
  • Code
    • def is_odd(input):
    • return input & 1
    • def is_odd(input)
    • input & 1 == 1
    • end
    Test Cases
    • 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 "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 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)
    • 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