Solved task 3
This commit is contained in:
parent
7aade7fac7
commit
89e4bb84ee
@ -0,0 +1,88 @@
|
|||||||
|
package com.alibaba.fastjson.parser;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONException;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
public class JSONScannerTest2 {
|
||||||
|
@Test
|
||||||
|
public void stringUtf8BomTest() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("\uFEFF,");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.COMMA, scanner.token());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringHasSpecialTest() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("\"\\b\\n\\t\\\"\\uABED\"");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.LITERAL_STRING, scanner.token());
|
||||||
|
Assert.assertEquals("\b\n\t\"\uABED", scanner.stringVal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringWithIso8601Date() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("2012-04-23T18:25:43.511Z");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
Assert.assertTrue(scanner.scanISO8601DateIfMatch());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanSingleComment() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("//dsajfklsjfk");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertTrue(scanner.isEOF());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanMultiComment() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("/*dsajfklsjfk*/");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertTrue(scanner.isEOF());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scannerSkipWhitespace() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("\n\t\t \r\b\f232");
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token());
|
||||||
|
Assert.assertEquals(232, scanner.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inputTokenTest_Null() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("null");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.NULL, scanner.token());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inputTokenTest_Undefined() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("undefined");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.UNDEFINED, scanner.token());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inputTokenTest_Undefined() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("undefined");
|
||||||
|
// After construction the UTF-8 BOM should be safely skipped
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.UNDEFINED, scanner.token());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inputTokenTest_ExplPosInt() throws Throwable {
|
||||||
|
JSONScanner scanner = new JSONScanner("+7531"); // explicit positive with sign
|
||||||
|
scanner.nextToken();
|
||||||
|
Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token());
|
||||||
|
Assert.assertEquals(7531, scanner.intValue());
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ name = MichaelChen
|
|||||||
|
|
||||||
solutionname = Solution_Phase$(phase)_$(name)
|
solutionname = Solution_Phase$(phase)_$(name)
|
||||||
target = $(solutionname)_V$(version).zip
|
target = $(solutionname)_V$(version).zip
|
||||||
package = $(solutionname).pdf
|
package = $(solutionname).pdf HashMap.java JSONScannerTest2.java
|
||||||
latexmkflags =
|
latexmkflags =
|
||||||
|
|
||||||
.PHONY : all dev
|
.PHONY : all dev
|
||||||
|
@ -210,7 +210,7 @@
|
|||||||
\begin{enumerate}[topsep=0pt, leftmargin=*]
|
\begin{enumerate}[topsep=0pt, leftmargin=*]
|
||||||
\item Measure the coverage of your given project test suite (which includes the existing test suite as well as the tests that you created in previous project phases) by three graph coverage criteria which you can freely choose. Describe each individual result in 2-3 sentences.
|
\item Measure the coverage of your given project test suite (which includes the existing test suite as well as the tests that you created in previous project phases) by three graph coverage criteria which you can freely choose. Describe each individual result in 2-3 sentences.
|
||||||
\begin{answer}
|
\begin{answer}
|
||||||
[TODO: Add answer here]
|
My test suite for the \texttt{JSONScanner} class so far covers 1\% of the class and 5\% of the \texttt{JsonLexerBase} base class, that does most of the work for basic JSON strings, in terms of instruction coverage. The fact that roughly similar coverage values are achieved with branch coverage using my small test suite is explained by the fact that most instructions that i have not covered are not covered because of missing tests that handle edge case (in this case mostly different JSON token alternatives) branches. My method coverage currently is at about 14\% and 12\% for the base class. Similar to the above tests, I am missing lots of tests for function calls that retrieve specific token values, however the coverage is higher than the branch coverage because the token alternatives are handled within the lexing method call, thus the method coverage is higher.
|
||||||
\end{answer}
|
\end{answer}
|
||||||
|
|
||||||
\item Extend the test suite with own tests, which have to fullfil \textbf{one} of the following criteria:
|
\item Extend the test suite with own tests, which have to fullfil \textbf{one} of the following criteria:
|
||||||
@ -219,11 +219,7 @@
|
|||||||
\item Reveal a new bug in the software project (describe the bug, its context, and a potential fix in detail)
|
\item Reveal a new bug in the software project (describe the bug, its context, and a potential fix in detail)
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
\begin{answer}
|
\begin{answer}
|
||||||
[TODO: Add answer here]
|
See file \texttt{JSONScannerTest2.java}. Using this test suite I increased my test instruction coverage from 1\% to more than 9\% and my branch coverage from .5\% to almost 5\% (factor 10). I almost doubled the method coverage, which matches the test suite, because I roughly doubled the amount of different methods I called for different edge cases.
|
||||||
|
|
||||||
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip]
|
|
||||||
/* Add code here */
|
|
||||||
\end{lstlisting}
|
|
||||||
\end{answer}
|
\end{answer}
|
||||||
|
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
Loading…
Reference in New Issue
Block a user