3. Testing

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

3.1. Pre Lab Exercises

  1. Chapter 2 exercise(s)

    • 5 but have it in a function that returns the result

    • Also write assertion tests for the function, include type hints, and write a docstring

  2. Chapter 4 exercise(s)

    • 8 but write assertion tests for the function, include type hints, and write a docstring

3.2. Before Kattis

  1. Write a function to calculate the density of an object

    • \(d = \frac{m}{V}\)

    • The function will have the mass and volume of the object as parameters

    • The function will return the density

    • Write an effective docstring for this function

    • Include type hints for this function

    • Write assertion tests for this function

  2. Write a function to calculate acceleration

    • \(a = \frac{\Delta v}{t}\)

    • The function will have the starting velocity, ending velocity, and time as parameters

    • The function will return the acceleration

    • Write an effective docstring for this function

    • Include type hints for this function

    • Write assertion tests for this function

  3. Write a function to convert latitudes/longitudes from degrees, minutes, and seconds to a decimal value of a degree

    • \(1 minute = \frac{1}{60} degrees\)

    • \(1 second = \frac{1}{60} minute = \frac{1}{3600} degrees\)

    • Wikipedia explains this in more detail

    • This function will have the degrees, minutes, and seconds as parameters

    • This function will return the latitude/longitude value as degrees with a decimal

    • Write an effective docstring for this function

    • Include type hints for this function

    • Write assertion tests for this function

3.3. Kattis Problems

  • Do not forget the code we used last time to read input on Kattis

1data = input()       # Read a WHOLE, SINGLE line of input
2data = data.split()  # Split string into individual pieces
3a_var = int(data[0]) # Take string from data[X], convert it to int...
4b_var = int(data[1]) # ... And store it in some variable

Warning

The above code will only work when the input is 2 integers on the same line. You may need to hack this code to make it work for your particular problem.

  • Skip any of the following problems if you did them already.

  • Although not necessary, for practice, write each solution in a function with docstrings, s, and assertion tests

  1. https://open.kattis.com/problems/hello

  2. https://open.kattis.com/problems/carrots

  3. https://open.kattis.com/problems/r2

  4. https://open.kattis.com/problems/faktor

  5. https://open.kattis.com/problems/ladder

  6. https://open.kattis.com/problems/planina

  7. https://open.kattis.com/problems/leggjasaman

  8. https://open.kattis.com/problems/metronome

  9. https://open.kattis.com/problems/ovissa

  10. https://open.kattis.com/problems/fifa

  11. https://open.kattis.com/problems/vidsnuningur