Skip to content

Instantly share code, notes, and snippets.

@JHarry444
Created February 14, 2019 14:29
Show Gist options
  • Save JHarry444/e44f61d90b3f5ab84b9f1cadea9e2394 to your computer and use it in GitHub Desktop.
Save JHarry444/e44f61d90b3f5ab84b9f1cadea9e2394 to your computer and use it in GitHub Desktop.
package main;
public class DogShow {
public static String exclude(int place) {
StringBuilder output = new StringBuilder();
for (int i = 1; i <= 100; i++) {
if (i != place) {
output.append(i);
if (i > 3 && i < 21) {
output.append("th");
} else if (i % 10 == 3) {
output.append("rd");
} else if (i % 10 == 2) {
output.append("nd");
} else if (i % 10 == 1) {
output.append("st");
} else {
output.append("th");
}
output.append(", ");
}
}
return output.substring(0, output.length() - 2);
}
}
package testing;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import main.DogShow;
public class DogShowTest {
@Test
public void initTest() {
assertEquals("String is empty", false, DogShow.exclude(1).isEmpty());
}
@Test
public void excludeTest() {
assertEquals("Place has not been removed", false, DogShow.exclude(2).contains(" 2nd"));
}
@Test
public void endsWithCommaTest() {
assertEquals("String ends in comma.", false, DogShow.exclude(100).endsWith(", "));
}
@Test
public void teenTest() {
assertEquals("Teens are incorrectly formatted", true, DogShow.exclude(5).contains("12th"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment