Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab 7 changes #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
javac -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar MarkdownParseTest.java MarkdownParse.java
java -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MarkdownParseTest
Binary file added MarkdownParse.class
Binary file not shown.
24 changes: 20 additions & 4 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,39 @@ public static ArrayList<String> getLinks(String markdown) {
ArrayList<String> toReturn = new ArrayList<>();
// find the next [, then find the ], then find the (, then read link upto next )
int currentIndex = 0;
while(currentIndex < markdown.length()) {
int openBracket = markdown.indexOf("[", currentIndex);
while(currentIndex < markdown.length()||openBracket!=null||closeBracket!=null||openParen!=null||closeParen!=null) {
int openBracket = MarkdownParse.checkOpenBracket(markdown, currentIndex);
int closeBracket = markdown.indexOf("]", openBracket);
int openParen = markdown.indexOf("(", closeBracket);
if(openBracket == -1 || closeBracket == -1){
break;
}
int closeParen = markdown.indexOf(")", openParen);
if(openBracket == -1){
break;
}
toReturn.add(markdown.substring(openParen + 1, closeParen));

currentIndex = closeParen + 1;

}

return toReturn;
}

public static int checkOpenBracket(String markdown, int currentIndex){
int openBracket = markdown.indexOf("[", currentIndex);
if(openBracket == -1){
return null;
}
return openBracket;
}

public static void main(String[] args) throws IOException {
Path fileName = Path.of(args[0]);
String content = Files.readString(fileName);
ArrayList<String> links = getLinks(content);
String contentOfFile = Files.readString(fileName);
ArrayList<String> links = getLinks(contentOfFile);
System.out.println(links);

}
}
Binary file added MarkdownParseTest.class
Binary file not shown.
64 changes: 63 additions & 1 deletion MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,72 @@
import static org.junit.Assert.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.junit.*;
public class MarkdownParseTest {

@Test
public void addition() {
public void addition(){
assertEquals(2, 1 + 1);

}


@Test
public void testLinks1() throws IOException{
String content = Files.readString(Path.of("test-file.md"));
assertEquals(List.of("https://something.com", "some-thing.html"), MarkdownParse.getLinks(content));
}

@Test
public void testLinks2() throws IOException{
String content = Files.readString(Path.of("test-file2.md"));
assertEquals(List.of("https://google.com", "some-thing.html"), MarkdownParse.getLinks(content));
}

@Test
public void testLinks3() throws IOException{
String content = Files.readString(Path.of("test-file3.md"));
assertEquals(List.of("more text here"), MarkdownParse.getLinks(content));
}

@Test
public void testLinks7() throws IOException{
String content = Files.readString(Path.of("test-file7.md"));
assertEquals(true, MarkdownParse.getLinks(content).isEmpty());
}

//New Test
@Test
public void getCorrectLinks4() throws IOException{
String content = Files.readString(Path.of("test-file4.md"));
assertEquals(List.of(""),MarkdownParse.getLinks(content));
}

//New Test
@Test
public void getCorrectLinks5() throws IOException{
String content = Files.readString(Path.of("test-file5.md"));
assertEquals(List.of("page.com"),MarkdownParse.getLinks(content));
}

//New Test
@Test
public void getCorrectLinks6() throws IOException{
String content = Files.readString(Path.of("test-file6.md"));
assertEquals(List.of(""),MarkdownParse.getLinks(content));
}

//New Test
@Test
public void getCorrectLinks8() throws IOException{
String content = Files.readString(Path.of("test-file8.md"));
assertEquals(List.of("a link on the first line"),MarkdownParse.getLinks(content));
}



}
3 changes: 3 additions & 0 deletions cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Host ieng6
HostName ieng6.ucsd.edu
User cs15ls122au
Empty file added lib/Makefile
Empty file.