<commit_before>require 'spec_helper'
require 'optimus_prime/transformers/validator'

RSpec.describe OptimusPrime::Transformers::Validator do
  let(:constraints) do
    {
      'level' => {
        type:  'range',
        values: [0, 100]
      },
      'score' => {
        type:  'greater_than_or_equal',
        values: [0]
      },
      'altitude' => {
        type:  'less_than_or_equal',
        values: [8888]
      },
      'character' => {
        type:   'set',
        values: ['tom', 'jerry']
      },
      'lorem' => {
        type:   'set',
        values: ['ipsum','dolor']
      }
    }
  end

  let(:logfile) { '/tmp/validator.log' }

  let(:validator) do
    validator = OptimusPrime::Transformers::Validator.new(constraints: constraints)
    validator.logger = Logger.new(logfile)
    validator
  end

  let(:input_legal) do
    [
      { 'character' => 'tom',   'level' => 92, 'score' => 220.5, 'altitude' => 5612 },
      { 'character' => 'jerry', 'level' => 73, 'score' => 211.2, 'altitude' => 4581 },
      { 'character' => 'jerry', 'level' => 22, 'score' => 111.2, 'altitude' => 2345 }
    ]
  end

  let(:input_illegal) do
    [
      { 'character' => 'tom',   'level' => 92, 'score' => 220.5, 'altitude' => 5612 },
      { 'character' => 'jermy', 'level' => -4, 'score' => -22.2, 'altitude' => 1000 },
      { 'character' => 'jerry', 'level' => 73, 'score' => 211.2, 'altitude' => 4581 }
    ]
  end<commit_msg>vrivia<commit_after>require 'spec_helper'
require 'optimus_prime/transformers/validator'

RSpec.describe OptimusPrime::Transformers::Validator do
  let(:constraints) do
    {
      'level' => {
        type:  'range',
        values: [0, 100]
      },
      'score' => {
        type:  'greater_than_or_equal',
        values: [0]
      },
      'altitude' => {
        type:  'less_than_or_equal',
        values: [8888]
      },
      'character' => {
        type:   'set',
        values: ['tom', 'jerry']
      },
      'lorem' => {
        type:   'set',
        values: ['ipsum', 'dolor']
      }
    }
  end

  let(:logfile) { '/tmp/validator.log' }

  let(:validator) do
    validator = OptimusPrime::Transformers::Validator.new(constraints: constraints)
    validator.logger = Logger.new(logfile)
    validator
  end

  let(:input_legal) do
    [
      { 'character' => 'tom',   'level' => 92, 'score' => 220.5, 'altitude' => 5612 },
      { 'character' => 'jerry', 'level' => 73, 'score' => 211.2, 'altitude' => 4581 },
      { 'character' => 'jerry', 'level' => 22, 'score' => 111.2, 'altitude' => 2345 }
    ]
  end

  let(:input_illegal) do
    [
      { 'character' => 'tom',   'level' => 92, 'score' => 220.5, 'altitude' => 5612 },
      { 'character' => 'jermy', 'level' => -4, 'score' => -22.2, 'altitude' => 1000 },
      { 'character' => 'jerry', 'level' => 73, 'score' => 211.2, 'altitude' => 4581 }
    ]
  end
{'fraction_non_alphanumeric': 0.19930313588850174, 'fraction_numerical': 0.046689895470383276, 'mean_word_length': 2.369718309859155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, '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': '2134654', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1031, 'n_words': 204}