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

add unit tests for ContentExtractor #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cn.edu.hfut.dmic.contentextractor;

import org.jsoup.nodes.Document;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by LordLRO on 17.09.2019.
*/

public class ContentExtractorTest {
private ContentExtractor contentExtractor = new ContentExtractor(new Document("testUri"));

@Test
public void testStrSim() throws Exception {
assertEquals(contentExtractor.strSim("", ""), 0, 0);
assertEquals(contentExtractor.strSim("", "abc"), 0, 0);
assertEquals(contentExtractor.strSim("132535365", "123456789"), 0.55555555, 0.00000001);

String longStringOfLetterA = new String(new char[2000000])
.replace("\0", "A");
assertEquals(contentExtractor
.strSim(longStringOfLetterA, "A"), 1.0 /longStringOfLetterA.length(), 0.000001);
}

/**
* Test using Robustness Testing skill
*/
@Test public void testLcs() throws Exception {
try {
assertEquals(contentExtractor.lcs(null, "Hello World!"), 0);
}
catch (NullPointerException e) {
}

assertEquals(contentExtractor.lcs("", "Hello World!"), 0);

assertEquals(contentExtractor.lcs("H", "Hello World!"), 1);

String firstLongString = new String(new char[1000])
.replace("\0", "Hello World!");
assertEquals(contentExtractor.lcs(firstLongString, "Hello World!"), 12);

String shorterFirstLongString = new String(new char[1000])
.replace("\0", "Hello World");
assertEquals(contentExtractor.lcs(shorterFirstLongString, "Hello World!"), 11);

String longerFirstLongString = new String(new char[1000])
.replace("\0", "Hello World!!");
assertEquals(contentExtractor.lcs(longerFirstLongString, "Hello World!"), 12);

try {
assertEquals(contentExtractor.lcs("He Word", null), 0);
}
catch (NullPointerException e) {
}

assertEquals(contentExtractor.lcs("He Word!", ""), 0);

assertEquals(contentExtractor.lcs("He Word!", "!"), 1);

String secondLongString = new String(new char[1000])
.replace("\0", "He Word!");
assertEquals(contentExtractor.lcs(secondLongString, "He Word!"), 8);

String shorterSecondLongString = new String(new char[1000])
.replace("\0", "He Word");
assertEquals(contentExtractor.lcs(shorterSecondLongString, "He Word!"), 7);

String longerSecondLongString = new String(new char[1000])
.replace("\0", "!He Word!");
assertEquals(contentExtractor.lcs(longerSecondLongString, "He Word!"), 8);

assertEquals(contentExtractor.lcs("Hello World!", "He Word!"), 8);
}

}