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 Q2ChecksumTest {
public Timeout globalTimeout = Timeout.millis(1000);
static final String INPUT_FILENAME_BASE = “assets/Q2Checksum”;
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, “HAMLET\n\n\n”);
public void smallChecksum() {
test(“B”, true, “fHAMLET\n\n\n”);
public void medChecksum() {
test(“C”, true, “oHAMLET\n” +
“\thDRAMATIS PjERSONAE\n” +
“qCLAUDIUS\tkqing of Denrmark. (KINdG CLAUDIUSq:)\n” +
“HAMLETy\tson to thte late\n”);
public void longerChecksum() {
test(“D”, true, “oHAMLET\n” +
“\thDRAMATIS PjERSONAE\n” +
“qCLAUDIUS\tkqing of Denrmark. (KINdG CLAUDIUSq:)\n” +
“HAMLETy\tson to thge late, anrd nephew tco the presient king.\n” +
“POLONIUS\tklord chambxerlain. (LyORD POLONInUS:)\n” +
“HORAtTIO\tfriendk to Hamleto.\n” +
private void test(String insuf, boolean cs, String expected) {
Q2Checksum.checksum(INPUT_FILENAME_BASE+insuf, OUTPUT_FILENAME, cs);
assertTrue(“Expected file \””+OUTPUT_FILENAME+”\”, but no file was found”, Files.exists(Paths.get(OUTPUT_FILENAME)));
String actual = Files.readString(Paths.get(OUTPUT_FILENAME));
assertTrue(“Expected file to contain \””+expected+”\” but got \””+actual+”\””, actual.equals(expected));
} catch (IOException e) {
System.out.println(e);
fail(e.getMessage());
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com