<commit_before>require 'minitest/autorun'
require_relative '../test_utils'

def fmt x,t
#--------------
  def j l, t
    n=t.delete(' ').size
    c=t.split.size-1
    x,y=t.split ' ',2
    return x if c<1
    whitespace_width=((l.to_f-n)/c).ceil
    d=x+' '*whitespace_width
    d+j(l-d.size,y)
  end
  w=t.split /(-| )/
  l=[]
  c=""
  while w.any?
    d,s=w.shift 2
    n=c.dup.chomp(?-)+d+(s||"")
    if n.strip.size>x
      l<<j(x,c)
      c=""
      w.unshift d,s
    else
      c=n
    end
  end
  l<<c
#--------------
end


describe :Justification do<commit_msg>More one letter vars + justify as a lambda<commit_after>require 'minitest/autorun'
require_relative '../test_utils'

def fmt m,t
#--------------
  j=->(l,t){
    n=t.delete(' ').size
    c=t.split.size-1
    x,y=t.split ' ',2
    return x if c<1
    w=((l.to_f-n)/c).ceil
    d=x+' '*w
    d+j[l-d.size,y]
  }
  w=t.split /(-| )/
  l=[]
  c=""
  while w.any?
    d,s=w.shift 2
    n=c.dup.chomp(?-)+d+(s||"")
    if n.strip.size>m
      l<<j[m,c]
      c=""
      w.unshift d,s
    else
      c=n
    end
  end
  l<<c
#--------------
end


describe :Justification do
{'fraction_non_alphanumeric': 0.239647577092511, 'fraction_numerical': 0.007048458149779736, 'mean_word_length': 1.8049382716049382, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 6, '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': '6440569', 'n_tokens_mistral': 523, 'n_tokens_neox': 517, 'n_words': 98}