Logo Search packages:      
Sourcecode: jlex version File versions  Download package

static void JLex::SparseBitSet::main ( String[]  args  )  [inline, static]

Self-test.

Definition at line 7766 of file Main.java.

References and(), clear(), clearAll(), clone(), equals(), get(), or(), set(), size, SparseBitSet(), and xor().

                                           {
      final int ITER = 500;
      final int RANGE= 65536;
      SparseBitSet a = new SparseBitSet();
      CUtility.ASSERT(!a.get(0) && !a.get(1));
      CUtility.ASSERT(!a.get(123329));
      a.set(0); CUtility.ASSERT(a.get(0) && !a.get(1));
      a.set(1); CUtility.ASSERT(a.get(0) && a.get(1));
      a.clearAll();
      CUtility.ASSERT(!a.get(0) && !a.get(1));
      java.util.Random r = new java.util.Random();
      java.util.Vector v = new java.util.Vector();
      for (int n=0; n<ITER; n++) {
          int rr = ((r.nextInt()>>>1) % RANGE) << 1;
          a.set(rr); v.addElement(new Integer(rr));
          // check that all the numbers are there.
          CUtility.ASSERT(a.get(rr) && !a.get(rr+1) && !a.get(rr-1));
          for (int i=0; i<v.size(); i++)
            CUtility.ASSERT(a.get(((Integer)v.elementAt(i)).intValue()));
      }
      SparseBitSet b = (SparseBitSet) a.clone();
      CUtility.ASSERT(a.equals(b) && b.equals(a));
      for (int n=0; n<ITER/2; n++) {
          int rr = (r.nextInt()>>>1) % v.size();
          int m = ((Integer)v.elementAt(rr)).intValue();
          b.clear(m); v.removeElementAt(rr);
          // check that numbers are removed properly.
          CUtility.ASSERT(!b.get(m));
      }
      CUtility.ASSERT(!a.equals(b));
      SparseBitSet c = (SparseBitSet) a.clone();
      SparseBitSet d = (SparseBitSet) a.clone();
      c.and(a);
      CUtility.ASSERT(c.equals(a) && a.equals(c));
      c.xor(a);
      CUtility.ASSERT(!c.equals(a) && c.size()==0);
      d.or(b);
      CUtility.ASSERT(d.equals(a) && !b.equals(d));
      d.and(b);
      CUtility.ASSERT(!d.equals(a) && b.equals(d));
      d.xor(a);
      CUtility.ASSERT(!d.equals(a) && !b.equals(d));
      c.or(d); c.or(b);
      CUtility.ASSERT(c.equals(a) && a.equals(c));
      c = (SparseBitSet) d.clone();
      c.and(b);
      CUtility.ASSERT(c.size()==0);
      System.out.println("Success.");
    }


Generated by  Doxygen 1.6.0   Back to index