<commit_before>require_relative '../test_helper'

class ResourceGeneratorTest < Test::Unit::TestCase

  # Define test methods for each resource type
  FHIR::RESOURCES.each do | resourceType |    
    define_method("test_resource_generator_#{resourceType}") do
      run_generator(resourceType)
    end
  end

  # Also check to make sure that everything in the resource is within the DSTU2 namespace
  FHIR::DSTU2::RESOURCES.each do | resourceType |    
    define_method("test_resource_generator_dsut2_#{resourceType}") do
      resource = run_generator(resourceType, :dstu2)
      assert check_valid_namespaces(resource, 'FHIR::DSTU2'), "Resource Generator created a class of type FHIR::DSTU2::#{resourceType} that contained elements from the wrong version."
    end
  end

  def run_generator(resourceType, version = :stu3)

    klass_namespace = "FHIR"
    if version != :stu3
      klass_namespace = "FHIR::#{version.to_s.upcase}"
    end
    klass = Module.const_get("#{klass_namespace}::#{resourceType}")
    
    r = Crucible::Tests::ResourceGenerator.generate(klass,3)
    assert !r.nil?, "Resource Generator could not generate #{resourceType}"
    errors = r.validate
    assert errors.empty?, "Resource Generator could not generate valid #{resourceType}\n\n#{r.to_json}\n\nERRORS: #{errors}"
<commit_msg>Be more explicit with an argument in one of the tests.<commit_after>require_relative '../test_helper'

class ResourceGeneratorTest < Test::Unit::TestCase

  # Define test methods for each resource type
  FHIR::RESOURCES.each do | resourceType |    
    define_method("test_resource_generator_#{resourceType}") do
      run_generator(resourceType, :stu3)
    end
  end

  # Also check to make sure that everything in the resource is within the DSTU2 namespace
  FHIR::DSTU2::RESOURCES.each do | resourceType |    
    define_method("test_resource_generator_dsut2_#{resourceType}") do
      resource = run_generator(resourceType, :dstu2)
      assert check_valid_namespaces(resource, 'FHIR::DSTU2'), "Resource Generator created a class of type FHIR::DSTU2::#{resourceType} that contained elements from the wrong version."
    end
  end

  def run_generator(resourceType, version)

    klass_namespace = "FHIR"
    if version != :stu3
      klass_namespace = "FHIR::#{version.to_s.upcase}"
    end
    klass = Module.const_get("#{klass_namespace}::#{resourceType}")
    
    r = Crucible::Tests::ResourceGenerator.generate(klass,3)
    assert !r.nil?, "Resource Generator could not generate #{resourceType}"
    errors = r.validate
    assert errors.empty?, "Resource Generator could not generate valid #{resourceType}\n\n#{r.to_json}\n\nERRORS: #{errors}"

{'fraction_non_alphanumeric': 0.106071964017991, 'fraction_numerical': 0.006746626686656672, 'mean_word_length': 4.525879917184265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5612426', 'n_tokens_mistral': 811, 'n_tokens_neox': 804, 'n_words': 208}