Skip to content

Commit

Permalink
Update topic-7-3 improved tests for 7.3.1.1 listForEachLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcdonnell2 authored Jul 30, 2024
1 parent 42d6424 commit 0b97f30
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions _sources/Unit7-ArrayList/topic-7-3-arraylist-loops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,54 @@ while looping over it, you’ll need to use a regular ``while`` or ``for`` loop.
public class RunestoneTests extends CodeTestHelper
{
@Test
public void testExpected() throws IOException
{
String output = getMethodOutput("main");
String expect = "100";
boolean passed = output.contains(expect);
getResults(expect, output, "Prints out sum", passed);
assertTrue(passed);
}
public void testExpected() throws IOException
{
String allOut = getMethodOutput("main");
String expect = "100";

String[] lines = allOut.split("\n");
String output = allOut;

for (String line: lines) {
if (line.contains("Sum") || line.contains(expect))
{
output = line;
break;
}
}

@Test
public void testProduct() throws IOException
{
String output = getMethodOutput("main");
String expect = "30000";
boolean passed = output.contains(expect);
getResults(expect, output, "Prints out product", passed);
assertTrue(passed);
}
boolean passed = output.contains(expect);

getResults(expect, output, "Prints out sum", passed);
assertTrue(passed);
}
@Test
public void testProduct() throws IOException
{
String allOut = getMethodOutput("main");
String expect = "30000";

String[] lines = allOut.split("\n");
String output = allOut;

for (String line: lines) {
if (line.contains("Product") || line.contains(expect))
{
output = line;
break;
}
}

boolean passed = output.contains(expect);

int numZeros = countOccurences(output.substring(output.indexOf("3")), "0");

if (numZeros != 4)
passed = false;

getResults(expect, output, "Prints out product", passed);
assertTrue(passed);
}

@Test
public void countForLoops()
Expand Down

0 comments on commit 0b97f30

Please sign in to comment.