import codewars_test as test import solution @test.describe('Test') def test_group(): @test.it('Even case') def is_even(): for i in range(-30, 30, 2): test.assert_equals(solution.is_even(i), True) @test.it('Odd case') def is_even(): for i in range(-29, 30, 2): test.assert_equals(solution.is_even(i), False)
- import codewars_test as test
- import solution
- @test.describe('Test')
- def test_group():
- @test.it('Even case')
- def is_even():
for i in range(0, 30, 2):- for i in range(-30, 30, 2):
- test.assert_equals(solution.is_even(i), True)
- @test.it('Odd case')
- def is_even():
for i in range(1, 30, 2):- for i in range(-29, 30, 2):
- test.assert_equals(solution.is_even(i), False)
import codewars_test as test import solution @test.describe('Test') def test_group(): @test.it('Even case') def is_even(): for i in range(-30, 30, 2): test.assert_equals(solution.is_even(i), True) @test.it('Odd case') def is_even(): for i in range(-29, 30, 2): test.assert_equals(solution.is_even(i), False)
- import codewars_test as test
- import solution
- @test.describe('Test')
- def test_group():
- @test.it('Even case')
- def is_even():
for i in range(0, 30, 2):- for i in range(-30, 30, 2):
- test.assert_equals(solution.is_even(i), True)
- @test.it('Odd case')
- def is_even():
for i in range(1, 30, 2):- for i in range(-29, 30, 2):
- test.assert_equals(solution.is_even(i), False)
package cat; public class kata{ public static int doubleValue(int x) { return x + x; } }
- package cat;
- public class kata{
- public static int doubleValue(int x) {
return x * 2;- return x + x;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import cat.kata.*; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testSomething() { assertEquals(cat.kata.doubleValue(2), 4); assertEquals(cat.kata.doubleValue(-2), -4); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import cat.kata.*;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testSomething() {
- assertEquals(cat.kata.doubleValue(2), 4);
- assertEquals(cat.kata.doubleValue(-2), -4);
- }
- }
import java.lang.Math; interface Kata { static int doubleValue(int x) { boolean isNeg=x<0; if (isNeg){ x= -x; } x=x+x; StringBuilder b= new StringBuilder(); while (x!=0){ b.append(x%2==0?"h":"a-"); x=x/2; } b=b.reverse(); String s=b.toString().replaceAll("-", ""); int curr=s.length()-1; int acc=0; int i=0; while (i<s.length()){ acc+= s.charAt(i)=='a'? (int) Math.pow(2,curr):0; i++; curr--; } return isNeg?-acc:acc; } }
- import java.lang.Math;
- interface Kata {
- static int doubleValue(int x) {
- boolean isNeg=x<0;
- if (isNeg){
- x= -x;
- }
- x=x+x;
- StringBuilder b= new StringBuilder();
- while (x!=0){
b.append(x%2==0?"0":"1");- b.append(x%2==0?"h":"a-");
- x=x/2;
- }
- b=b.reverse();
String s=b.toString();- String s=b.toString().replaceAll("-", "");
- int curr=s.length()-1;
- int acc=0;
- int i=0;
- while (i<s.length()){
acc+= s.charAt(i)=='1'? (int) Math.pow(2,curr):0;- acc+= s.charAt(i)=='a'? (int) Math.pow(2,curr):0;
- i++;
- curr--;
- }
- return isNeg?-acc:acc;
- }
- }