8.3.0.1

3 — The Image

Due Wednesday, 13 October 2021, 11:59:59pm

Delivery Use the Trains directory in your repository to deposit the products of this week’s milestone:

Since Python’s naming system is badly designed and its convention interfere with the specified name, Pythonistas may substitute _ for - in these file names.

Keep in mind our Trains.Com, a Plan when you work on designs.

Programming Task Your programming task is to implement a map visualizer.

The visualizer should consume a data representation of a map and display the map.

Here are some basic constraints on the map and its elements:
  • the map’s Width and Height are natural numbers in [10, 800] and [10, 800], respectively, and denote numbers of pixels

  • as a string, a city’s Name satisfies the regular expression "[a-zA-Z0-9\\ \\.\\,]+" [i.e., all letters of the English alphabet, all digits, plus space, dot, and comma] and has at most 25 ASCII characters.

Each connection between two cities must be visualized clearly and separately, including its color and length attributes.

Completely, Totally, Optional Fun Turn the visualizer into a map editor so you can visually design your railroad maps. The ideal map editor consumes and produces a data representation of a map. You may wish to use it for creating test cases, but it is easily possible to write down interesting test cases manually.

Design Task The referee and the players agree on a single map for the duration of the game. Using the map, the players select their destinations before they play actual turns. As the game evolves, different players acquire different connections and pick up different colored cards. The referee and the player must keep track of what they know about these changes:
  • The referee must should use this knowledge to check the legality of actions.

  • A player may use this knowledge to decide on which actions to take or plan ahead.

Hence both referees and players will need to work with a data representation of the current state of the game.

Design data representations for the state of the game for both referees and players. If you think identical representations are appropriate, explain so in your memo.

To describe the data representation, mix English and references to the data sub-language of your chosen programming language. For the operations, choose the wish list format that you got to know in Fundamentals I and Fundamentals II, depending on which of the languages used in these courses matches your chosen language most closely. Distinguish the two parts clearly.

The memo should not exceed two pages. Less is more.

Keep in mind our Trains.Com, a Plan when you work on designs.

Testing Task Create a test harness named xmap. The harness consumes its JSON input from STDIN and produces its results to STDOUT. Create three tests and place them in the specified folder.

A test case always consists of given inputs and expected outputs. For this course, a test consists of a pair of files: n-in.json, the input file, and n-out.json, the expected output file, where n is an integer between 1 and the requested number of tests.

Constraint No test file may exceed the size limit of 20Kb.

Its inputs consists of three JSON values: two Strings and a Map object. The two strings are Names of cities, and these cities must be on the Map.

The expected outputs is a Boolean, indicating whether the two give cities are connected form a destination or not.

Here are the relevant JSON specifications:

    Map is

      { "width"        : Width,

        "height"       : Height,

        "cities"       : [City,..,City],

        "connections"  : Connection Connections }

    

     TESTING CONSTRAINT For testing purposes, a Map should consist of at

       most 20 cities and 40 connections.

    

     INTERPRETATION specifies the logical and visual layout of a game map

    

    A City is [Name, [X, Y]] where X is a natural number

     in [0,W] and Y is a natural number in [0,H] with W and H as specified

     in the map object's "width" and "height" fields, respectively.

    

     CONSTRAINT No two cities may have the same name or occupy the same spot.

    

     INTERPRETATION specifies a city's name and location on the map

    

    A Connection Connections is an object whose domain elements are Names

     and whose range elements are Targets.

    

     CONSTRAINT Every Name must be a member of the Names in the "cities" field.

      The domain name must be string<? to the range's name.

    

     INTERPRETATION specifies from where connection originates (domain),

      to where they go and the nature of the connection (range)

    

    A Target is an object whose domain elements are Names

     and whose range elements are Segments.

    

     CONSTRAINT Every Name must be a member of the Names in the "cities" field.

      The domain name must be string<? to the range's name.

    

     INTERPRETATION specifies where a connection goes (domain)

      and their nature (range)

    

    A Segment is an object whose domain elements are Colors

     and whose range elements are Lengths.

    

     CONSTRAINT The Colors must be pairwise distinct.

    

     INTERPRETATION specifies the color and length of a connection

Pedagogy The design of a networked system should keep the number of messages small (in favor of large messages), and yet it should also ensure that messages are not overly large. This constraint creates a situation where you see this idea in practice. While the denotation of Map is an undirected graph, the "connections" field is constrained to specify each connection between two cities only once.

Hint This textual interchange representation enforces game-centric constraints on the map, but it is not intended to be identical to your data representation (and it is certainly not the one used for the oracle implementation).

Well-formed and Valid For now, you may assume that all inputs to your test harnesses will be well-formed and valid JSON.. As a reminder, a well-formed piece of JSON satisfies the grammar of JSON; such a piece is valid if it also satisfies all the constraints of the above specification. For example, ["Washington, D.C.", [700,-2]] is a well-formed piece of JSON but an invalid City. ["Washington, D.C.", [200,600]] is both well-formed and valid.

Beyond integeration testing, we should eventually move to stress testing. The course will touch on this idea in November or December.

Pedagogy Besides unit tests, multi-component projects also need integration tests. Such tests compose several components and run tests on the composite that exercise functions across the components. This task is a lightweight illustration of this idea.

When a milestone assignment requests an integration test harnesses, you should not have to modify the core functionality from the previous milestone—other than the addition of code for (de)serialization between your chosen data representation and JSON; see Trains.Com, a Plan.