// FILE. . . . . d:/hak/hlt/src/hlt/fot/fuz/test/Test.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hak-Laptop
// STARTED ON. . Sat Aug 11 06:32:30 2018

// Last modified on Sun Aug 12 04:57:56 2018 by hak

// This is to test the notion of "index" used in in
// hlt.language.util.SetOf (method "indexof(Object)".  Is it the order
// in which the "Indexed" object is created that gives it its index?
// Then, this is also the index in the AbstractList "base" that contains
// all possible elements, each at its index.

// public final int indexOf (Object object)
// {
//   if (object instanceof Indexed)    // WARNING: this works only if
//     return ((Indexed)object).index; // index is the position in base 
//
//   return base.indexOf(object);
// }

// In the object is not an Indexed instance, the base index is returned.

import hlt.language.util.SetOf;
import hlt.language.util.ArrayList;

public class Test
{
  public static void main (String[] args)
  {
    int testLength = 6;
    
    // A: testing one possible with Integer objects.

    ArrayList intObjects = new ArrayList();
    for (int i=0; i<testLength; i++)
      intObjects.set(i,Integer.valueOf(i+1));

    SetOf intObjectSet = new SetOf(intObjects);

    System.out.println("Initial reference list set A: "+intObjects);
    System.out.println();
    System.out.println("Initial object set reference A: "+intObjectSet.top());
    System.out.println();
    System.out.println("Initial empty object set A: "+intObjectSet);
    System.out.println();

    for (int i=0; i<intObjects.size(); i++)
      intObjectSet.add(Integer.valueOf(i+1));

    System.out.println("Final reference list set A: "+intObjects);
    System.out.println();
    System.out.println("Final object set reference A: "+intObjectSet.top());
    System.out.println();
    System.out.println("Final full object set A: "+intObjectSet);

    System.out.println("\n------------------------------------------------------\n");

    // B: testing another possible with Integer objects.

    intObjects = new ArrayList();
    intObjectSet = new SetOf(intObjects);

    System.out.println("Initial reference list set B: "+intObjects);
    System.out.println();
    System.out.println("Initial object set reference B: "+intObjectSet.top());
    System.out.println();
    System.out.println("Initial empty Object set B: "+intObjectSet);
    System.out.println();

    for (int i=0; i<testLength; i++)
      {
	intObjects.set(i,Integer.valueOf(i+1)); // updates the set's data ArrayList!
	intObjectSet.add(Integer.valueOf(i+1));
      }

    System.out.println("Final reference list set B: "+intObjects);
    System.out.println();
    System.out.println("Final object set reference B: "+intObjectSet.top());
    System.out.println();
    System.out.println("Final full object set B: "+intObjectSet);

    System.out.println("\n------------------------------------------------------\n");
    System.out.println("no runtime error as it explicitly updates the ArrayList intObjects");
    System.out.println("so that when adding an equal Integer, indexOf on it in will find it...");
    System.out.println("but Final object set reference is always empty! This is calling for trouble later!!!");
    System.out.println("\n------------------------------------------------------\n");

    // C: testing another possible with Integer objects.

    intObjects = new ArrayList();
    intObjectSet = new SetOf(intObjects);

    System.out.println("Initial reference list set C: "+intObjects);
    System.out.println();
    System.out.println("Initial object set reference C: "+intObjectSet.top());
    System.out.println();
    System.out.println("Initial empty Object set C: "+intObjectSet);

    for (int i=0; i<testLength; i++)
      intObjectSet.add(Integer.valueOf(i+1));

    System.out.println("\n------------------------------------------------------\n");
    System.out.println("this raises a java.lang.IndexOutOfCoundsException: bitIndex < 0: -1");
    System.out.println("as this will try to set bit number -1 since indexOf(Integer(1)) = -1");
    System.out.println("to indicate that this object is not in the reference set (which is empty!)");
    System.out.println("\n------------------------------------------------------\n");

    System.out.println("Final reference list set C: "+intObjects);
    System.out.println();
    System.out.println("Final object set reference C: "+intObjectSet.top());
    System.out.println();
    System.out.println("Final full object set C: "+intObjectSet);

  }
}
