Ejemplo n.º 1
0
 def setUp(self):
     namespace = dict(__file__=__file__)
     with codewars.Test(namespace=namespace) as test:
         test.describe('a dummy test case')
         test.it('should works')
         test.assert_equals(1 + 1, 2, '1 + 1 = 2')
         test.assert_not_equals(2 ** 3, 6, '2 ^ 3 != 6')
         test.expect(not False, 'passed')
         test.expect_error('Just raise', raise_something)
         self.expect_pass = test.translated
     with codewars.Test(namespace=namespace) as test:
         test.assert_equals(1, 2)
         self.expect_fail_equal = test.translated
     with codewars.Test(namespace=namespace) as test:
         test.assert_not_equals(1, 1)
         self.expect_fail_not_equal = test.translated
     with codewars.Test(namespace=namespace) as test:
         test.expect_error('', raise_nothing)
         self.expect_fail_error = test.translated
     with codewars.Test(namespace=namespace) as test:
         test.expect(False)
         self.expect_fail_pass = test.translated
     self.stream = io.StringIO()
     self.runner = unittest.TextTestRunner(stream=self.stream)
Ejemplo n.º 2
0
# encoding: UTF-8
"""
https://www.codewars.com/kata/scramblies
"""

import codewars


def encode(string):
    counting = [0] * 26
    offset = ord('a')
    for char in string:
        counting[ord(char) - offset] += 1
    return counting


def scramble(s1, s2):
    c1, c2 = encode(s1), encode(s2)
    return all(x >= y for x, y in zip(c1, c2))


with codewars.Test(namespace=globals()) as Test:
    Test.assert_equals(scramble('rkqodlw', 'world'), True)
    Test.assert_equals(scramble('cedewaraaossoqqyt', 'codewars'), True)
    Test.assert_equals(scramble('katas', 'steak'), False)
    Test.assert_equals(scramble('scriptjava', 'javascript'), True)
    Test.assert_equals(scramble('scriptingjava', 'javascript'), True)