\Subsubsection{Parser}

This section outlines the testing strategy for the Parser and elaborates the
steps of the testing. Throughout the tests the presence of a functional DistributionFactory is assumed.


\textbf{Testing strategy}

The testing will follow the bottom-up testing strategy. This means that the smallest parts that can be tested will be tested first, and when their functionality has been verified, the testing will move on to the methods using them. The last tested method for the Parser is therefore readModel, which calls all the other methods.

NOTE: Due to the lack of time available only parseVariable was tested thoroughly. The results of the program speak for the other parts of the Parser, as does the testing summary done with Emma [Emma]

\textbf{parseVariable}

Method syntax: parseVariable(File file, boolean isInteger, String toParse, HashMap<String, Variable> variableMapper, DistributionFactory fact)

Testing of this class can be done by running the ParserUnitTest class with correct parameters. Below is a list of tests that the class performs. Should there be an error, refer to the list below to see what goes wrong.


In the testing a functional \textit{DistributionFactory} is given to the method in every case.
The \textit{variableMapper} given should be an empty one in every case that does not involve parameter dependencies. To test dependencies we should add some variable names and variables there.
\textit{isInteger} should be tested with both \textit{true} and \textit{false} for all test cases.
The \textit{file} parameter is used only for error printing, it can be any file, or even null. Every case should print the given file name in the error messages.
What drives the tests here is what \textit{toParse} contains.
The test are performed with a Java class calling the separate methods with described parameters. For testing purposes the Parser has all methods publicly visible. 

Here's a table of the tests to be performed:

\begin{tabular}[]{| l | l | p{5cm} | p{7.0cm} |}
\hline
\textbf{case \#}&\textbf{isInteger}&\textbf{toParse}&\textbf{Expected result} \\
\hline
1 & false & `(som?erubbish)' & `In null: Invalid variable name on line 0' \\
\hline
2 & false & `alpha' & `In null: No column definition, expression or distribution found for variable on line 0' \\
\hline
3 & false & `alpha()' & `In null: Invalid column number on line 0' \\
\hline
4 & false & `alpha(10rub?bish )' & `In null: Invalid column number on line 0' \\
\hline
5 & false & `alpha(15.23)' & `In null: Invalid column number on line 0' \\
\hline
6 & false & `alpha(-1)' &  `In null: Invalid column number on line 0 (columns start at 1)' \\
\hline
7 & false & `alpha(2)' & A Variable with getName == alpha, isFunctional == false, column == 2, isInteger == false and isData == true. \\
\hline
8 & false & `alpha(*)' & A Variable with getName == alpha, isFunctional == false, column == -1, isInteger == false and isData == true. \\
\hline
9  & false & `alpha = 1.0' & A Variable with getName == alpha, isFunctional == true, isInteger == false, isData == false that has an equation with equation[0] == 1.0. \\
\hline
10 & true & `alpha = 1.0' & This is wrong, but the equation validity is not checked. Should return a Variable such as above but with isInteger = true.\\
\hline
11 & false & `alpha \char126' & An error about a missing distribution.\\
\hline
12 & false & `al3ph6a \char126 continuous\_uniform(' & `In null: Mismatching parentheses on line 0' \\
\hline
13 & false & `alpha98 \char126continuous\_uniform( )' & `In null: Too few parameters on line 0' \\
\hline
14 & false & `a4lpha \char126 continuous\_uniform( (v 1.8 )' & `In null: Parameter 1 on line 0 is not a decimal number or a correct variable name' \\
\hline
15 & false & `iota\char126 continuous\_uniform( 1.0)' & `In null: Too few parameters on line 0' \\
\hline
16 & false &`iota\char126 discrete\_uniform( 0, 1.0 )' & `In null: Parameter 2 on line 0 is not an integer or a correct variable name' \\
\hline
17 & false &`iota\char126 discrete\_uniform( 0, 1, 18)' & `In null: Too many parameters on line 0' \\
\hline
18 & false &`iota\char126 discrete\_uniform( gamma, 1)' & `In null: Parameter 1 on line 0 is not defined before it is used' \\
\hline
19 & false &`iota\char126 discrete\_uniform( gamma, 1)' & (First define gamma as a new Variable with isInteger == false and put it into variableMapper) `In null: Parameter 1 on line 0 is not of type INTEGER' \\
\hline
\end{tabular}

\begin{tabular}[]{| l | l | p{5cm} | p{7.0cm} |}
\hline
20 & false &`iota\char126 discrete\_uniform( gamma, 1)' & (First define gamma as a new Variable with isInteger == true and put it into variableMapper) A variable with isInteger == false, getName == iota, getDependsList().get(0) == gamma that has the distribution discrete\_uniform. \\
\hline
21 & false &   `iota\char126 continuous\_uniform ( gamma, 1.0)' & (with an empty variableMapper) `In null: Parameter 1 on line 0 is not defined before it is used' \\
\hline
22 & false &   `iota\char126 continuous\_uniform (gamma, 1.0)' & (First define gamma as a new Variable with isInteger == true and put it into variableMapper) A variable with isInteger == false, getName == `iota', getDependsList().get(0) == gamma that has the distribution continuous\_uniform. Note: INTEGERS are allowed as parameters for distributions that accept REALs. \\
\hline
23 & false & `iota\char126 continuous\_uniform (gamma, 1.0)' &  (First define gamma as a new Variable with isInteger == false and put it into variableMapper) A variable with getName() == `iota', isInteger == false, getDependsList().get(0) == gamma, getDistribution.getParameter(0) == gamma. \\
\hline
24 & false & `iota = COUNT (\&x) + 24*zeta' & `In null: `COUNT(\&varname)' must be the only element of an equation if it is used (line 0)' \\
\hline

25 & false & `iota = SUM (\&x) + 24*zeta' & `In null: `SUM(\&varname)' must be the only element of an equation if it is used (line 0)' \\
\hline

26 & false & iota = SUM (\&gamma) & The Parser's spatAffectedMap should now have the variable in it, and trying to find a Variable by the name from spatAffectedMap in variableMapper should return null (because we didn't define gamma). \\
\hline

27 & false & iota = SUM (\&gamma) & (First define gamma and put it into variableMapper) The Parser's spatAffectedMap should now have the variable in it, and trying to find a Variable by the name from spatAffectedMap in variableMapper should return the variable gamma. iota.getEquation().getEquation()[0] should be `SUM(\&' and iota.getEquation().getEquation()[1] == `gamma'. \\ 
\hline
\end{tabular}

\begin{tabular}[]{| l | l | p{5cm} | p{7.0cm} |}
\hline
28 & false & `iota = 24*zeta' & `In null: Variable 1 on line 0 is not defined before it is used' \\
\hline
29 & false & `iota = 28 * gamma * gamma *BLAH(24)' & (First define gamma as a new Variable with isInteger == true and put it into variableMapper) should return a Variable with getName() == `iota',  with the getEquation().getEquation() array: `28*', `gamma', `*', `gamma', `*BLAH(24)', with iota.getDependsList().get(0) == gamma and and gamma.getAffectsList().get(0) == iota. \\
\hline
\end{tabular}


The method parseVariable spans lines 359 through 678 in the Parser.
The method is divided up like this:


\begin{itemize}
\item 359-465 for general variable processing and data column reading
\item 466-595 for stochastic variables
\item 596-675 for functional variables
\item 676-678 are for returning the Variable constructed.
\end{itemize}

After tests 1-22 succeed, all branches to do with stochastic variables and general processing (361-593) have been tested.
Tests 23-29 test the functional variable branches (594-672) thoroughly.
After all tests (1-29) complete successfully, parseVariable has been tested with 100\% branch coverage.
