string_lower(_, _).
:- begin_tests(example).
:- include(example).
test(string_lower_tests, [forall(member(Input-Expect, ["X"-"x", "A"-"a"])), Result = Expect]) :-
string_lower(Input, Result).
:- end_tests(example).
function foo() {
return bar();
}
const chai = require("chai");
const assert = chai.assert;
function bar() {
return 5;
}
describe("Solution", function() {
it("should test for something", function() {
assert.strictEquals(foo(), 5);
});
});
USING: ;
IN: example
: foo ( -- x ) 4 ;
IN: math.margins
! Overriding math.margins definitions
: ± ( -- y ) 5 ;
USING: math.margins tools.testest ;
FROM: example => foo ;
IN: example.tests
: run-tests ( -- )
"Example" describe#{
"test case" it#{
<{ ± -> 5 }>
}#
}#
;
MAIN: run-tests
USING: namespaces vocabs.loader prettyprint ;
IN: example
vocab-roots get .
! Use vocabulary tools.testest for testing.
! See https://github.com/codewars/testest
USING: example tools.testest ;
IN: example.tests
: run-tests ( -- )
"Example" describe#{
"test case" it#{
<{ 1 -> 1 }>
}#
}#
;
MAIN: run-tests
def foo(n): if n == 0: while True: yield 0 else: for v in foo(n-1): yield v+1
USING: kernel math generators combinators.extras ;IN: exampleGEN: foo ( n -- gen )[ [ 0 yield ] forever ][ 1 - foo [ [ next 1 + yield ] keep ] forever drop ] if-zero ;- def foo(n):
- if n == 0:
- while True:
- yield 0
- else:
- for v in foo(n-1):
- yield v+1
import codewars_test as test from itertools import islice from solution import foo take = lambda gen, n: list(islice(gen, n)) depth = 100 vals = 300 @test.describe("Example") def _(): @test.it("test case") def _(): test.assert_equals(take(foo(depth), vals), [depth]*vals)
USING: example tools.testest generators arrays ;IN: example.tests- import codewars_test as test
- from itertools import islice
- from solution import foo
CONSTANT: depth 100CONSTANT: vals 300- take = lambda gen, n: list(islice(gen, n))
: run-tests ( -- )"Example" describe#{"test case" it#{<{ depth foo vals take -> vals depth <array> }>}#}#;- depth = 100
- vals = 300
MAIN: run-tests- @test.describe("Example")
- def _():
- @test.it("test case")
- def _():
- test.assert_equals(take(foo(depth), vals), [depth]*vals)
Builds a stack of depth
generators, each incrementing a value starting at 0 by 1 before yielding. vals
number of items are then generated. Expected time complexity should be O(depth * vals)
, however we find that depth = 10, vals = 1000
is very fast, depth = 100, vals = 100
is somewhat slow, and depth = 1000, vals = 10
is extremely slow (times out).
USING: kernel math generators combinators.extras ;
IN: example
GEN: foo ( n -- gen )
[ [ 0 yield ] forever ]
[ 1 - foo [ [ next 1 + yield ] keep ] forever drop ] if-zero ;
USING: example tools.testest generators arrays ;
IN: example.tests
CONSTANT: depth 100
CONSTANT: vals 300
: run-tests ( -- )
"Example" describe#{
"test case" it#{
<{ depth foo vals take -> vals depth <array> }>
}#
}#
;
MAIN: run-tests
Simply loading sequences.extras
adds ~5-6 seconds of runtime.
USING: sequences.extras ;
IN: example
: foo ( -- v ) 1 ;
USING: example tools.testest ;
IN: example.tests
: run-tests ( -- )
"Example" describe#{
"test case" it#{
<{ foo -> 1 }>
}#
}#
;
MAIN: run-tests
USING: ;
IN: foo
: bla ( -- ) 3 ;
USING: kernel foo tools.testest prettyprint assocs compiler.errors namespaces sequences tools.errors ;
IN: foo.tests
: run-tests ( -- )
compiler-errors get values [
"Example" describe#{
"test case" it#{
<{ bla -> 1 }>
}#
}#
] [ errors. ] if-empty
;
MAIN: run-tests
print("Solution code")
import codewars_test as test
print("Test Code")
import solution # or from solution import something
# 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)
USING: kernel sequences qw ;
IN: foo
: x ( seq -- counts ) qw{ n e w s } [ [ = ] curry count ] with map ; inline
! Use vocabulary tools.testest for testing.
! See https://github.com/codewars/testest
USING: foo tools.testest ;
IN: example.tests
: run-tests ( -- )
"Example" describe#{
"test case" it#{
<{ { "s" } x -> { 0 0 0 1 } }>
}#
}#
;
MAIN: run-tests
-1
def f(s,p):s.c='YNeos'[(p=='')+sum(map(ord,p.lower()))%324>0::2] KumiteFoo=type('',(),{"__init__":f,"solution":lambda s:s.c})
def f(s,p):s.c='No'if(p=='')+sum(map(ord,p.lower()))%324else'Yes'- def f(s,p):s.c='YNeos'[(p=='')+sum(map(ord,p.lower()))%324>0::2]
- KumiteFoo=type('',(),{"__init__":f,"solution":lambda s:s.c})
import codewars_test as test from solution import KumiteFoo @test.describe("Example") def test_group(): @test.it("test case: True return Yes") def test_case(): test.assert_equals(KumiteFoo('ffoooo').solution(), 'Yes') test.assert_equals(KumiteFoo('fffoooooo').solution(), 'Yes') test.assert_equals(KumiteFoo('fffffoooooooooo').solution(), 'Yes') test.assert_equals(KumiteFoo('FfffFoooOooOoOo').solution(), 'Yes') test.assert_equals(KumiteFoo('ffffffffffffffffoooooooooooooooooooooooooooooooo').solution(), 'Yes') @test.it("test case: False return No") def test_case(): test.assert_equals(KumiteFoo('ffooo').solution(), 'No') test.assert_equals(KumiteFoo('fffooooo').solution(), 'No') test.assert_equals(KumiteFoo('ffoo').solution(), 'No') test.assert_equals(KumiteFoo('').solution(), 'No')
- import codewars_test as test
- from solution import KumiteFoo
- @test.describe("Example")
- def test_group():
- @test.it("test case: True return Yes")
- def test_case():
- test.assert_equals(KumiteFoo('ffoooo').solution(), 'Yes')
- test.assert_equals(KumiteFoo('fffoooooo').solution(), 'Yes')
- test.assert_equals(KumiteFoo('fffffoooooooooo').solution(), 'Yes')
- test.assert_equals(KumiteFoo('FfffFoooOooOoOo').solution(), 'Yes')
- test.assert_equals(KumiteFoo('ffffffffffffffffoooooooooooooooooooooooooooooooo').solution(), 'Yes')
- @test.it("test case: False return No")
- def test_case():
- test.assert_equals(KumiteFoo('ffooo').solution(), 'No')
- test.assert_equals(KumiteFoo('fffooooo').solution(), 'No')
- test.assert_equals(KumiteFoo('ffoo').solution(), 'No')
- test.assert_equals(KumiteFoo('').solution(), 'No')
pattern1 = r"\d|\((?R)\)"
pattern2 = r"(.*)00(?1)"
import codewars_test as test
from solution import pattern1, pattern2
import regex
@test.describe("Recursive regex")
def test_group():
@test.it("Pattern 1")
def test_case():
test.expect(regex.match(pattern1, "5"))
test.expect(regex.match(pattern1, "(6)"))
test.expect(regex.match(pattern1, "((((((9))))))"))
@test.it("Pattern 2")
def test_case():
test.expect(regex.match(pattern2, "110011"))
test.expect(regex.match(pattern2, "abc00abc"))
test.expect(regex.match(pattern2, "00"))
USING: kernel parser sequences quotations prettyprint fry ; QUALIFIED-WITH: tools.testest tt IN: testest.extras : wrap-it ( quot -- wrapped ) '[ tt:it#{ _ dip tt:}# ] ; : wrap-describe ( quot -- wrapped ) '[ tt:describe#{ _ dip tt:}# ] ; SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it append! ; SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe append! ;
- USING: kernel parser sequences quotations prettyprint fry ;
- QUALIFIED-WITH: tools.testest tt
- IN: testest.extras
- : wrap-it ( quot -- wrapped )
- '[ tt:it#{ _ dip tt:}# ] ;
- : wrap-describe ( quot -- wrapped )
- '[ tt:describe#{ _ dip tt:}# ] ;
SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it suffix! \ call suffix! ;SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe suffix! \ call suffix! ;- SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it append! ;
- SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe append! ;
USING: kernel parser sequences quotations prettyprint fry ;
QUALIFIED-WITH: tools.testest tt
IN: testest.extras
: wrap-it ( quot -- wrapped )
'[ tt:it#{ _ dip tt:}# ] ;
: wrap-describe ( quot -- wrapped )
'[ tt:describe#{ _ dip tt:}# ] ;
SYNTAX: it#{ \ tt:}# parse-until >quotation wrap-it suffix! \ call suffix! ;
SYNTAX: describe#{ \ tt:}# parse-until >quotation wrap-describe suffix! \ call suffix! ;
USING: kernel tools.testest math prettyprint io ;
QUALIFIED-WITH: testest.extras te
IN: testest.tests
: run-tests ( -- )
"Example" te:describe#{
"hello" te:it#{
<{ 1 1 + -> 2 }>
}#
"fail" te:it#{
<{ 1 1 + -> 3 }>
}#
"nested describe" te:describe#{
"pass" te:it#{
<{ 1 1 + -> 2 }>
}#
"fail" te:it#{
! Nothing on the stack
"Nothing on the stack!" print
get-datastack .
<{ 1 1 + -> 3 }>
}#
}#
}#
;
MAIN: run-tests
from time import sleep, time def addition(a, b): start = time() sleep(a) sleep(b) return int(time() - start)
def bit1(cin,a,b):s=cin^a^bcout=(a and b) or (cin and (a^b))return cout,s- from time import sleep, time
- def addition(a, b):
p=32tape_a=[0]*ptape_b=[0]*ptape=[0]*pa=bin(a)[2:]a="".join(("0"*(p-len(a)),a))b=bin(b)[2:]b="".join(("0"*(p-len(b)),b))for i in range(0,p):if a[i]=="0":passelse:tape_a[i]=1for i in range(0,p):if b[i]=="0":passelse:tape_b[i]=1tape_a=tape_a[::-1]tape_b=tape_b[::-1]c=0for i in range(0,p):c,tape[i]=bit1(c,tape_a[i],tape_b[i])tape=tape[::-1]return int("".join(map(lambda a:str(a),tape)),2)- start = time()
- sleep(a)
- sleep(b)
- return int(time() - start)
import codewars_test as test from solution import addition import random # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): for i in range(1): n1, n2 = random.randint(1, 5), random.randint(1, 5) test.assert_equals(addition(n1, n2), sum([n1, n2]))
- import codewars_test as test
- from solution import addition
- import random
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
for i in range(10):n1, n2 = random.randint(1, 121), random.randint(1, 121)- for i in range(1):
- n1, n2 = random.randint(1, 5), random.randint(1, 5)
- test.assert_equals(addition(n1, n2), sum([n1, n2]))