package comp1110.exam;
import org.junit.Before;
import org.junit.Rule;
Copyright By PowCoder代写 加微信 powcoder
import org.junit.Test;
import org.junit.rules.Timeout;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class Q2CapsTest {
public Timeout globalTimeout = Timeout.millis(1000);
static final String INPUT_FILENAME_BASE = “assets/Q2Caps”;
static final String OUTPUT_FILENAME = “assets/Q2output”;
public void setup() {
Files.deleteIfExists(Paths.get(OUTPUT_FILENAME));
} catch (IOException e) {
System.err.println(e);
public void empty() {
test(“A”, false, “”, “”);
public void small() {
test(“B”, false, “hi! hi ! hi”, “hi! hi ! hi”);
public void smallChecksum() {
test(“B”, true, “HI! hi ! hi”, “hi! hi ! hi”);
public void medChecksum() {
test(“C”, true, ” is not simply random TEXT! It is over 2000 years OLD!!”, ” is not simply random text! It is over 2000 years old!!”);
public void largeChecksum() {
test(“D”, true, “Contrary to popular belief, is not simply random TEXT! It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years OLD!! More?!? Clintock”, “Contrary to popular belief, is not simply random text! It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old!! More?!? Clintock”);
private void test(String insuf, boolean cs, String expected, String content) {
Q2Caps.capitalize(INPUT_FILENAME_BASE+insuf, OUTPUT_FILENAME, cs);
assertTrue(“Called Q2Caps.capitalize(“+INPUT_FILENAME_BASE+insuf+”, “+OUTPUT_FILENAME+”, “+cs+”). Expected file \””+OUTPUT_FILENAME+”\”, but no file was found”, Files.exists(Paths.get(OUTPUT_FILENAME)));
String actual = Files.readString(Paths.get(OUTPUT_FILENAME));
assertTrue(“Called Q2Caps.capitalize(“+INPUT_FILENAME_BASE+insuf+”, “+OUTPUT_FILENAME+”, “+cs+”). Expected file to contain \””+expected+”\” but got \””+actual+”\” when file contained \””+content+”\”.”, actual.equals(expected));
} catch (IOException e) {
System.out.println(e);
fail(e.getMessage());
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com