Class summary:   Testing and Plotting Tables
1 Reviewing Testing Row Functions
2 How to Test Functions that Return Tables
3 Plotting Table Data

Class summary: Testing and Plotting Tables

Copyright (c) 2017 Kathi Fisler

1 Reviewing Testing Row Functions

We began with a handout that showed our running gradebook example, along with where blocks for testing the functions that compute values over rows. Several questions about specifics of tables came up and are recorded in the first 20 minutes of lecture capture.

(Note: this posted version is slightly different than what we handed out in class – the difference is in the TESTING section at the bottom, which was not on the printed handout)

2 How to Test Functions that Return Tables

We then discussed how to test functions that return tables. The handout illustrated this using a function that adds exam averages and letter grades to tables. Basically, we showed how we start with a small sample table, then manually created a version of the table with the extra rows, and used those two tables to write a test case for the function.

The printed handout put the testing table (gradebook-extended) before the function and used a where block to capture the test. The version linked here instead puts the table and the test after the function, by using a check block (like where, but it lives outside the function, which can be useful for cases like this where we want to separate our main code from our testing data).

It’s important here that we figure out and write the result table by hand before writing the function body, even though we are placing the testing table under the function in the file. Writing the function first, generating the answer table, and copying it into a hand-developed table defeats the entire purpose of using examples to check that our code is behaving as we wanted it to.

Isn’t this process of setting up test tables annoying and tedious? A bit, yes, but we only write very small tables for this purpose (a few rows), and we can copy and paste to create the result table. The point here is that if we write examples that carefully test the function on the small table, we can then just use the function on the large (google-sheet table) without worrying about whether the table will work.

In short, we’ve begun to make a shift from merely writing examples to testing functions. Testing will get increasingly important as our functions get more complex.

3 Plotting Table Data

Finally, we saw how to use the plotting functions (described in our tables documentation) to create scatter-plots and other plots from table data. These functions are fairly straightforward to use – they generally take a table and the names of the column(s) to use to generate the plots.

Here are some examples of how to create plots:

  # create plot that contrasts students' grades on the two exams

  scatter-plot(gradebook-real, "exam1", "exam2")

  

  # add a linear-regression line to the scatterplot

  # (no worries if you don't know what a linear regression is yet)

  lr-plot(gradebook-real, "exam1", "exam2")

  

  # plot the exam1 grades as bars in decreasing order

  bar-chart(sort-by(gradebook-real, "exam1", false), "name", "exam1")

You’ll get more practice with these in labs and on the project.