Exemplo n.º 1
0
 def test_pyramid_array(self):
     assert_true(pyramid(0), [])
     assert_true(pyramid(1), [[1]])
     assert_true(pyramid(2), [[1], [1, 1]])
     assert_true(pyramid(3), [[1], [1, 1], [1, 1, 1]])
Exemplo n.º 2
0
 def test_roman_numerals_decoder(self):
     assert_true(solution('XXI'), 21)
     assert_true(solution('I'), 1)
     assert_true(solution('IV'), 4)
     assert_true(solution('MMVIII'), 2008)
     assert_true(solution('MDCLXVI'), 1666)
Exemplo n.º 3
0
 def test_flatten_kata(self):
     assert_true(flatten([[1], [[8]]]), [1, 8])
     assert_true(flatten([[1, 2, 3]]), [1, 2, 3])
     assert_true(flatten(), [])
     assert_true(flatten(1, 2, 3), [1, 2, 3])
     assert_true(flatten([1, 2], [3, 4, 5], [6, [7], [[8]]]), [1, 2, 3, 4, 5, 6, 7, 8])
     assert_true(flatten(1, 2, ['9', [], []], None), [1, 2, '9', None])
     assert_true(flatten(['hello', 2, ['text', [4, 5]]], [[]], '[list]'), ['hello', 2, 'text', 4, 5, '[list]'])
Exemplo n.º 4
0
 def test_list_filtering(self):
     assert_true(filter_list([1, 2, 'a', 'b']), [1, 2])
Exemplo n.º 5
0
 def test_persistent_burger(self):
     assert_true(persistence(39), 3)
Exemplo n.º 6
0
 def test_permutations(self):
     assert_true(smash(['hello', 'world']), 'hello world')
Exemplo n.º 7
0
 def test_online_rpg(self):
     assert_true(playerRankUp(64), False)
     assert_true(
         playerRankUp(180),
         'Well done! You have advanced to the qualifying stage. Win 2 out of your next 3 games to rank up.'
     )
Exemplo n.º 8
0
    def test_phone_directory(self):
        dr = ("/+1-541-754-3010 156 Alphand_St. <J Steeve>\n 133, Green, Rd. <E Kustur> NY-56423 ;+1-541-914-3010;\n"
              "+1-541-984-3012 <P Reed> /PO Box 530; Pollocksville, NC-28573\n :+1-321-512-2222 <Paul Dive> Sequoia Alley PQ-67209\n"
              "+1-741-984-3090 <Peter Reedgrave> _Chicago\n :+1-921-333-2222 <Anna Stevens> Haramburu_Street AA-67209\n"
              "+1-111-544-8973 <Peter Pan> LA\n +1-921-512-2222 <Wilfrid Stevens> Wild Street AA-67209\n"
              "<Peter Gone> LA ?+1-121-544-8974 \n <R Steell> Quora Street AB-47209 +1-481-512-2222!\n"
              "<Arthur Clarke> San Antonio $+1-121-504-8974 TT-45120\n <Ray Chandler> Teliman Pk. !+1-681-512-2222! AB-47209,\n"
              "<Sophia Loren> +1-421-674-8974 Bern TP-46017\n <Peter O'Brien> High Street +1-908-512-2222; CC-47209\n"
              "<Anastasia> +48-421-674-8974 Via Quirinal Roma\n <P Salinger> Main Street, +1-098-512-2222, Denver\n"
              "<C Powel> *+19-421-674-8974 Chateau des Fosses Strasbourg F-68000\n <Bernard Deltheil> +1-498-512-2222; Mount Av.  Eldorado\n"
              "+1-099-500-8000 <Peter Crush> Labrador Bd.\n +1-931-512-4855 <William Saurin> Bison Street CQ-23071\n"
              "<P Salinge> Main Street, +1-098-512-2222, Denve\n")

        assert_true(phone(dr, "48-421-674-8974"),
                    "Phone => 48-421-674-8974, Name => Anastasia, Address => Via Quirinal Roma")
        assert_true(phone(dr, "1-921-512-2222"),
                    "Phone => 1-921-512-2222, Name => Wilfrid Stevens, Address => Wild Street AA-67209")
        assert_true(phone(dr, "1-908-512-2222"),
                    "Phone => 1-908-512-2222, Name => Peter O'Brien, Address => High Street CC-47209")
        assert_true(phone(dr, "1-541-754-3010"),
                    "Phone => 1-541-754-3010, Name => J Steeve, Address => 156 Alphand St.")
        assert_true(phone(dr, "1-121-504-8974"),
                    "Phone => 1-121-504-8974, Name => Arthur Clarke, Address => San Antonio TT-45120")
        assert_true(phone(dr, "1-498-512-2222"),
                    "Phone => 1-498-512-2222, Name => Bernard Deltheil, Address => Mount Av. Eldorado")
        assert_true(phone(dr, "1-098-512-2222"), "Error => Too many people: 1-098-512-2222")
        assert_true(phone(dr, "5-555-555-5555"), "Error => Not found: 5-555-555-5555")
Exemplo n.º 9
0
 def test_vowel_recognition(self):
     assert_true(vowel_recognition("baceb"), 16)
     assert_true(vowel_recognition("aeiouAEIOU"), 220)
Exemplo n.º 10
0
 def test_pizza_pieces(self):
     assert_true(max_pizza(3), 7)
     assert_true(max_pizza(4), 11)
Exemplo n.º 11
0
 def test_build_a_pile_of_cubes(self):
     assert_true(find_nb(4183059834009), 2022)
     assert_true(find_nb(24723578342962), -1)
Exemplo n.º 12
0
 def test_return_negative(self):
     assert_true(make_negative(42), -42)
Exemplo n.º 13
0
 def test_regular_ball_super_ball(self):
     assert_true(Ball().ball_type, "regular")
     assert_true(Ball("super").ball_type, "super")
Exemplo n.º 14
0
 def test_highest_and_lowest(self):
     assert_true(high_and_low("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6"),
                 "542 -214")
Exemplo n.º 15
0
 def test_build_the_tower(self):
     assert_true(tower_builder(1), [
         '*',
     ])
     assert_true(tower_builder(3), ['  *  ', ' *** ', '*****'])
Exemplo n.º 16
0
 def test_number_zoo_patrol(self):
     assert_true(find_missing_number([2, 3, 4]), 1)
     assert_true(find_missing_number([1, 2, 3]), 4)
     assert_true(find_missing_number([1, 2, 4]), 3)
Exemplo n.º 17
0
 def test_basic_subclasses(self):
     paradise = God()
     assert_true(isinstance(paradise[0], Man), True)
Exemplo n.º 18
0
 def test_disarium_number(self):
     assert_true(disarium_number(89), "Disarium !!")
     assert_true(disarium_number(518), "Disarium !!")
     assert_true(disarium_number(1024), "Not !!")
Exemplo n.º 19
0
 def test_name_your_python(self):
     bubba = Python('Bubba')
     assert_true(bubba.name, 'Bubba')
Exemplo n.º 20
0
 def test_decode_the_morse_code(self):
     assert_true(decodeMorse('.... . -.--   .--- ..- -.. .'), 'HEY JUDE')
     assert_true(decodeMorse('...---...'), 'SOS')
     assert_true(decodeMorse('  E E '), 'E E')
    def test_error_correction_1_hamming_code(self):
        assert_true(encode('4z'), '000000111111000111000000000111111111111000111000')
        assert_true(encode("hey"), "000111111000111000000000000111111000000111000111000111111111111000000111")
        assert_true(encode("The Sensei told me that i can do this kata"), "000111000111000111000000000111111000111000000000000111111000000111000111000000111000000000000000000111000111000000111111000111111000000111000111000111111000111111111000000111111111000000111111000111111000000111000111000111111000111000000111000000111000000000000000000111111111000111000000000111111000111111111111000111111000111111000000000111111000000111000000000000111000000000000000000111111000111111000111000111111000000111000111000000111000000000000000000111111111000111000000000111111000111000000000000111111000000000000111000111111111000111000000000000111000000000000000000111111000111000000111000000111000000000000000000111111000000000111111000111111000000000000111000111111000111111111000000000111000000000000000000111111000000111000000000111111000111111111111000000111000000000000000000111111111000111000000000111111000111000000000000111111000111000000111000111111111000000111111000000111000000000000000000111111000111000111111000111111000000000000111000111111111000111000000000111111000000000000111")
        assert_true(encode("T3st"), "000111000111000111000000000000111111000000111111000111111111000000111111000111111111000111000000")

        assert_true(decode("100111111000111001000010000111111000000111001111000111110110111000010111"), "hey")
        assert_true(decode("000111000111000111000100000111111000111000001000000111111000010111000111000100111000000000000100000111000111000000111111000111111000000111000111000111111000111111111000000111111111000000111111000110111000000111000111000111111000111000000111000000111000000000000000000111111111000111000000000111111000111111111111000111111000111111000000000111111000000111000001000000111000000000001000000111111000111111000111000111111000000111000111000000111000000000000000000111111111000111000000000111111000111000000000000111111000000010000111000111111111000111000000000100111000000000000000000111111000111000000111000000111000000000000000000111111000000000111111000111111000000000000111000111111000111111111000000000111000000000000010000111111000000111000000000111111000111111110111000000111000000000000000000111111111000111000000000111111000111000000000000111111000111000000111000111111111000000111111000000111000000000000000000111111000111000111111000111111000000000000111000111111111000111000000000111111000000000000111"), "The Sensei told me that i can do this kata")
        assert_true(decode("000111000111000111000010000000111111000000111111000111111111000000111111000111111111000111010000"), "T3st")
        assert_true(decode("000111000111000111000001000000111111110111111111000111111111000000111111000111111111000111000000000000111000000000000111000000111000000111000111"), "T?st!%")
        assert_true(decode('000000111111000111000000000111111111111000111000'), '4z')
Exemplo n.º 22
0
 def test_counting_duplicates(self):
     assert_true(duplicate_count('abcdea'), 1)
     assert_true(duplicate_count('abcdeaB'), 2)
Exemplo n.º 23
0
 def test_prefill_an_array(self):
     assert_true(prefill(3, 1), [1, 1, 1])
     assert_true(prefill(2, 'abc'), ['abc', 'abc'])
 def test_does_my_number_look_big_in_this(self):
     assert_true(narcissistic(371), True)
Exemplo n.º 25
0
 def test_weight_for_weight(self):
     # assert_true(order_weight("103 123 4444 99 2000"), "2000 103 123 4444 99")
     assert_true(order_weight("2000 10003 1234000 44444444 9999 11 11 22 123"),
                 "11 11 2000 10003 22 123 1234000 44444444 9999")
Exemplo n.º 26
0
# It's pretty straightforward.
# Your goal is to create a function that removes the first and last characters of a string.
# You're given one parameter, the original string.
# You don't have to worry with strings with less than two characters.
from asserts.Asserts import assert_true


def remove_char(s):
    return s[1:-1]


assert_true(remove_char('eloquent'), 'loquen')
assert_true(remove_char('ok'), '')
Exemplo n.º 27
0
 def test_take_a_ten_minute_walk(self):
     assert_true(isValidWalk('nws'), False)
Exemplo n.º 28
0
 def test_round_and_round(self):
     assert_true(round_by_2_decimal_places(Decimal('2')), Decimal('2'))
     assert_true(round_by_2_decimal_places(Decimal('7.477')),
                 Decimal('7.48'))
     assert_true(round_by_2_decimal_places(Decimal('-4.999')),
                 Decimal('-5'))
     assert_true(round_by_2_decimal_places(Decimal('18.123')),
                 Decimal('18.12'))
     assert_true(round_by_2_decimal_places(Decimal('0')), Decimal('0'))
     assert_true(round_by_2_decimal_places(Decimal('1.455')),
                 Decimal('1.46'))
     assert_true(round_by_2_decimal_places(Decimal('-1.455')),
                 Decimal('-1.46'))
     assert_true(round_by_2_decimal_places(Decimal('1.055')),
                 Decimal('1.06'))
     assert_true(round_by_2_decimal_places(Decimal('-1.055')),
                 Decimal('-1.06'))
     assert_true(round_by_2_decimal_places(Decimal('16.765')),
                 Decimal('16.77'))
     assert_true(round_by_2_decimal_places(Decimal('-16.765')),
                 Decimal('-16.77'))
     assert_true(round_by_2_decimal_places(Decimal('1.025')),
                 Decimal('1.03'))
     assert_true(round_by_2_decimal_places(Decimal('-1.025')),
                 Decimal('-1.03'))
     assert_true(round_by_2_decimal_places(Decimal('16.355')),
                 Decimal('16.36'))
     assert_true(round_by_2_decimal_places(Decimal('-16.345')),
                 Decimal('-16.35'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('-1.1949999999999999999999999999')), Decimal('-1.19'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('-1.1950000000000000000000000001')), Decimal('-1.2'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('1.1949999999999999999999999999')), Decimal('1.19'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('1.1950000000000000000000000001')), Decimal('1.2'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('-1.1849999999999999999999999999')), Decimal('-1.18'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('-1.1850000000000000000000000001')), Decimal('-1.19'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('1.1849999999999999999999999999')), Decimal('1.18'))
     assert_true(
         round_by_2_decimal_places(
             Decimal('1.1850000000000000000000000001')), Decimal('1.19'))
Exemplo n.º 29
0
 def test_grasshopper_terminal_game(self):
     assert_true(move(0, 4), 8)
     assert_true(move(3, 6), 15)
     assert_true(move(2, 5), 12)
Exemplo n.º 30
0
 def test_printer_errors(self):
     assert_true(
         printer_error(
             "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmxyz"),
         "3/56")
     assert_true(printer_error("aaaxbbbbyyhwawiwjjjwwm"), '8/22')