-
FundamentalsNumbersData TypesIntegers
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
Output:
-
Code def is_odd(input):return input & 1- def is_odd(input)
- input & 1 == 1
- end
Test Cases 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
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}