CMU Coding Bootcamp

fix: update homework with tests

thecoded.prof a13423d7 9eb04529

verified
Changed files
+54 -15
python
-8
python/assignments/sep30/leftoverPizzaSlices.py
··· 1 - def leftoverPizzaSlices(students, slicesPerStudent): 2 - neededSlices = students * slicesPerStudent 3 - nearest8th = (neededSlices + 7) // 8 * 8 4 - return nearest8th - neededSlices 5 - 6 - assert leftoverPizzaSlices(10, 2) == 4 7 - assert leftoverPizzaSlices(15, 3) == 3 8 - assert leftoverPizzaSlices(20, 4) == 0
+8 -3
python/assignments/sep30/numberOfBricks.py
··· 2 2 def numberOfBricks(steps): 3 3 return math.ceil((steps*(steps+1))/2) 4 4 5 - assert numberOfBricks(1) == 1 6 - assert numberOfBricks(3) == 10 7 - assert numberOfBricks(4) == 20 5 + print('Testing numberOfBricks()...', end='') 6 + assert(numberOfBricks(0) == 0) 7 + assert(numberOfBricks(1) == 1) 8 + assert(numberOfBricks(2) == 3) 9 + assert(numberOfBricks(3) == 6) 10 + assert(numberOfBricks(4) == 10) 11 + assert(numberOfBricks(10) == 55) 12 + print('Passed!')
+30
python/assignments/sep30/pizzas.py
··· 1 + def howManyPizzas(students, slicesPerStudent): 2 + neededSlices = students * slicesPerStudent 3 + return (neededSlices + 7) // 8 4 + 5 + def leftoverPizzaSlices(students, slicesPerStudent): 6 + neededSlices = students * slicesPerStudent 7 + nearest8th = howManyPizzas(students, slicesPerStudent) * 8 8 + return nearest8th - neededSlices 9 + 10 + print('Testing howManyPizzas()...', end='') 11 + assert(howManyPizzas(8, 1) == 1) 12 + assert(howManyPizzas(9, 1) == 2) 13 + assert(howManyPizzas(5, 4) == 3) 14 + assert(howManyPizzas(10, 2) == 3) 15 + assert(howManyPizzas(0, 0) == 0) 16 + assert(howManyPizzas(0, 3) == 0) 17 + assert(howManyPizzas(10, 0) == 0) 18 + assert(howManyPizzas(3, 4) == 2) 19 + print('Passed!') 20 + 21 + print('Testing leftoverPizzaSlices()...', end='') 22 + assert(leftoverPizzaSlices(8, 1) == 0) 23 + assert(leftoverPizzaSlices(9, 1) == 7) 24 + assert(leftoverPizzaSlices(5, 4) == 4) 25 + assert(leftoverPizzaSlices(10, 2) == 4) 26 + assert(leftoverPizzaSlices(0, 0) == 0) 27 + assert(leftoverPizzaSlices(0, 3) == 0) 28 + assert(leftoverPizzaSlices(10, 0) == 0) 29 + assert(leftoverPizzaSlices(3, 4) == 4) 30 + print('Passed!')
+16 -4
python/assignments/sep30/pythagoreanTriple.py
··· 1 1 def isPythagoreanTriple(a, b, c): 2 - return (a < b and b < c) and (a**2 + b**2) == c**2 2 + return (a < b and b < c) and ((a**2 + b**2) == c**2) and not (a < 0 or b < 0 or c < 0) 3 3 4 - assert isPythagoreanTriple(3, 4, 5) == True 5 - assert isPythagoreanTriple(5, 4, 3) == False 6 - assert isPythagoreanTriple(5, 12, 13) == True 4 + 5 + print('Testing isPythagoreanTriple()...', end='') 6 + assert(isPythagoreanTriple(3, 4, 5) == True) # 3**2 + 4**2 == 5**2 7 + assert(isPythagoreanTriple(5, 4, 3) == False) # wrong order 8 + assert(isPythagoreanTriple(4, 5, 3) == False) # wrong order 9 + 10 + assert(isPythagoreanTriple(5, 12, 13) == True) # 5**2 + 12**2 == 13**2 11 + assert(isPythagoreanTriple(13, 12, 5) == False) # wrong order 12 + assert(isPythagoreanTriple(12, 13, 5) == False) # wrong order 13 + 14 + assert(isPythagoreanTriple(-3, 4, 5) == False) # no negatives 15 + assert(isPythagoreanTriple( 0, 5, 5) == False) # no 0's 16 + assert(isPythagoreanTriple( 1, 1, 1) == False) # 1**2 + 1**2 != 1**2 17 + assert(isPythagoreanTriple( 3, 4, 6) == False) # 3**2 + 4**2 != 6**2 18 + print('Passed!')