/**
   * Tests sequentialMint to see if it will produce the correct length of Pids at an arbitrary
   * starting value.
   *
   * @param prefix A sequence of characters that appear in the beginning of PIDs
   * @param sansVowel Dictates whether or not vowels are allowed
   * @param tokenType An enum used to configure PIDS
   * @param rootLength Designates the length of the id's root
   * @param amount The number of PIDs to be created
   */
  @Test(dataProvider = "rootLength")
  public void testSequentialRootLengthWithStartingValue(
      String prefix, boolean sansVowel, Token tokenType, int rootLength, int amount) {

    // store parameters in a setting object
    Setting setting = new Setting(prefix, tokenType, null, rootLength, sansVowel);

    // create a new minter and create a set
    AutoIdGenerator generator = new AutoIdGenerator(prefix, tokenType, rootLength);
    int startingValue = amount / 2;
    Set<Pid> sequentialSet = generator.sequentialMint(amount, startingValue);

    int counter = 0;
    Pid prev = null;
    Iterator<Pid> iter = sequentialSet.iterator();
    while (iter.hasNext()) {
      // fail if the length does not match
      Pid current = iter.next();
      PID_TEST.testRootLength(current.getName(), setting);

      if (prev != null && counter != startingValue) {
        PID_TEST.testOrder(prev, current);
      }

      counter++;
      prev = current;
    }

    // test to see if the amount matches the size of the generated set
    Assert.assertEquals(sequentialSet.size(), amount);
  }
  /**
   * Tests to see if the sequentialMint method will print the desired prefix
   *
   * @param prefix A sequence of characters that appear in the beginning of PIDs
   * @param sansVowel Dictates whether or not vowels are allowed
   * @param tokenType An enum used to configure PIDS
   * @param rootLength Designates the length of the id's root
   * @param amount The number of PIDs to be created
   */
  @Test(dataProvider = "prefix")
  public void testSequentialMintPrefix(
      String prefix, boolean sansVowel, Token tokenType, int rootLength, int amount) {
    // store parameters in a setting object
    Setting setting = new Setting(prefix, tokenType, null, rootLength, sansVowel);
    IdGenerator generator = new AutoIdGenerator(prefix, tokenType, rootLength);
    Set<Pid> sequentialSet = generator.sequentialMint(amount);

    Pid prev = null;
    Iterator<Pid> iter = sequentialSet.iterator();
    while (iter.hasNext()) {
      // fail if the length does not match
      Pid current = iter.next();
      PID_TEST.testPrefix(current.getName(), setting);

      if (prev != null) {
        PID_TEST.testOrder(prev, current);
      }

      prev = current;
    }

    // test to see if the amount matches the size of the generated set
    Assert.assertEquals(sequentialSet.size(), amount);
  }
  /**
   * Tests AutoIdGenerator for the presence of vowels through the randomMint method
   *
   * @param prefix A sequence of characters that appear in the beginning of PIDs
   * @param sansVowel Dictates whether or not vowels are allowed
   * @param tokenType An enum used to configure PIDS
   * @param rootLength Designates the length of the id's root
   * @param amount The number of PIDs to be created
   */
  @Test(dataProvider = "sansVowel")
  public void testRandomMintSansVowels(
      String prefix, boolean sansVowel, Token tokenType, int rootLength, int amount) {
    // store parameters in a setting object
    Setting setting = new Setting(prefix, tokenType, null, rootLength, sansVowel);
    IdGenerator generator = new AutoIdGenerator(prefix, tokenType, rootLength);
    Set<Pid> randomSet = generator.randomMint(amount);

    for (Pid id : randomSet) {
      PID_TEST.testTokenType(id.getName(), setting);
    }
    // test to see if the amount matches the size of the generated set
    Assert.assertEquals(randomSet.size(), amount);
  }
Exemple #4
0
  /**
   * Term comparison method
   *
   * @return true if the input Term is equal to the object, false otherwize
   */
  public boolean equal(Term _any) {

    try {

      /* Pids */
      if ((PidV != null) && (_any.PidV != null)) if (PidV.equal(_any.PidV)) return true;

      /* Refs */
      if ((RefV != null) && (_any.RefV != null)) if (RefV.equal(_any.RefV)) return true;

      /* Ports */
      if ((PortV != null) && (_any.PortV != null)) if (PortV.equals(_any.PortV)) return true;

      /* strings */
      if ((stringV != null) && (_any.stringV != null))
        if (stringV.equals(_any.stringV)) return true;

      /* atoms and booleans */
      if ((atomV != null) && (_any.atomV != null)) if (atomV.equals(_any.atomV)) return true;

      /* booleans */
      if (atomV != null) if (_any.booleanV == Boolean.valueOf(atomV).booleanValue()) return true;

      if (_any.atomV != null)
        if (booleanV == Boolean.valueOf(_any.atomV).booleanValue()) return true;

      /* integer types plus floating point types */
      double _ownNS = longV + doubleV;

      double _othersNS = _any.longV + _any.doubleV;

      if ((equal(_ownNS, _othersNS)) && (!equal(_ownNS, 0))) return true;

      /* All together, 0 or false */
      if ((equal(_ownNS, _othersNS)) && booleanV == _any.booleanV) return true;

      return false;

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }