<commit_before>/*
 * $Id$
 */
package org.xins.tests.common.specs;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.xins.specs.APISpec;
import org.xins.specs.FunctionSpec;
import org.xins.specs.InputParamSpec;
import org.xins.specs.InvalidNameException;
import org.xins.specs.InvalidVersionException;

/**
 * Tests for class <code>InputParamSpec</code>.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 */
public class InputParamSpecTests extends TestCase {

   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   /**
    * Returns a test suite with all test cases defined by this class.
    *
    * @return
    *    the test suite, never <code>null</code>.
    */
   public static Test suite() {
      return new TestSuite(InputParamSpecTests.class);
   }


   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructor
   //-------------------------------------------------------------------------

   /**
    * Constructs a new <code>InputParamSpecTests</code> test suite with
    * the specified name. The name will be passed to the superconstructor.
    *
    * @param name
    *    the name for this test suite.
    */
   public InputParamSpecTests(String name) {
      super(name);
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Performs setup for the tests.
    */
   protected void setUp() {
      // empty
   }

   public void testInputParamSpec_java_lang_String__java_lang_String() throws Throwable {

      APISpec      api = new APISpec("api", "1.0");
      FunctionSpec fnc = new FunctionSpec(api, "Function", "1.0");
      InputParamSpec spec;

      // Test null arguments
      int argCount = 2;
      int combinations = 3; // (2 ** 2) - 1
      for (int i = 0; i < combinations; i++) {
         boolean arg1 = (i & 1) > 0;
         boolean arg2 = (i & 2) > 0;
         try {
            spec = new InputParamSpec(
               (arg1 ? fnc    : null),
               (arg2 ? "type" : null)
            );
            fail("InputParamSpec() should throw an IllegalArgumentException. Configuration: "
                 + (arg1 ? "non-null" : "null") + ", "
                 + (arg2 ? "non-null" : "null") + '.');
         } catch (IllegalArgumentException iae) { /* as expected */ }
      }

      // Test invalid names
      String[] invalidNames = new String[] {
         "",         "TYP",  "TYp"  ,   "Typ",    "typ_", "_typ",
         "typ.",     ".typ", "typ.typ", "typ.ty", "1",    "ty_pe",
         "typ-typ", "-typ", "typ-",     "ty_p",   "typ--typ"
      };
      for (int i = 0; i < invalidNames.length; i++) {
         try {
            String name = invalidNames[i];
            spec = new InputParamSpec(fnc, name);
            fail("InputParamSpec(FunctionSpec, \"" + name + "\") should throw an InvalidNameException.");
         } catch (InvalidNameException ine) { /* as expected */ }
      }

      // Test valid constructions
      String[] names = new String[] {
         "type", "someType", "someType2", "some2", "s", "s2", "typeAB"};
      for (int i = 0; i < names.length; i++) {
         String name = names[i];
         spec = new InputParamSpec(fnc, name);
      }
   }
<commit_msg>Changed to match new InputParamSpec constructor.<commit_after>/*
 * $Id$
 */
package org.xins.tests.common.specs;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.xins.specs.APISpec;
import org.xins.specs.FunctionSpec;
import org.xins.specs.InputParamSpec;
import org.xins.specs.InvalidNameException;
import org.xins.specs.InvalidVersionException;
import org.xins.specs.TypeSpec;

/**
 * Tests for class <code>InputParamSpec</code>.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 */
public class InputParamSpecTests extends TestCase {

   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   /**
    * Returns a test suite with all test cases defined by this class.
    *
    * @return
    *    the test suite, never <code>null</code>.
    */
   public static Test suite() {
      return new TestSuite(InputParamSpecTests.class);
   }


   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructor
   //-------------------------------------------------------------------------

   /**
    * Constructs a new <code>InputParamSpecTests</code> test suite with
    * the specified name. The name will be passed to the superconstructor.
    *
    * @param name
    *    the name for this test suite.
    */
   public InputParamSpecTests(String name) {
      super(name);
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Performs setup for the tests.
    */
   protected void setUp() {
      // empty
   }

   public void testInputParamSpec_java_lang_String__java_lang_String() throws Throwable {

      APISpec      api = new APISpec("api", "1.0");
      FunctionSpec fnc = new FunctionSpec(api, "Function", "1.0");
      TypeSpec     typ = new TypeSpec(api, "type", "1.0");
      InputParamSpec spec;

      // Test null arguments
      int argCount = 3;
      int combinations = 7; // (2 ** 3) - 1
      for (int i = 0; i < combinations; i++) {
         boolean arg1 = (i & 1) > 0;
         boolean arg2 = (i & 2) > 0;
         boolean arg3 = (i & 4) > 0;
         try {
            spec = new InputParamSpec(
               (arg1 ? fnc    : null),
               (arg2 ? "par"  : null),
               (arg3 ? typ    : null),
               false
            );
            fail("InputParamSpec() should throw an IllegalArgumentException. Configuration: "
                 + (arg1 ? "non-null" : "null") + ", "
                 + (arg2 ? "non-null" : "null") + ", "
                 + (arg3 ? "non-null" : "null") + ", false.");
         } catch (IllegalArgumentException iae) { /* as expected */ }
      }

      // Test invalid names
      String[] invalidNames = new String[] {
         "",         "TYP",  "TYp"  ,   "Typ",    "typ_", "_typ",
         "typ.",     ".typ", "typ.typ", "typ.ty", "1",    "ty_pe",
         "typ-typ", "-typ", "typ-",     "ty_p",   "typ--typ"
      };
      for (int i = 0; i < invalidNames.length; i++) {
         try {
            String name = invalidNames[i];
            spec = new InputParamSpec(fnc, name, typ, false);
            fail("InputParamSpec(FunctionSpec, \"" + name + "\") should throw an InvalidNameException.");
         } catch (InvalidNameException ine) { /* as expected */ }
      }

      // Test valid constructions
      String[] names = new String[] {
         "type", "someType", "someType2", "some2", "s", "s2", "typeAB"};
      for (int i = 0; i < names.length; i++) {
         String name = names[i];
         spec = new InputParamSpec(fnc, name, typ, false);
         spec = new InputParamSpec(fnc, name, typ, true);
      }
   }

{'fraction_non_alphanumeric': 0.30081101007618577, 'fraction_numerical': 0.007249938559842713, 'mean_word_length': 1.2003244120032441, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6540111', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2099, 'n_words': 552}