Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 3.23 KB

lab-report-2-week-4.md

File metadata and controls

93 lines (62 loc) · 3.23 KB

Bug 1

Code changes:

change1

Link to test file for bug 1

Test in MarkdownParseTest:

@Test
    public void getLinks2() throws IOException {
        Path fileName = Path.of("test-file-2.md");
	    String contents = Files.readString(fileName);
        ArrayList<String> links = MarkdownParse.getLinks(contents);
        System.out.println(links);
        assertEquals(List.of("link.(com"), links);
    }

The failure-inducing input was having an extra open paren in the link address. This, again, caused the symptom of an infinite loop and OutOfMemoryError.

Output:

Bug1Symptom

This input created an infinite loop because the index kept setting back to -1 and looping through the text in the test file over and over again. To fix this, I added an if statement that checks for the index equaling -1 and stops if any of the indexes equal -1.

Bug 2

Code Changes:

change2 change2pt2 change2pt3

Link to test file for bug 2

Test in MarkdownParseTest:

@Test
    public void getLinksImage() throws IOException {
        Path fileName = Path.of("image-test.md");
	    String contents = Files.readString(fileName);
        ArrayList<String> links = MarkdownParse.getLinks(contents);
        System.out.println(links);
        assertEquals(new ArrayList<>(List.of()), links);
    }

The input was an image which should not be considered a link. The symptom was the .png being returned and printed as if it was a link.

Output:

Bug2Symptom

Some different failures also came up while trying to fix the original one:

Bug2Symptom2 Bug2Symptom3

The input was an image, so it should have returned nothing, but instead it returned the .png, which is not a link. The code change to fix this was to check for an exclamation mark immediately before the opening bracket, as well as some other changes to fix the failures that came up while trying to fix the original bug.

Bug 3

Code Changes:

change3

Link to test file for bug 3

Test in MarkdownParseTest:

@Test
    public void getLinksSpaceinURL() throws IOException {
        Path fileName = Path.of("test-space-in-url.md");
	    String contents = Files.readString(fileName);
        ArrayList<String> links = MarkdownParse.getLinks(contents);
        System.out.println(links);
        assertEquals(new ArrayList<>(List.of()), links);
    }

The failure-inducing input was having a space in the url of the link. This should not be included in the output since it is not a valid link, however it was included and produced a failure.

Output:

Bug3Symptom

The input was a link with a space in the url, which does not create a valid link, so it should not be returned by MarkdownParse. However, it was, so to fix this bug, we check that the index of the space in the link is not in the middle of it by checking if the index of the space is equal to -1. If it is, the link can be added.