4
I was looking for some Java exercises to train and learn some algorithms when I came across the site exercism. and I decided to do their Java exercises. So far so good, I downloaded their app using the chocolately and installed the Gradle to run the tests. I found the methodological proposal of their exercises very interesting until the problem came.
The problem is this:
When you make the exercise request by cmd using the command:
$ exercism fetch java hello-world
The exercise already comes with bugs (intentionally) so that you find them and solve them all. After solving the bugs, and running the command:
$ gradle test
inside the exercise folder, everything should go well and then you are free to submit your answer using the command:
$ exercism submit src/main/java/HelloWorld.java
indicating the path of your code in submission:
Now that comes the problem.
The following code is used for testing:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HelloWorldTest {
@Test
public void helloNoName() {
assertEquals("Hello, World!", HelloWorld.hello(""));
assertEquals("Hello, World!", HelloWorld.hello(null));
}
@Test
public void helloSampleName() {
assertEquals("Hello, Alice!", HelloWorld.hello("Alice"));
}
@Test
public void helloAnotherSampleName() {
assertEquals("Hello, Bob!", HelloWorld.hello("Bob"));
}
}
What I understood this code should do is to receive a string from the main program and test if the string is empty of the type ""
or void
he should return: Hello, World!.
If written in the main program the name Alice or Bob it would return or Hello, Alice! or Hello, Bob!
My main program is as follows:
public class HelloWorld {
public static String hello(String name) {
return name;
}
}
I already tried to put the three valid strings concatenated, three returns in the method, set up an array of strings and have them display one at a time and nothing.
The problem is that the requirement of the exercise asks that this be solved by editing the main program which is the Helloworld.java that prevents me from changing the test program that is the Helloworldtest.java 'Cause that would be cheating.
The mistake that the gradle
Show me this one:
PS C:\Users\anton\exercism\java\hello-world> gradle test
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
HelloWorldTest > helloAnotherSampleName FAILED
org.junit.ComparisonFailure at HelloWorldTest.java:20
HelloWorldTest > helloSampleName FAILED
org.junit.ComparisonFailure at HelloWorldTest.java:15
HelloWorldTest > helloNoName FAILED
org.junit.ComparisonFailure at HelloWorldTest.java:9
3 tests completed, 3 failed
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Users/anton/exercism/java/hello-world/build/reports/tests/inde
x.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.581 secs
If anyone knows how I fix it send me a tip here.
From what I understand of the test, the method
hello()
takes a string and concatenates with "Hello, ", if the string is null or empty, displays "Hello, word!". This already answers your question, now get to work! D– user28595
I would even respond with the method ready, but I think it will be more constructive for yourself this creation.
– user28595
I’ll keep trying here, hope to get soon
– Antonio Carlos Araújo
I already gave you practically a "portugol", just turn it into code.
– user28595
The question Helloword does not meet the presented unitary tests. Edit the question and add your main program from that test there.
– user28595
I just switched to name;
– Antonio Carlos Araújo
Still not answering, you are not checking whether the string name is empty or null, and you are not concatenating with Hello,
– user28595
Conseguiiiiii, Vlw Diegão =)
– Antonio Carlos Araújo
Arrange! : D You can answer your own question with the code.
– user28595
I did not understand why the question was closed by "outside the scope", even if it is about programming, and having a reproducible example of the problem and the attempt to resolve, despite being an exercise.
– user28595
This question is being discussed at the goal.
– bfavaretto