266 lines
8.2 KiB
Java
266 lines
8.2 KiB
Java
|
|
/**
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2021 Exercism
|
|
* Copyright (c) 2026 Networked Embedded Systems, University of Duisburg-Essen
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
import de.uni_due.s3.jack2.backend.checkers.tracingchecker.framework.TracingFramework;
|
|
import de.uni_due.s3.jack2.backend.checkers.tracingchecker.framework.TracingFramework.Test;
|
|
|
|
import java.util.Collections;
|
|
|
|
public class BobTest {
|
|
|
|
private static final int MAX_POINTS = 100;
|
|
private static final int TEST_CASES = 25;
|
|
private static final int SUCCESS_POINTS = MAX_POINTS / TEST_CASES;
|
|
private static final int FAILURE_POINTS = 0;
|
|
|
|
private final java.util.List<Integer> testPoints = new java.util.ArrayList<>();
|
|
|
|
@Test(name = "stating something")
|
|
public void saySomething() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("Tom-ay-to, tom-aaaah-to."));
|
|
});
|
|
}
|
|
|
|
@Test(name = "shouting")
|
|
public void shouting() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whoa, chill out!", bob.hey("WATCH OUT!"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "shouting gibberish")
|
|
public void shoutingGibberish() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whoa, chill out!", bob.hey("FCECDFCAAB"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "asking a question")
|
|
public void askingAQuestion() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("Does this cryogenic chamber make me look fat?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "asking a numeric question")
|
|
public void askingANumericQuestion() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("You are, what, like 15?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "asking gibberish")
|
|
public void askingGibberish() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("fffbbcbeab?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "talking forcefully")
|
|
public void talkingForcefully() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("Hi there!"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "using acronyms in regular speech")
|
|
public void usingAcronymsInRegularSpeech() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("It's OK if you don't want to go work for NASA."));
|
|
});
|
|
}
|
|
|
|
@Test(name = "forceful question")
|
|
public void forcefulQuestions() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Calm down, I know what I'm doing!", bob.hey("WHAT'S GOING ON?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "shouting numbers")
|
|
public void shoutingNumbers() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whoa, chill out!", bob.hey("1, 2, 3 GO!"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "no letters")
|
|
public void onlyNumbers() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("1, 2, 3"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "question with no letters")
|
|
public void questionWithOnlyNumbers() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("4?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "shouting with special characters")
|
|
public void shoutingWithSpecialCharacters() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whoa, chill out!", bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "shouting with no exclamation mark")
|
|
public void shoutingWithNoExclamationMark() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whoa, chill out!", bob.hey("I HATE THE DENTIST"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "statement containing question mark")
|
|
public void statementContainingQuestionMark() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("Ending with ? means a question."));
|
|
});
|
|
}
|
|
|
|
@Test(name = "non-letters with question")
|
|
public void nonLettersWithQuestion() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey(":) ?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "prattling on")
|
|
public void prattlingOn() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("Wait! Hang on. Are you going to be OK?"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "silence")
|
|
public void silence() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Fine. Be that way!", bob.hey(""));
|
|
});
|
|
}
|
|
|
|
@Test(name = "prolonged silence")
|
|
public void prolongedSilence() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Fine. Be that way!", bob.hey(" "));
|
|
});
|
|
}
|
|
|
|
@Test(name = "alternate silence")
|
|
public void alternateSilence() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Fine. Be that way!", bob.hey("\t\t\t\t\t\t\t\t\t\t"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "starting with whitespace")
|
|
public void startingWithWhitespace() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey(" hmmmmmmm..."));
|
|
});
|
|
}
|
|
|
|
@Test(name = "ending with whitespace")
|
|
public void endingWithWhiteSpace() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("Okay if like my spacebar quite a bit? "));
|
|
});
|
|
}
|
|
|
|
@Test(name = "other whitespace")
|
|
public void otherWhiteSpace() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Fine. Be that way!", bob.hey("\n\r \t"));
|
|
});
|
|
}
|
|
|
|
@Test(name = "non-question ending with whitespace")
|
|
public void nonQuestionEndingWithWhiteSpace() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Whatever.", bob.hey("This is a statement ending with whitespace "));
|
|
});
|
|
}
|
|
|
|
@Test(name = "multiple line question")
|
|
public void multipleLineQuestion() {
|
|
runTest(() -> {
|
|
Bob bob = new Bob();
|
|
assertEquals("Sure.", bob.hey("\nDoes this cryogenic chamber make\n me look fat?"));
|
|
});
|
|
}
|
|
|
|
private void runTest(Runnable body) {
|
|
try {
|
|
body.run();
|
|
testPoints.add(SUCCESS_POINTS);
|
|
} catch (Throwable t) {
|
|
TracingFramework.printError(t.getMessage());
|
|
testPoints.add(FAILURE_POINTS);
|
|
}
|
|
}
|
|
|
|
private void assertEquals(Object expected, Object actual) {
|
|
if (expected == null && actual == null)
|
|
return;
|
|
if (expected != null && expected.equals(actual))
|
|
return;
|
|
throw new AssertionError("Expected: " + expected + ", but got: " + actual);
|
|
}
|
|
|
|
public int getResult() {
|
|
int sum = testPoints.stream().mapToInt(Integer::intValue).sum();
|
|
return sum / SUCCESS_POINTS == TEST_CASES ? MAX_POINTS : sum;
|
|
}
|
|
|
|
}
|