This assignment is a relatively simple program to capture various aspects of programming languages. We will work on versions of the program using 4 different languages. Next we will use Elixir. You may use any modules that are in the default Elixir library.
The application is a simple Orbits calculation, described here.
My solution is 12 functions (inluding main
) totaling 91 non-blank lines of code.
Because I thought I understood the problem well and had my working Smalltalk code to refer to for the algorithm, and therefore didn't initially build unit tests, this took me a lot longer.
I wrote the initial complete structure in about an hour, but found the problems I uncovered to be very hard to characterize, and probably spent another hour or two (interrupted by meetings) making relatively little progress.
Only after I started writing unit tests did I start to move at a reasonable speed, and probably finished in another hour.
In addition to the specifications there, the following Elixir-specific parameters will apply:
- If you didn't already do it for Assignment 1, to set up your fossil, see the fossil page. Once you open the fossil, you will see that there are directories and frameworks already set up for all 3 assignments.
-
cd A2
-
You would normally do
mix new a2
to create your package, but this has already been done in your fossil. -
Your
A2
module must have aprocess/1
function that accepts a string of an input file. A skeleton of this is already provided, along with amain
. -
When run via
iex -S mix
, the above methods would return results. -
Put your ownership information (see the assignment page) in the
Assign2/README.md
file. -
Your code will be tested via both
iex -S mix
andmix run
. -
You should be able to run tests with:
mix test
and it should at least run the provided test. -
The marker should be able to run your program by entering the following code:
$ iex -S mix Interactive Elixir (1.13.2) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> A2.main() Sun 42 Earth Earth Sun end-of-file entered here ^D on Linux/MacOSX Earth orbits Sun Sun orbits :ok iex(2)>
Note that theformat
function returns a string; it does no I/O. Piping it toIO.write
formats it with the newline character interpreted appropriately. - The Elixir style guide is a good source of guidance on code structuring.
-
Run your program with:
mix run -e 'A2.main()' <../sample-input
-
To check for correctness for this input, run your program with (on Linux or MacOSX):
mix run -e 'A2.main()' <../sample-input | diff - ../sample-output
You should do your assignment in the your Fossil CPS506
repository in the A2
directory.
Every time you have completed a part of the assignment, you should commit it to the repository.
You shouldn't wait until everything is complete to do this, it's better to commit regularly.
You don't have to commit with a particular fossil comment - we'll mark the last commit before the due date - however if you commit with a comment something like "Mark this A2 even though it's late", we will mark that even if it's late.
Remember to do fossil status
and fossil ext
from somewhere within the repository periodically to make sure you're commiting all of your code.
Also remember to not add binary files or other files that can be generated from the source.
You can use fossil add
and fossil rm
as many times as you want, but you only have to do it once each time there are new files to be included in the repository.
(There is also a fossil addremove
command, but there is something unintuitive about it so I rarely use it.)
In a terminal/command window simply change to the working directory and check-in, for example:
cd cd cps506 fossil ci -m "finished code and tests for Orbits"