Esempio n. 1
0
from byotest import assert_equal


def add(x, y):
    return x + y


assert_equal(add(5, 3), 8)
assert_equal(add(2, 4), 6)
assert_equal(add(2, 2), 4)
assert_equal(add(-1, -5), -6)
assert_equal(add(-7, 2), -5)
assert_equal(add(0, 0), 0)
assert_equal(add(65535, 1), 65536)

print("All test pass")

assert add(5, 3) == 8
assert add(2, 4) == 6
assert add(2, 2) == 4
# assert add(2.3,3.4) == 5.7 Float numbers arent as precise and small as we think!
assert add(-1, -5) == -6
assert add(-7, +2) == -5
assert add(0, 0) == 0
assert add(65535, 1) == 65536

print("All test pass")
Esempio n. 2
0
skorea_coins = [500, 100, 50, 10, 5]


def get_change(amount, coins=euro_coins):

    change = []

    for c in coins:
        while c <= amount:
            change.append(c)
            amount = amount - c

    return change


assert_equal(get_change(0), [])

assert_equal(get_change(1), [1])
assert_equal(get_change(2), [2])
assert_equal(get_change(5), [5])
assert_equal(get_change(10), [10])
assert_equal(get_change(20), [20])
assert_equal(get_change(50), [50])
assert_equal(get_change(100), [100])
assert_equal(get_change(200), [200])

assert_equal(get_change(3), [2, 1])
assert_equal(get_change(8), [5, 2, 1])
assert_equal(get_change(76), [50, 20, 5, 1])

assert_equal(get_change(4), [2, 2])
from byotest import assert_equal

usd_coins = [100, 50, 25, 10, 5, 1]
eur_coins = [100, 50, 20, 10, 5, 2, 1]


def get_change(amount, coins=eur_coins):
    change = []
    for coin in coins:
        while coin <= amount:
            amount -= coin
            change.append(coin)

    return change

assert_equal(get_change(0), [])
assert_equal(get_change(1), [1])
assert_equal(get_change(2), [2])
assert_equal(get_change(5), [5])
assert_equal(get_change(10), [10])
assert_equal(get_change(20), [20])
assert_equal(get_change(50), [50])
assert_equal(get_change(100), [100])

assert_equal(get_change(3), [2, 1])
assert_equal(get_change(7), [5, 2])
assert_equal(get_change(9), [5, 2, 2])

assert_equal(get_change(35), [20, 10, 5])
assert_equal(get_change(35, usd_coins), [25, 10])
Esempio n. 4
0
from byotest import assert_equal

# This function counts the number of uppercase letters in a string.
# def foo(text):
#     count = 0
#     for c in text:
#         if c.isupper():
#             count += 1
#     return count


# List comprehension
def foo(text):
    return len([c for c in text if c.isupper()])


# print(foo("Hello"))

assert_equal(foo(""), 0)
assert_equal(foo("Hello"), 1)
assert_equal(foo("HeLlo"), 2)

print("All tests pass")
Esempio n. 5
0
from byotest import assert_equal


def foo2(text):

    return (len([c for c in text if c.isupper()]))


assert_equal(foo2("LoooL"), 2)
assert_equal(foo2(""), 0)
assert_equal(foo2(""), 0)

print("All test pass")