title: Bad interaction between a script and its tester
body: <p><strong>So I have this script I've written:</strong></p>
  
  <pre><code>public class Primes {
  public static void main(String[] args) {
  }
  //Part 4: Question 1
      public static int Binary2int(String b){
          int size = b.length();
          double count, sum=0;
          boolean binary = true;
  
          for (int i=0; i&lt;b.length() ; i++){
              int digit = b.charAt(i)-'0';
              if (digit&gt;1){
                  binary = false;
                  i=b.length();
              }
              count = digit*Math.pow(2, size-i-1);
              sum+=count;
          }
          if (!binary){
              System.out.println("Error - "+b+" is not a binary number.");
          }
          int sum1 = (int)sum;
          return sum1;
      }
      //Part 4: Question 2
      public static boolean isBinaryString(String b){
          boolean binary = true;
  
          for (int i=0; i&lt;b.length() ; i++){
              int digit = b.charAt(i)-'0';
              if (digit&gt;1){
                  binary = false;
                  i=b.length();
              }
          }
          return binary;
      }
      //Part 4: Question 3
      public static String int2Binary(int n){
          int count=0;
          if (n&lt;=0){
              count = 1;
          }
          for (int i=n; i&gt;0 ;){
              i=i/2;
              count++;
          }
  
          int arr[] = new int [count];
  
          for (int i=n, t=0; i&gt;0 ;t++){
              arr[arr.length-1-t] = i%2;
              i = i/2;
          }
          if (n&lt;=0){
              arr[0] = 0;
          }
          String s = Arrays.toString(arr);
  
          return s;
      }
  }
  </code></pre>
  
  <p><strong>4.1 is meant to take a string (which stands for a binary number) and then return an integer(which stands for the integer the binary number in the input represents).
  4.2 takes a binary number in the form of a string and then returns a Boolean variable (true if it’s a binary number and false if it isn’t).
  4.3 is doing the opposite of 4.1, it takes an integer in the form of an integer and returns the binary number that represents it in the form of a string.
  Oh and It all works fine when I'm testing it.
  Now the problem is that the one checking it will be using the following (type of)script:</strong></p>
  
  <pre><code>/**
   * This class represents a tester - to be used by students to check Ex3: &lt;br&gt;
   * 1. call all the public functions, check compilation. &lt;br&gt;
   * 2. test some of function of their results. &lt;br&gt; &lt;br&gt;
   * note: for debug change the printFlag to true.
   */
  public class BynaryTest {
  
      /**
       * if set to true - will print a trace of all the checks.
       */
      public static boolean printFlag = true;//false;
      /**
       * number of errors the test program found
       */
      public static int error = 0;
  
      /**
       * this main function runs the test of the EX3Tester class
       */
      public static void main(String[] a) {
          System.out.println("******* Testing Ex3 - print mode = " + printFlag + " ********");
          checkEx34();
          System.out.println();
          System.out.println("******* U have got " + error + " errors ********");
      }
  
      public static void checkEx34() {
          if (printFlag) {
              System.out.println("**** Cheking Ex21 ****");
          }
          int[] nums = {0, 1, 12345};
          for (int i = 0; i &lt; nums.length; i = i + 1) {
              String s = Primes.int2Binary(nums[i]);
              int num2 = Primes.Binary2int(s);
              if (nums[i] != num2) {
                  error++;
                  System.out.println("** Error in EX34:" + num2 + "!=" + nums[i] + " **");
              } else {
                  if (printFlag) {
                      System.out.println("num[" + i + "]=" + nums[i] + " binary: " + s + " .. ok");
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>The interaction between the two scripts does happen and nothing crashes, but then, for some reason, the only outcome I get from using it is:</strong></p>
  
  <pre><code>** Error in EX34:21!=0 **
  Error - [1] is not a binary number.
  ** Error in EX34:21!=1 **
  Error - [1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1] is not a binary number.
  ** Error in EX34:21!=12345 **
  
  ******* U have got 3 errors ********
  </code></pre>
  
  <p><strong>I've tried to fix it myself or finding out what causes that sort of unwanted outcome but I couldn't come up with anything :(</strong></p>