<commit_before>require File.expand_path('../../spec_helper', __FILE__)

describe "Nice Password" do

  it "should raise Format Error if word count exceeds a threshold for decent generation" do
    lambda do
      NicePassword.new(:words => 6)
    end.should raise_error(NicePassword::FormatError)
  end

  describe "defaults" do

    it "should have the length of 12" do
      NicePassword.new.length.should == 12
    end

    it "should contain a two digit number" do
      digits = NicePassword.new.scan(/\d+/)
      digits.join.size.should == 2
    end

    it "should contain two words" do
      words = NicePassword.new.scan(/\D+/)
      words.size.should == 2
    end

  end

  describe "options" do

    it "should be able to specify length" do
      (6..20).each do |n|
        NicePassword.new(:length => n).length.should == n
      end
    end

    it "should be able to specify number of digits" do
      (1..5).each do |n|
        digits = NicePassword.new(:digits => n).scan(/\d+/)
        digits.join("").size.should == n
      end
    end

    it "should be able to specify number of words" do
      (2..4).each do |n|
        words = NicePassword.new(:words => n)
        words.scan(/\D+/).size.should == n
      end
    end
    
    it "should be able to specify the language"
    
    it "should be able to send an alternate dictionary"

  end

end<commit_msg>Tests for language and dictionary added<commit_after>require File.expand_path('../../spec_helper', __FILE__)

describe "Nice Password" do

  it "should raise Format Error if word count exceeds a threshold for decent generation" do
    lambda do
      NicePassword.new(:words => 6)
    end.should raise_error(NicePassword::FormatError)
  end

  describe "defaults" do

    it "should have the length of 12" do
      NicePassword.new.length.should == 12
    end

    it "should contain a two digit number" do
      digits = NicePassword.new.scan(/\d+/)
      digits.join.size.should == 2
    end

    it "should contain two words" do
      words = NicePassword.new.scan(/\D+/)
      words.size.should == 2
    end

  end

  describe "options" do

    it "should be able to specify length" do
      (6..20).each do |n|
        password = NicePassword.new(:length => n)
        password.length.should == n
      end
    end

    it "should be able to specify number of digits" do
      (1..5).each do |n|
        password = NicePassword.new(:digits => n)
        password.scan(/\d+/).join.size.should == n
      end
    end

    it "should be able to specify number of words" do
      (2..4).each do |n|
        password = NicePassword.new(:words => n)
        password.scan(/\D+/).size.should == n
      end
    end
    
    it "should be able to specify the language" do
      ['en', 'fr', 'sp'].each do |lang|
        yaml_file = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'nice_password', 'dictionaries', "#{lang}.yml")
        dictionary = YAML::load(File.open(yaml_file))
        
        password = NicePassword.new(:language => lang)
        password.scan(/\D+/).each do |word|
          dictionary.include?(word).should be_true
        end
      end
      
    end
    
    it "should be able to send an alternate dictionary" do
      dictionary = ['a', 'b', 'c', 'd', 'e', 'ax', 'be', 'co', 'do', 'em', 
        'art', 'bye', 'cat', 'doe', 'ear', 'aces', 'baby', 'cart', 'dove', 'even',
        'apple', 'boast', 'child', 'devil', 'eager',
        'aprons', 'bounce', 'chance', 'denied', 'easter',
        'approve', 'beneath', 'chiller', 'defined', 'evolves',
        'annotate', 'believes', 'children', 'destruct', 'eloquent',
        'appreciate', 'backbench', 'construct', 'deflected', 'everybody']
      password = NicePassword.new(:dictionary => dictionary)
      password.scan(/\D+/).each do |word|
        dictionary.include?(word).should be_true
      end
    end

  end

end
{'fraction_non_alphanumeric': 0.13924703455389376, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 2.3789198606271778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6875252', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1188, 'n_words': 380}