<commit_before># encoding: utf-8
load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )

RSpec::Matchers.define :be_visibility do | distance, direction, comparator |
  match do | visibility |
    if    visibility.nil? && [ distance, direction, comparator ].all?( &:nil? )
      true
    elsif visibility.nil? != [ distance, direction, comparator ].all?( &:nil? )
      false
    elsif visibility.distance.nil?   != distance.nil?
      false
    elsif visibility.direction.nil?  != direction.nil?
      false
    elsif visibility.comparator.nil? != comparator.nil?
      false
    elsif visibility.distance.is_a?( Metar::Distance ) && (visibility.distance.value - distance).abs > 0.01
      false
    elsif visibility.direction.is_a?( M9t::Direction ) && (visibility.direction.value - direction).abs > 0.01
      false
    elsif comparator.is_a?( Symbol )                   && visibility.comparator != comparator
      false
    else
      true
    end
  end
end

describe Metar::Visibility do

  context '.parse' do

    [
      [ 'understands 9999',          '9999',    [ 10000.00, nil,   :more_than ] ],
      [ 'understands nnnn + NDV',    '0123NDV', [   123.00, nil,   nil ] ],
      [ 'understands n/nSM',         '3/4SM',   [  1207.01, nil,   nil ] ],
      [ 'understands n n/nSM',       '1 1/4SM', [  2011.68, nil,   nil ] ],
      [ 'understands nSM',           '5SM',     [  8046.72, nil,   nil ] ],
      [ 'understands M1/4SM',        'M1/4SM',  [   402.34, nil,   :less_than ] ],
      [ 'understands n + KM',        '5KM',     [  5000.00, nil,   nil ] ],
      [ 'understands n',             '500',     [   500.00, nil,   nil ] ],
      [ 'understands n + compass',   '500NW',   [   500.00, 315.0,        nil ] ],
      [ 'returns nil for unmatched', 'FUBAR',   [      nil,   nil,        nil ] ],
    ].each do | docstring, raw, expected |
      example docstring do
        Metar::Visibility.parse( raw ).should be_visibility( *expected )<commit_msg>A specific example of visibility 3/16<commit_after># encoding: utf-8
load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )

RSpec::Matchers.define :be_visibility do | distance, direction, comparator |
  match do | visibility |
    if    visibility.nil? && [ distance, direction, comparator ].all?( &:nil? )
      true
    elsif visibility.nil? != [ distance, direction, comparator ].all?( &:nil? )
      false
    elsif visibility.distance.nil?   != distance.nil?
      false
    elsif visibility.direction.nil?  != direction.nil?
      false
    elsif visibility.comparator.nil? != comparator.nil?
      false
    elsif visibility.distance.is_a?( Metar::Distance ) && (visibility.distance.value - distance).abs > 0.01
      false
    elsif visibility.direction.is_a?( M9t::Direction ) && (visibility.direction.value - direction).abs > 0.01
      false
    elsif comparator.is_a?( Symbol )                   && visibility.comparator != comparator
      false
    else
      true
    end
  end
end

describe Metar::Visibility do

  context '.parse' do

    [
      [ 'understands 9999',          '9999',    [ 10000.00, nil,   :more_than ] ],
      [ 'understands nnnn + NDV',    '0123NDV', [   123.00, nil,   nil ] ],
      [ 'understands n/nSM',         '3/4SM',   [  1207.01, nil,   nil ] ],
      [ 'understands 3/16SM',        '3/16SM',  [  301.752, nil,   nil ] ],
      [ 'understands n n/nSM',       '1 1/4SM', [  2011.68, nil,   nil ] ],
      [ 'understands nSM',           '5SM',     [  8046.72, nil,   nil ] ],
      [ 'understands M1/4SM',        'M1/4SM',  [   402.34, nil,   :less_than ] ],
      [ 'understands n + KM',        '5KM',     [  5000.00, nil,   nil ] ],
      [ 'understands n',             '500',     [   500.00, nil,   nil ] ],
      [ 'understands n + compass',   '500NW',   [   500.00, 315.0,        nil ] ],
      [ 'returns nil for unmatched', 'FUBAR',   [      nil,   nil,        nil ] ],
    ].each do | docstring, raw, expected |
      example docstring do
        Metar::Visibility.parse( raw ).should be_visibility( *expected )
{'fraction_non_alphanumeric': 0.149581074420897, 'fraction_numerical': 0.049038935436175456, 'mean_word_length': 2.1392111368909514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4412928', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1326, 'n_words': 321}