Individual Project: txter
Deliverable 4
Project Goals
In this project, you will be developing a Java application, txter, using an agile, test-driven development process across multiple deliverables. For this assignment you will use version 19 of the Java Development Kit. You will receive one grade for the entire project, but each deliverable must be completed by its own due date and all deliverables will contribute to the overall project grade.
Specification
txter is a command-line utility written in Java with the following specification:
Summary
txter allows for simple text manipulation of the contents of a file.
Syntax
txter [OPTIONS] FILE
Description
The program txter performs basic text transformation on the lines of text from an input file. It is invoked as a command-line tool using the syntax described above, after compilation. The program writes the transformed text to the standard output and errors or usage messages to the standard error without modifying the input file. The FILE parameter is required and must be the last parameter as shown above. The options allowed in the program, which are optional, delimited by the left [ and right ] brackets, may be provided in any order and are described as follows:
Option
-e <string>
-k <string>
Description
Exclude Lines: Exclude lines containing the given
substring. This option is mutually exclusive with -k.
Keep Lines: Keep only the lines containing the given substring. This option is mutually exclusive with -e.
Option
-i
-r <target>
-d <integer>
Order of execution
Description
Case Insensitive: Applies case insensitive matching when used with "Keep Lines" and "Exclude Lines". This option takes no parameters.
Reverse text: A valid target here is either “words” or “text”. Reverse words or text in each line according to the parameter “words” or “text”. The "words" string parameter will reverse the order of words in each line, but leave the characters of the words in the original order. The "text" string parameter will reverse the characters within each line. Spaces should be considered as a word or characters here.
Duplicate Lines: Duplicate each line to the file the number of times specified. 0 is minimum and 9 is maximum for <integer>.
The last command-line parameter provided is always treated as the filename, as shown in the syntax section, while OPTIONS flags can appear in any order and parsed as they appear from left to right. This means that the following two commands are equivalent when executed on the command line:
Example 1 txter -d 1 -k ..? input.txt Example 2 txter -k ..? -d 1 input.txt
In the above examples, (Example 1) parses -d first, then -k, and finally input.txt while (Example 2) parses -k first, then -d, and finally input.txt. These two will result in the same output (assuming that the same input.txt is used for both) because the parsing of options is independent of their execution order. The order of execution for each option is given in the diagram below (note that the colors and border lines are there for ease of viewing):
2
The above diagram of the execution order of options can also be described as follows:
-
If -i is present, then -k or -e shall keep or exclude lines containing matched strings with case insensitive manner.If -i is not present, then -k or -e shall keep or exclude lines containing exact matched strings with case sensitive manner.
-
If -r is present, then text in each line shall be reversed according to its parameter.
-
If-dispresent,eachlineshallbeduplicatedby<integer>times.
Notes
-
● To keep this application simple, all errors shall result in the display of the standard usage message. This is shown in the syntax section above as well as in the files provided to you which are linked in later sections.
-
● If options are repeated, only their last occurrence is applied. The Examples section below shows a case of repeated options.
-
● An empty input file shall produce an empty output. The Examples section below shows a case of an empty input file.
-
● You shall assume that the command line parameter strings will not contain newline characters (\r, \n, \r\n) as the behavior of the program would be platform dependent and may result in error during grading. Therefore there should be no test cases using these values as option parameters. Additionally, you may assume that your application will be called with valid String[] args.
-
● Specifying option -e with an empty string as the string parameter shall exclude all lines, resulting in an empty output.
-
● Specifying option -k with an empty string as the string parameter shall keep all lines.
-
● IMPORTANT: You are expected to infer the expected program behavior using the gradescope provided information alone. Submitting an implementation that prints out the instructor-provided test inputs is unfair to your classmates and will result in a significant grade penalty.
Program errors
-
● The last line of a non-empty input file must be terminated by a newline. If the non-empty input file does not terminate in a newline, the program shall generate an error.
-
● All parameters of program options are required and shall result in an error if omitted. This means that parsing an option that should include parameters but doesn't should result in an error. The Examples section below shows a case of missing option parameters.
-
● Specifying option parameters with the wrong type shall result in an error.
-
● Specifying option -i without -e or -k shall result in an error.
-
● Specifying option -i with parameters shall result in an error.
-
● Specifying options -e and -k simultaneously shall result in an error.
-
● Specifying option -r with a parameter outside of the allowed values ("words", 3
"text") shall result in an error.
● Specifying option -d with an integer outside of the inclusive range 0 to 9 as the
duplication parameter shall result in an error.
4
Examples of Usage
The examples described here can also be seen in JUnit 5 form on the MainTest.java file provided to you in D1. In the following, "↵" represents a newline character.
Example 1
txter -e test sample.txt
input sample.txt
stdout
stderr
Example 2
txter -i sample.txt
input sample.txt
stdout
stderr
Example 3
txter -e Bird sample.txt
input sample.txt
stdout
stderr
Dog goes "woof".↵ Cat goes "meow".↵ Bird goes "tweet".↵
Dog goes "woof".↵ Cat goes "meow".↵
nothing sent to stderr
nothing sent to stdout
nothing sent to stderr
Hello, world!↵
↵
How are you?↵
nothing sent to stdout
Usage: txter [ -i | -k substring | -e substring | -r target | -d num ] FILE↵
5
Example 4
txter -k Mouse sample.txt
input sample.txt
stdout
stderr
Example 5
Dog goes "woof".↵ Cat goes "meow".↵ Bird goes "tweet".↵
nothing sent to stdout
nothing sent to stderr
txter -r words sample.txt
input sample.txt
stdout
stderr
Example 6
Baby Shark , doo - doo, doo-doo, doo-doo ↵ doo-doo doo-doo, doo, - doo , Shark Baby↵
nothing sent to stderr
txter -r text sample.txt
!syas siht tahw wonk reven lliw uoY↵
input sample.txt
stdout
stderr
...tiaw ho↵
You will never know what this says!↵
oh wait...↵
nothing sent to stderr
6
Example 7
txter -d 8 -d 2 sample.txt
Baby Shark, doo-doo, doo-doo, doo-doo↵
input sample.txt
stdout
stderr
Example 8
Mommy Shark, doo-doo, doo-doo, doo-doo↵
Baby Shark, doo-doo, doo-doo, doo-doo↵ Baby Shark, doo-doo, doo-doo, doo-doo↵ Baby Shark, doo-doo, doo-doo, doo-doo↵ Mommy Shark, doo-doo, doo-doo, doo-doo↵ Mommy Shark, doo-doo, doo-doo, doo-doo↵ Mommy Shark, doo-doo, doo-doo, doo-doo↵
nothing sent to stderr
txter -r words -d 1 -k cat -i sample.txt
input sample.txt
stdout
stderr
Dog goes "woof".↵ Cat goes "meow".↵ Bird goes "tweet".↵
"meow". goes Cat↵ "meow". goes Cat↵
nothing sent to stderr
Deliverables Summary
This part of the document is provided to help you track where you are in the individual project. This section will be updated in future deliverables.
Deliverable 1 Provided
txter specification (linked in this document above)
Skeleton of the main class for txter (linked below)
JUnit 5 example tests and skeleton of test class to submit (linked below)
JUnit 5 library (linked below)
Expected
Part I (Category partition)
catpart.txt: TSL file you created
catpart.txt.tsl: test specifications generated by the TSLgenerator tool when
run on your TSL file Part II (JUnit tests)
MyMainTest.java: JUnit tests derived from your category partition test frames
Deliverable 4
Provided
Code and interfaces to use as a starting point for this deliverable Instructor-provided test cases for class txter (through Gradescope)
Expected
Implementation of class txter that passes all instructor-provided test
Deliverable 4: Instructions
Your company has received positive feedback for the command-line version of the txter utility. They have therefore decided to provide its functionality through a library and an API, so that additional applications can be built on top of it. Part of your team has already created a Java interface for the API (TxterInterface), which you will be able to download, and a set of tests for it, which you will be able to run on your code through Gradescope. Your job is to develop a class, named Txter, that implements the provided interface and passes the provided tests.
To complete this deliverable, you will submit your code (i.e., class Txter and related files) and make sure that it passes all the instructor-provided tests (Gradescope will run them for you and report information about passing and failing tests). To do so, you will have to refactor your code so that it can be invoked using the provided interface. Because the code will be invoked programmatically, rather than from the command line, the use of incorrect parameters should result in an exception, and no error messages should be generated on the console.
Grade
Your grade for this deliverable will be proportional to the percentage of instructor test cases that pass on your code. For example, if your implementation passes 85 of the 100 provided test cases, your grade for this deliverable will be 85 (this is an example, the actual number of tests may differ).
Detailed Steps
1. Downloadarchiveindividualproject-d4.tar.gz
2. Unpackthearchiveinthedirectory"IndividualProject"thatyoucreatedin
Deliverable 1. Hereafter, we will refer to this directory as <dir>. 3. Afterunpacking,youshouldseethefollowingfiles:
-
<dir>/txter/src/edu/gatech/seclass/txter/
TxterInterface.java
This is the interface that you have to implement in the class Txter. Make sure to read the description of the methods and their parameters in the comments before each method, including the details about exceptions that the methods may throw. Given that the core functionality did not change, the methods should be self-explanatory. -
<dir>/txter/src/edu/gatech/seclass/txter/
TxterException.java
The exception to be thrown by your Txter class in case of errors, with a suitable message. The error message does not have any rules, so it can be the usage string or more specific details of why the exception was thrown. They are similar to those used for the command-line version of the utility, with some additional messages and small changes.
10
c. <dir>/txter/test/edu/gatech/seclass/txter/
MyLibTest.java
This is a test class with a single test case for the Txter class, to give you an
idea of how a test would look in this context.