Welcome to Two Fer on Exercism's Java Track.
If you need help running the tests or submitting your code, check out HELP.md
.
Two-fer
or 2-fer
is short for two for one. One for you and one for me.
Given a name, return a string with the message:
One for name, one for me.
Where "name" is the given name.
However, if the name is missing, return the string:
One for you, one for me.
Here are some examples:
Name | String to return |
---|---|
Alice | One for Alice, one for me. |
Bob | One for Bob, one for me. |
One for you, one for me. | |
Zaphod | One for Zaphod, one for me. |
Before you start, make sure you understand how to write code that can pass the test cases. For more context, check out this tutorial.
Most Java exercises include multiple test cases. These cases are structured to support a useful process known as test-driven development (TDD). TDD involves repeating a structured cycle that helps programmers build complex functionality piece by piece rather than all at once. That cycle can be described as follows:
- Add a test that describes one piece of desired functionality your code is currently missing.
- Run the tests to verify that this newly-added test fails.
- Update your existing code until:
- All the old tests continue to pass;
- The new test also passes.
- Clean up your code, making sure that all tests continue to pass. This typically involves renaming variables, removing duplicated chunks of logic, removing leftover logging, etc.
- Return to step 1 until all desired functionality has been built!
The test files in this track contain all the tests your solution should pass to be considered valid. That doesn't immediately seem to be compatible with the cycle described above, in which tests are written one by one. However, the tool that we use to write our tests, JUnit, provides an @Ignore annotation that can be used to temporarily skip an already-written test. Using this annotation, we make sure that the test files we deliver to you satisfy the following rules:
- The first test in any test file is not skipped by default.
- All but the first test in any test file are skipped by default.
This allows you to simulate the TDD cycle by following these slightly-modified steps:
- Run the tests to verify that at most one test currently fails.
- Update your existing code until all the non-skipped tests pass.
- Clean up your code, making sure that all non-skipped tests continue to pass.
- Remove the topmost
@Ignore
annotation in the test file. - Return to step 1 until no tests are skipped and all tests pass!
- @Smarticles101
- @FridaTveit
- @ikhadykin
- @jmrunkle
- @jssander
- @kytrinyx
- @lemoncurry
- @msomji
- @muzimuzhi
- @rdavid1099
- @sjwarner-bp
- @SleeplessByte
- @sshine
- @stkent
- @uzilan
- @Valkryst
- @ymoskovits