Note that there are some explanatory texts on larger screens.

plurals
  1. POerror while running function
    primarykey
    data
    text
    <p>Hi im trying to run my function and test it thought the junit test but i can't figure out why my junit tests are failing. im sure that the function that i wrote works. This is homework if anyone is wondering . </p> <p>here is the test </p> <pre><code>@Test public void test4() { lst1.removeAll(3); assertEquals(8, lst1.size()); assertEquals(false, lst1.contains(3)); lst1.removeAll(6); assertEquals(5, lst1.size()); assertEquals(false, lst1.contains(6)); lst1.removeAll(5); assertEquals(3, lst1.size()); lst1.removeAll(4); assertEquals(2, lst1.size()); lst1.removeAll(7); assertEquals(1, lst1.size()); lst1.removeAll(8); assertEquals(0, lst1.size()); } </code></pre> <p>here is the code </p> <pre><code>public void removeAll( E x ) { first = first.next; if (first.data == x ) { first = first.next; } Node curr = first; Node fut = curr.next ; while ( fut!= null) { if (fut.data == x ) { curr.next = fut.next; } curr=curr.next; fut=fut.next; } assert check(); } </code></pre> <p>set up of the junit </p> <pre><code>public class MyListTest { private MyList&lt;Integer&gt; lst0; private MyList&lt;Integer&gt; lst1; private Integer[] a; @Before public void setUp() throws Exception { lst0 = new MyList&lt;Integer&gt;(); a = new Integer[] {3,4,3,5,6,8,6,6,7,5}; lst1 = new MyList&lt;Integer&gt;(); for(Integer x: a) { lst1.add(x); } } </code></pre> <p>Size method</p> <pre><code>public int size() { return sz; } </code></pre> <p>Main method </p> <pre><code>public class MyList&lt;E extends Comparable&lt; E&gt;&gt; implements Iterable&lt;E&gt; { private Node first; private int sz; public MyList() { first = null; sz = 0; assert check(); } } </code></pre> <p>check method </p> <pre><code>private boolean check() { if (first == null &amp;&amp; sz != 0) return false; if (sz == 0 &amp;&amp; first != null) return false; if (sz == 1 &amp;&amp; (first == null || first.next != null)) return false; if (sz &gt; 1 &amp;&amp; (first == null || first.next == null)) return false; int count = 0; Node p = first; while(p != null) { count++; p = p.next; } if (count != sz) { System.out.printf("count = %d, sz = %d\n", count, sz); return false; } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload