test.assert_equals(AmIYelling("HELLO"),True) test.assert_equals(AmIYelling("YES IM STILL YELLING"),True) test.assert_equals(AmIYelling("No Im not yelling"),False) test.assert_equals(AmIYelling("neither now"),False) test.assert_equals(AmIYelling("BUT I AM NOW!!!!"),True) test.assert_equals(AmIYelling("1234"),True) test.assert_equals(AmIYelling("1234!!"),True)
- test.assert_equals(AmIYelling("HELLO"),True)
- test.assert_equals(AmIYelling("YES IM STILL YELLING"),True)
- test.assert_equals(AmIYelling("No Im not yelling"),False)
- test.assert_equals(AmIYelling("neither now"),False)
- test.assert_equals(AmIYelling("BUT I AM NOW!!!!"),True)
test.assert_equals(AmIYelling("1234"),True)- test.assert_equals(AmIYelling("1234"),True)
- test.assert_equals(AmIYelling("1234!!"),True)
Alternative using lists utilizing previous idea of reversion to avoid sorting. Missing test for number with integer square root added.
from math import sqrt def divisors(n): fa = [i for i in range(1, int(sqrt(n)) + 1) if not (n%i)] fa.extend([n//i for i in reversed(fa) if n//i > i]) return fa
- from math import sqrt
- def divisors(n):
fa={i for i in range(1,int(sqrt(n)) + 1) if not(n%i)}ct={n//i for i in fa}return sorted(fa|ct)- fa = [i for i in range(1, int(sqrt(n)) + 1) if not (n%i)]
- fa.extend([n//i for i in reversed(fa) if n//i > i])
- return fa
from math import sqrt, floor def divisors_check(n): fact = []; for i in range(1, int(floor(sqrt(n))) + 1): if not(n % i): fact.append(i) if n / i != i: fact.append(n / i) fact.sort() return fact test.describe( "Static Cases" ) test.it( "n = 4" ) test.assert_equals(divisors(4), [1, 2, 4], 'Naive concatenation of lo [1,2] and high [2,4] factors will produce duplicity [1,2,2,4]') test.it( "n = 200" ) test.assert_equals(divisors(200), [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 200]) test.it( "n = 560") test.assert_equals(divisors(560), [1, 2, 4, 5, 7, 8, 10, 14, 16, 20, 28, 35, 40, 56, 70, 80, 112, 140, 280, 560]) test.it("n = 755") test.assert_equals(divisors(755), [1, 5, 151, 755]) from random import randint test.describe( "Random Tests") test.it ("More than 1000 Random Tests with challenging values up to 1000000000(10e9)") for h in range(0,1000): n = randint(1000, 1000000000) result = divisors_check(n) res = divisors(n) test.it("Testing for = " + str(n)) test.assert_equals(res, result)
- from math import sqrt, floor
- def divisors_check(n):
- fact = [];
- for i in range(1, int(floor(sqrt(n))) + 1):
- if not(n % i):
- fact.append(i)
- if n / i != i:
- fact.append(n / i)
- fact.sort()
- return fact
- test.describe( "Static Cases" )
- test.it( "n = 4" )
- test.assert_equals(divisors(4), [1, 2, 4], 'Naive concatenation of lo [1,2] and high [2,4] factors will produce duplicity [1,2,2,4]')
- test.it( "n = 200" )
- test.assert_equals(divisors(200), [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 200])
- test.it( "n = 560")
- test.assert_equals(divisors(560), [1, 2, 4, 5, 7, 8, 10, 14, 16, 20, 28, 35, 40, 56, 70, 80, 112, 140, 280, 560])
- test.it("n = 755")
- test.assert_equals(divisors(755), [1, 5, 151, 755])
- from random import randint
- test.describe( "Random Tests")
- test.it ("More than 1000 Random Tests with challenging values up to 1000000000(10e9)")
- for h in range(0,1000):
- n = randint(1000, 1000000000)
- result = divisors_check(n)
- res = divisors(n)
- test.it("Testing for = " + str(n))
- test.assert_equals(res, result)
def square(n): result = (("*" *n+"\n")*n)[:-1] print(result) # ...write a function that prints... return result # result to be tested
- def square(n):
print(("*" *n+"")*n) # to see the resultreturn (("*" *n+"\n")*n)[:-1]- result = (("*" *n+"
- ")*n)[:-1]
- print(result) # ...write a function that prints...
- return result # result to be tested
# TODO: Given a number n, write a function that prints a square of '*' having side n # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings #test.it('Basic tests') test.assert_equals(square(2),'**\n**') test.assert_equals(square(5),'*****\n*****\n*****\n*****\n*****') test.assert_equals(square(4),'****\n****\n****\n****') test.assert_equals(square(0),'')
# TODO: Given a number, write a function that prints a square with the caracter '*'- # TODO: Given a number n, write a function that prints a square of '*' having side n
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
- # You can use Test.describe and Test.it to write BDD style test groupings
# test.assert_equals(square(2),['**', '**'])# test.assert_equals(square(3),['***', '***', '***'])# test.assert_equals(square(4),['****', '****', '****', '****'])# test.assert_equals(square(5),['*****', '*****', '*****', '*****', '*****'])test.assert_equals(square(2),"****")- #test.it('Basic tests')
- test.assert_equals(square(2),'**
- **')
- test.assert_equals(square(5),'*****\n*****\n*****\n*****\n*****')
- test.assert_equals(square(4),'****\n****\n****\n****')
- test.assert_equals(square(0),'')
Numbers
Data Types
def kilogramsToGrams(kilograms=1): return kilograms * 1000
def kilogramsToGrams(kilograms):- def kilogramsToGrams(kilograms=1):
- return kilograms * 1000
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings test.assert_equals(kilogramsToGrams(1), 1000) test.assert_equals(kilogramsToGrams(1.365), 1365) kilograms = 0.126 grams = 126 test.assert_equals(kilograms*kilogramsToGrams(), grams)
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
- # You can use Test.describe and Test.it to write BDD style test groupings
- test.assert_equals(kilogramsToGrams(1), 1000)
test.assert_equals(kilogramsToGrams(1.365), 1365)- test.assert_equals(kilogramsToGrams(1.365), 1365)
- kilograms = 0.126
- grams = 126
- test.assert_equals(kilograms*kilogramsToGrams(), grams)