'java codewars initiateRandTests expected:<false> but was:<true>
This code passed all tests except one "initiateRandTests".I dont understand what is it. On the site 0 information about this or I cant understand it.
there is my code:
public class XO {
public static boolean getXO (String str) {
int num = 0, x = 0, o = 0;
int indX, indO;
while(num < str.length()){
indX = str.indexOf("x", num);
indO = str.indexOf("o", num);
if (indX == num){[enter image description here][1]
x++;[enter image description here][2]
}
if (indO == num){
o++;
}
num++;
}
return x == o;
}
}
and there are tests:
public class SolutionTest {
@Test
public void testSomething1() {
assertEquals(true, XO.getXO("xxxooo"));
}
@Test
public void testSomething2() {
assertEquals(true, XO.getXO("xxxXooOo"));
}
@Test
public void testSomething3() {
assertEquals(false, XO.getXO("xxx23424esdsfvxXXOOooo"));
}
@Test
public void testSomething4() {
assertEquals(false, XO.getXO("xXxxoewrcoOoo"));
}
@Test
public void testSomething5() {
assertEquals(false, XO.getXO("XxxxooO"));
}
@Test
public void testSomething6() {
assertEquals(true, XO.getXO("zssddd"));
}
@Test
public void testSomething7() {
assertEquals(false, XO.getXO("Xxxxertr34"));
}
}
as can you see all tests complited except last [1]: https://i.stack.imgur.com/AE2m9.png this part I dont understand [2]: https://i.stack.imgur.com/CsfYr.png
Solution 1:[1]
Your code seems to be correct. I found this in the Codewars doc.
Some test or assertion libraries used by Codewars do not have a nice way to specify additional assertion messages for failed test cases, or authors did not think or care about adding these. If this is the case you will unfortunately have to debug in another way (for example by printing test input), and perhaps raise an issue about confusing assertion messages.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aymeric Bizouarn |
