title: One test fails, how to fix this?
body: <p>I have tried many times to fix the failure from the method <code>void sameNumbers()</code> and still I have not found a solution. </p>
  
  <p>The Junit failures:
  <a href="https://i.stack.imgur.com/QKLb5.png" rel="nofollow noreferrer">junit output</a></p>
  
  <p>The problem is, when the first array is <code>[1]</code> and the second one is <code>[0, 1]</code> it returns <code>true</code>, instead of <code>false</code>.</p>
  
  <p>Can someone please explain and help me to fix this ? </p>
  
  <p>Thank you.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class SameNumbers {
  
      public static boolean sameNumbers(int[] values1, int[] values2) {
  
          Arrays.sort(values1);
          Arrays.sort(values2);
          boolean found = false;
  
          if (values1.length == 0 &amp;&amp; values2.length == 0) {
              found = true;
          } else if (values1.length == 0 &amp;&amp; values2.length &gt; 0 || values1.length &gt; 0 &amp;&amp; values2.length == 0) {
              found = false;
          } else if (Arrays.equals(values1, values2)) {
              found = true;
          } else if (values1.length &gt; 0 &amp;&amp; values2.length &gt; 1 || values1.length &gt; 1 &amp;&amp; values2.length &gt; 0) {
              for (int i = 0; i &lt; values1.length; i++) {
                  for (int k = 0; k &lt; values2.length; k++) {
                      if (values1[i] == values2[k]) {
                          found = true;
                      } else {
                          found = false;
                      }
                  }
              }
  
          }
  
          return found;
  
      }
  }
  </code></pre>
  
  <pre><code>class SameNumbersTest {
  
      static final int nbrTests = 20;
      private Random random = new Random();
  
      @Test
      void sameNumbers1() {
          Assertions.assertEquals(true, SameNumbers.sameNumbers(new int[] {}, new int[] {}),
                  "SameNumbers.sameNumbers(new int[]{}, new int[]{})");
      }
  
      @Test
      void sameNumbers2() {
          for (int i = 0; i &lt; nbrTests; i++) {
              int r = random.nextInt(20);
              Assertions.assertFalse(SameNumbers.sameNumbers(new int[] {}, new int[] { r }),
                      "SameNumbers.sameNumbers(new int[]{}, new int[]{r})");
              Assertions.assertFalse(SameNumbers.sameNumbers(new int[] { r }, new int[] {}),
                      "SameNumbers.sameNumbers(new int[]{r}, new int[]{})");
              Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { r }, new int[] { r }),
                      "SameNumbers.sameNumbers(new int[]{r}, new int[]{r})");
          }
      }
  
      @Test
      void sameNumbers3() {
          for (int i = 0; i &lt; nbrTests; i++) {
              int r = random.nextInt(20);
              if (r != 1) {
                  Assertions.assertFalse(SameNumbers.sameNumbers(new int[] { 1 }, new int[] { r, 1 }),
                          "SameNumbers.sameNumbers(new int[]{1}, new int[]{r, 1})");
                  Assertions.assertFalse(SameNumbers.sameNumbers(new int[] { r, 1 }, new int[] { 1 }),
                          "SameNumbers.sameNumbers(new int[]{r, 1}, new " + "int[]{1})");
              } else {
                  Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { 1 }, new int[] { r, 1 }),
                          "SameNumbers.sameNumbers(new int[]{1}, new int[]{r, 1})");
                  Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { r, 1 }, new int[] { 1 }),
                          "SameNumbers.sameNumbers(new int[]{r, 1}, new int[]{1})");
              }
          }
      }
  
      @Test
      void sameNumbers4() {
          Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { 1, 2, 3 }, new int[] { 3, 2, 1 }),
                  "SameNumbers.sameNumbers(new int[]{1, 2, 3}, new int[]{3, 2, 1})");
          Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { 1, 2, 3 }, new int[] { 3, 3, 2, 1 }),
                  "SameNumbers.sameNumbers(new int[]{1, 2, 3}, new int[]{3, 3, 2, 1})");
          Assertions.assertFalse(SameNumbers.sameNumbers(new int[] { 1, 2, 3 }, new int[] { 3, 4, 2, 1 }),
                  "ameNumbers.sameNumbers(new int[]{1, 2, 3}, new int[]{3, 4, 2, 1})");
          Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { 1, 2 }, new int[] { 2, 1, 1 }),
                  "SameNumbers.sameNumbers(new int[]{1, 2}, new int[]{2, 1, 1})");
          Assertions.assertTrue(SameNumbers.sameNumbers(new int[] { 1, 2, 2 }, new int[] { 2, 1, 1 }),
                  "SameNumbers.sameNumbers(new int[]{1, 2, 2}, new int[]{2, 1, 1})");
      }
  
  }
  </code></pre>