<commit_before>require_relative 'helper'
require_relative '../lib/rudbms/file/block'

class TestBlock < MiniTest::Unit::TestCase

  def setup
    @filename = 'alpha'
    @block_number = 1
    @as_string = "[file #{@filename}, block #{@block_number}]"
  end

  def test_must_initialize_with_filename_and_block_number
    assert_raises(ArgumentError) do
      Block.new
    end
    assert Block.new(@filename, @block_number), 'Could not instantiate Block with two params'
  end

  def test_should_have_filename_attribute
    b = Block.new(@filename, @block_number)
    assert_respond_to(b, :filename, 'Missing attr accessor for filename.')
  end

  def test_should_have_block_number_attribute
    b = Block.new(@filename, @block_number)
    assert_respond_to(b, :block_number, 'Missing attr accessor for block number.')
  end

  def test_constructor_should_assign_passed_filname_and_block_number
    filename = 'alpha'
    block_num = 1
    b = Block.new(@filename, @block_number)
    assert_equal(@filename, b.filename, 'Filename does not match initialized value.')
    assert_equal(@block_number, b.block_number, 'Block number does not match initialized value.')
  end

  def test_should_have_number_attribute_that_returns_block_number
    b = Block.new(@filename, @block_number)
    assert_respond_to(b, :number, 'Missing attr accessor for number.')
    assert_equal(b.block_number, b.number, 'Block number does not match initialized value.')    
  end

  def test_string_representation
    b = Block.new(@filename, @block_number)
    assert_equal(@as_string, b.to_s, 'String representation of Block incorrect.')
  end

  def test_blocks_with_differing_filename_or_block_number_should_not_be_considered_equal
    b = Block.new(@filename, @block_number)
    b2 = Block.new(@filename + "foo", @block_number + 1)
    b3 = Block.new(@filename + "foo", @block_number)
    b4 = Block.new(@filename, @block_number + 1)
    refute_equal(b, b2)
    refute_equal(b, b3)
    refute_equal(b, b4)
  end

  def test_blocks_with_same_filename_and_block_number_should_be_considered_equal
    b = Block.new(@filename, @block_number)
    b2 = Block.new(@filename, @block_number)
    assert_equal(b, b2)
  end

end<commit_msg>Refactoring Block test. [ci skip]<commit_after>require_relative 'helper'
require_relative '../lib/rudbms/file/block'

class TestBlock < MiniTest::Unit::TestCase

  def setup
    @filename = 'alpha'
    @block_number = 1
    @as_string = "[file #{@filename}, block #{@block_number}]"
    @default_block = Block.new(@filename, @block_number)
  end

  def test_must_initialize_with_filename_and_block_number
    assert_raises(ArgumentError) do
      Block.new
    end
    assert Block.new(@filename, @block_number), 'Could not instantiate Block with two params'
  end

  def test_should_have_filename_attribute
    assert_respond_to(@default_block, :filename, 'Missing attr accessor for filename.')
  end

  def test_should_have_block_number_attribute
    assert_respond_to(@default_block, :block_number, 'Missing attr accessor for block number.')
  end

  def test_constructor_should_assign_passed_filname_and_block_number
    filename = 'alpha'
    block_num = 1
    assert_equal(@filename, @default_block.filename, 'Filename does not match initialized value.')
    assert_equal(@block_number, @default_block.block_number, 'Block number does not match initialized value.')
  end

  def test_should_have_number_attribute_that_returns_block_number
    assert_respond_to(@default_block, :number, 'Missing attr accessor for number.')
    assert_equal(@default_block.block_number, @default_block.number, 'Block number does not match initialized value.')    
  end

  def test_string_representation
    assert_equal(@as_string, @default_block.to_s, 'String representation of Block incorrect.')
  end

  def test_blocks_with_differing_filename_or_block_number_should_not_be_considered_equal
    b1 = Block.new(@filename + "foo", @block_number + 1)
    b2 = Block.new(@filename + "foo", @block_number)
    b3 = Block.new(@filename, @block_number + 1)
    refute_equal(@default_block, b1)
    refute_equal(@default_block, b2)
    refute_equal(@default_block, b3)
  end

  def test_blocks_with_same_filename_and_block_number_should_be_considered_equal
    b = Block.new(@filename, @block_number)
    assert_equal(@default_block, b)
  end

end
{'fraction_non_alphanumeric': 0.09172620419451487, 'fraction_numerical': 0.005070292694169164, 'mean_word_length': 4.9289617486338795, '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': '7106166', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1369, 'n_words': 309}