CS 4530/CS 5500 Homeworks

Homework 0

Out: Immediately
Due: Friday, 18 September 2020 (AoE)

The main purpose of this problem set is to give you an opportunity to learn how to write simple programs in the TypeScript language and ecosystem.

This is an individual assignment, but you may seek help about installing and using the TypeScript toolset, or about the TypeScript language itself. See the section on getting help on the course description web page.


Revision History

Building Your TypeScript Environment

Visual Studio Code will be the required IDE for this course. VSC is an excellent code editor. It includes on-the-fly syntax highlighting, autocompletion, and error highlighting, and is available for Windows, macOS, and Linux. If you have not used VSC before, watch one or more of the official Getting Started videos.

If you are using Windows, in Settings, go to "Choose Default Apps by File Type" and associate .ts files with VSC.

VSC includes a git integration. You will not need to use git for this assignment, but you will need it for later assignments and for the project. In the unlikely event that you have not used git before, you will need to learn git, since it is required for this course. There are many tutorials out there; we will put up our own a little later in the semester.

If you have not used node.js before, you may need to install it, and you may wish to learn about the node package manager, npm.

Building a Package in TypeScript

For this homework, we have provided a very simple framework to help you build your package. To set up a package, do the following:
  1. Create the folder for your package.
  2. Copy the attached zip file, and unpack it into your folder. After unpacking, your folder should now have a src/ folder, package.json and tsconfig.json files in it.
  3. Edit the package.json file to add the correct project name and author name.
  4. Open up a shell in the folder, and say npm install. You can do this in VSC (the default key is C-~ or C-`). The installation may take a minute or two, depending on your internet connection. After installation, your folder should now have a node_modules folder in it, and a package-lock.json file in it.
  5. Open your newly created project in VSC: from VSC, go to File->Open, and select the folder that you just created (the one that contains package.json).
  6. Write your source files using VSC, and put them in the src/ folder within your assignment. Typescript files use the .ts extension. Your unit tests for foo.ts should be named foo.spec.ts and are kept in the src directory.
  7. To run your tests, open up a shell and say 'npm test'. This will compile your source files and run all the tests in src/*.spec.ts .

Problem Specification: Space Invaders

Earth is being invaded by martians. Here's a description of the Martian fleet:

  1. The Martians have some Spaceships.
  2. Each Spaceship is either a mother ship or a drone.
  3. A mother ship has a name, which is a string, a crew, which is a list of Martians, and a possibly-empty set of daughter ships, each of which is a spaceship (note that a mothership may itself be a daughter ship of another mother ship).
  4. A drone has no attributes.
  5. A Martian has a name, which is a string, and some other attributes, which are unspecified.

Note: When we say the fleet of a spaceship, we mean her daughter ships and all their fleets.

Your task is to build a TypeScript module that exports the following:

  1. Types Spaceship and Martian.
  2. Utility functions:
    • droneFactory: () -> Spaceship that creates a new drone
    • mothershipFactory: (name: string, crew: Martian[], daughterShips?: Spaceship[]) -> Spaceship that creates a new mother ship
    • martianFactory: (name: string) -> Martian that creates a new Martian
    • getDaughterShips: (ship:Spaceship) -> Spaceship[] that returns the daughter ships of a ship. If the ship is a drone, this function should return an empty array.
  3. A function hasMork: (ship:Spaceship) -> boolean that returns true if and only if the spaceship has a Martian named "Mork" in its crew.
  4. A function totalMorks: (ship:Spaceship) -> number that returns the total number of Martians named "Mork" that are in the crews of either the spaceship or its fleet
  5. A function shipWithoutDrones : (ship:Spaceship) -> Spaceship that returns another spaceship just like the original, except that all of its daughters that are drones have been removed. If the ship specified is not a mother ship, this function should return undefined.
  6. A function shipWithoutDeepDrones : (ship:Spaceship) -> Spaceship that returns another spaceship just like the original, except that all of the drones in its fleet have been removed. If the ship specified is not a mother ship, this function should return undefined.
  7. A function shipWithoutDeepMorks : (ship:Spaceship) -> Spaceship that returns another spaceship just like the original, except that every ship in its fleet who has a crewmember named "Mork" has been removed. When a ship is removed from the fleet, so are all its daughters and their fleets. If the ship initially specified as the parameter to this function contains Mork, this function should return undefined.
  8. A function shipWithoutMorksButPromoteTheirDaughters : (ship:Spaceship) -> Spaceship that returns another ship just like the original, except that all of its daughters who have a crewmember named "Mork" have been removed. However, when a daughter is removed from the fleet, each of its daughters (a grand-daughter of the given spaceship) are promoted to become a daughter of the given spaceship, even if it has a Mork in its crew. Note that this function ONLY checks the daughter ships of the ship specified (not the entire fleet). If the ship initially specified as the parameter to this function contains Mork, this function should return undefined.

Your task also includes writing unit tests for these functions.

Put your solution in a file called index.ts and your unit tests in a file called index.spec.ts, both in the src folder. These two files should contain your entire submission.

To get you started, the zip file we gave you contains sample files src/index.ts and src/index.spec.ts . Pay special attention to the examples in the sample index.spec.ts . These examples not only show the format of a typical test file, but they also illustrate some important properties of the TypeScript language that you might skip over as you read.

Questions

Please post all questions on Piazza.

Grading

Your assignment will be graded on a series of automated functional tests, making sure that it implements the specification above, and it will also be inspected manually for general coding conventions and correctness. This assignment will be graded on a very lenient "pass/fail" basis and will not directly contribute to your course grade.

In accordance with the "reasonable person principle," we reserve the right to audit your code and correct any marks that are improperly assigned by the automated functional test suite, for instance, due to your code incorrectly following the specification, but passing the test. We would encourage you to spend your time correctly implementing the assignment, and not trying to force it to pass the test, even if it is not following the spirit of the assignment.

Submitting Your Solution

Submit your solution using Gradescope. To create your account on Gradescope, you should click "Login with school credentials," select "myNortheastern Username," and log in. After logging in, select "Enroll in course" and use entry code 95B8E2. Within Gradescope, upload your index.ts and index.spec.ts to Gradescope. Please note that your submisison should not print anything to console.log. After you submit your assignment, Gradescope will automatically compile your code and run our suite of automated tests. You should verify that the result that Gradescope generates is what you expect. Your code is built and tested in an Ubuntu 18 VM, using NodeJS v14. You may resubmit to Gradescope an unlimited number of times before the deadline.

Please be reminded of the course late submisison policy: assignments will be accepted up to 48 hours past the deadline at a penalty of 50%, and not accepted beyond 48 hours past the deadline.