<commit_before>require 'minitest_helper'

class TestBanditMask < Minitest::Test # :nodoc:
  def setup
    @cls = Class.new(BanditMask)
  end

  def test_define_bit
    @cls.bit :read, 0b01
    assert_equal({ read: 0b01 }, @cls.bits)

    @cls.bit :write, 0b10
    assert_equal({ read: 0b01, write: 0b10 }, @cls.bits)
  end

  def test_initialize_with_default_mask
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new
    assert_equal 0, mask.to_i
  end

  def test_initialize_with_specific_mask
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new 0b001 | 0b100
    assert_equal 0b101, mask.to_i
  end

  def test_push_bit_into_mask
    @cls.bit :read, 0b1

    mask = @cls.new
    assert_equal 0, mask.to_i

    mask << :read
    assert_equal 0b1, mask.to_i
  end

  def test_push_multiple_bits_into_mask
    @cls.bit :read, 0b01
    @cls.bit :write, 0b10

    mask = @cls.new
    mask << :read << :write
    assert_equal 0b11, mask.to_i
  end

  def test_push_undefined_bit_into_mask
    mask = @cls.new

    e = assert_raises(ArgumentError) { mask << :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_bitwise_or_remembers_original_bitmask
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new 0b001

    assert_equal 0b011, Integer(mask | :write)
    assert_equal 0b111, Integer(mask | :write | :execute)
  end

  def test_bitwise_or_returns_new_instance_of_mask_class
    @cls.bit :read, 0b1
    mask = @cls.new
    assert_kind_of @cls, mask | :read
  end

  def test_bitwise_or_with_undefined_bit
    mask = @cls.new

    e = assert_raises(ArgumentError) { mask | :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_get_list_of_enabled_bits
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new
    mask << :read << :execute
    assert_equal [:read, :execute], mask.bits
  end

  def test_include_with_a_single_bit
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new
    mask << :read << :execute

    assert_includes mask, :read
    refute_includes mask, :write
    assert_includes mask, :execute
  end

  def test_include_with_multiple_bits
    @cls.bit :read, 0b001
    @cls.bit :write, 0b010
    @cls.bit :execute, 0b100

    mask = @cls.new
    mask << :read << :execute

    refute mask.include?(:read, :write),
      "#{mask.inspect} must NOT have :read and :write"
    assert mask.include?(:read, :execute),
      "#{mask.inspect} must have :read and :execute"
  end

  def test_include_with_undefined_bit
    mask = @cls.new

    e = assert_raises(ArgumentError) { mask.include? :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_include_without_any_arguments
    mask = @cls.new

    e = assert_raises(ArgumentError) { mask.include? }
    assert_equal 'wrong number of arguments (0 for 1+)', e.message
  end

  def test_coerce_to_integer
    @cls.bit :read, 0b01
    @cls.bit :write, 0b10

    mask = @cls.new
    mask << :read << :write

    assert_equal 0b11, Integer(mask)
  end

  def test_coerce_to_array
    @cls.bit :read, 0b01
    @cls.bit :write, 0b10

    mask = @cls.new
    mask << :read << :write

    assert_equal [:read, :write], Array(mask)
  end
end<commit_msg>refactored tests<commit_after>require 'minitest_helper'

class TestBanditMask < Minitest::Test # :nodoc:
  def test_define_bit
    assert_equal({ read: 0b001, write: 0b010, execute: 0b100 }, cls.bits)
  end

  def test_initialize_with_default_mask
    mask = cls.new
    assert_equal 0, mask.to_i
  end

  def test_initialize_with_specific_mask
    mask = cls.new 0b001 | 0b100
    assert_equal 0b101, mask.to_i
  end

  def test_push_bit_into_mask
    mask = cls.new

    assert_equal 0b0, mask.to_i
    mask << :read
    assert_equal 0b1, mask.to_i
  end

  def test_push_multiple_bits_into_mask
    mask = cls.new
    mask << :read << :write
    assert_equal 0b11, mask.to_i
  end

  def test_push_undefined_bit_into_mask
    mask = cls.new

    e = assert_raises(ArgumentError) { mask << :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_bitwise_or_remembers_original_bitmask
    mask = cls.new 0b001

    assert_equal 0b011, Integer(mask | :write)
    assert_equal 0b111, Integer(mask | :write | :execute)
  end

  def test_bitwise_or_returns_new_instance_of_mask_class
    _cls = cls
    mask = _cls.new
    assert_kind_of _cls, mask | :read
  end

  def test_bitwise_or_with_undefined_bit
    mask = cls.new

    e = assert_raises(ArgumentError) { mask | :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_get_list_of_enabled_bits
    mask = cls.new
    mask << :read << :execute
    assert_equal [:read, :execute], mask.bits
  end

  def test_include_with_a_single_bit
    mask = cls.new
    mask << :read << :execute

    assert_includes mask, :read
    refute_includes mask, :write
    assert_includes mask, :execute
  end

  def test_include_with_multiple_bits
    mask = cls.new
    mask << :read << :execute

    refute mask.include?(:read, :write),
      "#{mask.inspect} must NOT have :read and :write"
    assert mask.include?(:read, :execute),
      "#{mask.inspect} must have :read and :execute"
  end

  def test_include_with_undefined_bit
    mask = cls.new

    e = assert_raises(ArgumentError) { mask.include? :bogus }
    assert_match /undefined bit/, e.message
  end

  def test_include_without_any_arguments
    mask = cls.new

    e = assert_raises(ArgumentError) { mask.include? }
    assert_equal 'wrong number of arguments (0 for 1+)', e.message
  end

  def test_coerce_to_integer
    mask = cls.new
    mask << :read << :write

    assert_equal 0b11, Integer(mask)
  end

  def test_coerce_to_array
    mask = cls.new
    mask << :read << :write

    assert_equal [:read, :write], Array(mask)
  end

  def cls
    Class.new BanditMask do
      bit :read, 1 << 0
      bit :write, 1 << 1
      bit :execute, 1 << 2
    end
  end
end
{'fraction_non_alphanumeric': 0.09795249795249795, 'fraction_numerical': 0.03276003276003276, 'mean_word_length': 3.033025099075297, 'pattern_counts': {'":': 0, '<': 67, '<?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': '4518679', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2228, 'n_words': 550}