-3

I was given an assignment:

Consider a list of single digit numbers. For example, [2,2,5]. Consider the successors of such lists.

  • The successor of [2,2,5] is [2,2,6].
  • The successor of [2,3,9,9] is [2,4,0,0].
  • The successor of [9,9,9,9] is [1,0,0,0,0].

Write a Java program that takes such a list of numbers as input and returns its successor. You cannot express this list as a decimal number and compute its successor as the number may be so large that an overflow occurs. Make your program as short as possible.

Submit code in Java along with compilation instructions and test scripts.

I have written the program and compiled and ran it successfully. The program does exactly what the assignment requires. However, I am not sure what the instructor mean by test scripts. Would someone please explain and provide an example to what it is?

Note: If you decide to downvote the question, provide a reason so I can edit my question.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • 1
    Likely asking for a unit test. http://stackoverflow.com/questions/8751553/how-to-write-a-unit-test Basically, create a test with the example inputs, and assert that the outputs are exactly what you promise they are. – Compass Feb 28 '17 at 20:20
  • 3
    Why not ask your instructor what they mean? – resueman Feb 28 '17 at 20:21
  • Already emailed him, but he does not reply. – ConfusedStudent Feb 28 '17 at 20:22
  • 1
    A test script is pretty much what it sounds like. Given a specific input, what is the expected output. Tests can be automated, but they don't have to be. In the real world, QA teams have a set of scripts that they run to test the applicaiton, and the business also writes up a test script that the application must pass. This is UAT or User Acceptance Testing. The goals are slightly different, in that the developer is looking to make sure the code operates correctly, QA does a number of use case and edge testing to break the code, and customer makes sure it does what they asked for. – Mike Feb 28 '17 at 20:34

2 Answers2

2

Look up Junit. The professor wants you to create a test class that tests specific scenarios. Something like this:

@Test
public void testSuccesor() {
   int[] start = {2,2,5};
   int[] expected = {2,2,6};

   int[] actual = callSuccesorMethod(start);

   assertArrayEquals(expected, actual);
}

The test will throw a failure if the expected value does not match the actual value. Unit testing is a great way to validate your code. It also helps with future development, when you change the code you can just rerun your tests to validate you didn't break anything.

Check out TDD as well, its a style of programming that could interest you.

Mason T.
  • 1,567
  • 1
  • 14
  • 33
  • Thank you. This is what I need. – ConfusedStudent Feb 28 '17 at 20:31
  • I like your answer and I like testing anyway, so I upvoted but I think that script equals junit is pure speculation on your side :-) – GhostCat Feb 28 '17 at 20:32
  • @KaneBilliot GhostCat brings up a good point, please check with your professor that Junit is fine before turning in the assignment. – Mason T. Feb 28 '17 at 20:35
  • I agree with @ghostCat. The instructor said nothing about a JUnit test. he said a script - not more Java code - which can be any shell script that executes the program and tests one or more scenarios. – FredK Feb 28 '17 at 20:35
0

A test script is a program that exercises your code (known as the "system under test" or simply "SUT") in a predictable manner, and verifies that its behaviour is correct for the given inputs. The test may be in the same language as the SUT, but it's very common to use a different language, as you have different requirements on performance, ease of modification, readability and robustness.

For example, a simple shell script may be enough in your case:

#!/bin/bash
set -e # important, so the script fails if any single command fails

test '2,2,6' = $(./successor '2,2,5')
test '2,4,0,0' = $(./successor '2,3,9,9')
# Add any more tests you think you should have

If your compilation instructions are presented in the form of a Makefile, you could run your tests from there, too. It's a common convention to call the target test, so make test would compile your program and run its tests.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103