Let's continue our work on the machine project! Today we'll begin the next project checkpoint, MP2. We'll install the test suites and begin work on our first test case.
MP2 represents a step up from MP1. Rather than making small changes, we'll be writing larger chunks of code. However! The code we ask you to write will mirror code that we've given you. So you can use our starter code as a guide.
Before you can get to work on MP2 in earnest, we need to install the MP2 test suites. Before we continue, please commit your work.
Since you are using Kotlin, download the MP2 tests here and move the file to the
app/src/test/kotlin/edu/illinois/cs/cs124/ay2021/mp/ directory in your machine project.
For this checkpoint you'll also need to download some new data, and move
preferences.csv to the
app/src/main/resources/ directory in your machine project.
You'll also want to reconfigure
grade.yaml in the root directory of your project to request that we grade Checkpoint 2.
We've completed this steps before, so if you need to review please examine the lessons for MP1.
Like MP1, when we add
MP2Test.kt to our project our code will no longer compile.
This is because the test suite expects us to have created some new methods and classes that don't exist yet.
The task here is a bit more involved than it was for MP1, so let's go over the minimum we need to do to get our code to compile together:
We've provided you with new data about staff restaurant preferences in a file named
Here's the format of the data in the file:
Each line contains multiple
Strings separated by commas.
The first token is an ID that identifies the person.
Subsequent IDs, of which there will be 1 or more, each identify a restaurant in our restaurant data set.
All of the IDs are
Strings called universally-unique identifiers, or UUIDs for short.
UUIDs are a common way of creating unique identifiers to identify a piece of data in a computer program.
You can think of them as sort of like your student ID number—a unique identifier that exists only to uniquely identify some piece of data.
We use them because the other properties of people and restaurants—things like their name—are not guaranteed to be unique.
Your next MP task is to load the CSV data from
preferences.csv and convert it into JSON.
Specifically, given this line in
You should construct the following JSON string:
Before we examine the Android code you need to write today, let's take a minute to discuss how to create JSON objects using Jackson. In particular we'll look at how to create objects that contain arrays, which you'll need to do to complete today's checkpoint.
Note that you may get a deprecation warning in Android Studio when using
put to add an
ArrayNode to an
In this case you can replace the call to
put with a call to
replace, which will also work.
Now let's return to the Android code and discuss how to complete
Note that this method is quite similar to—but not the same as—
So we'll spend time walking through that method in detail, and then discuss any potential differences.
As a reminder, on lessons where we focus on the machine project we will not assign a homework problem! However, the lesson will usually focus on helping you complete a particular part of the MP test suite, and so we encourage you to spend time on that in lieu of a homework problem.
Today your goal should be to
Server.loadPreferencesmethod and convert the
JSONmatching the data shape that the test suites expect.