1 — JSON, Design
Due Tuesday, 14 January 2020, 6am
The purpose of this assignment is to get you to know the JSON library of your chosen programming language and to (re-)learn how to apply the program design principles from Fundamentals I and II in this context.
Delivery Deliver your solutions in a folder called 1 in your github repo with the following organization:
Executable means that we can run these programs as ./xcount, ./xreplace, and ./xcontext from the Linux command line. They can thus be bash scripts or Python scripts or whatever runs.
the executables xcount, xreplace, and xcontext as specified in the testing task below.
the directories Count/, Replace/, and Context/ with the integration tests as specified in the testing task below.
the directory Other/, which contains the solutions to the programming tasks including a short README file in case it isn’t obvious how TAs should navigate the directory.
- a Name |
- a JSON array where each element is an St. |
|
A Name is String a non-empty String consisting of just |
lowercase letters. |
Hint In this context JSON plays the role of information and your chosen language will represent this information as data, as determined by the chosen JSON library. You might thus get objects from a class you define or built-in data values.
count, which consumes a data representation of an St in your chosen language and produces the number of Names in the given St.
replace, which consumes a data representation of an St in your chosen language and produces an St with the same array shape where each Name is replaced with its dual. For example, a JSON "a" is replaced with "z", "b" is replaced with "y", and so on.
context, which consumes a data representation of an St in your chosen language and produces a (representation of) T with the same array shape where each Name is replaced with a natural number that represents its nesting depth, i.e., the number of "[ ... ]" that surround it in JSON (though that might be different in the data representation of your chosen language).
Testing Task Write integration test harnesses (or scripts): xcount for count, xreplace for replace, and xcontext for context. Each harness is a batch program; it reads a single JSON St expression from STDIN and prints the result to STDOUT. The test harnesses imports and then use the respective programs from above to perform the computation. You may assume that these harnesses will never applied to anything but instances of St.
Create two tests per program in Count/, Replace/, and Context/, respectively. A test consists of two files: N-in.json and N-out.json for N in {1, 2}.
$ cat Count/1-in.json |
"a" |
$ cat Count/1-out |
1 |
$ ./xcount < Count/1-in.json | diff - Count/1-out.json |
Our test harness will run your executables in a similar way; it will use a comparison function that is appropriate for JSON (though this won’t play a role in this course).
See JSON: Simplicity and Complexity for constraints on the JSON uses in this course.