<commit_before>require_relative '../test_helper'

class TestBEREncoding < Test::Unit::TestCase
  def test_empty_array
    assert_equal [], [].to_ber.read_ber
  end

  def test_array
    ary = [1,2,3]
    encoded_ary = ary.map { |el| el.to_ber }.to_ber

    assert_equal ary, encoded_ary.read_ber
  end

  # http://tools.ietf.org/html/rfc4511#section-5.1
  def test_true
    assert_equal "\x01\x01\xFF".b, true.to_ber
  end

  def test_false
    assert_equal "\x01\x01\x00", false.to_ber
  end

  # Sample based
  {
    0           => "\x02\x01\x00",
    1           => "\x02\x01\x01",
    127         => "\x02\x01\x7F",
    128         => "\x02\x02\x00\x80",
    255         => "\x02\x01\xFF",
    256         => "\x02\x02\x01\x00",
    65535       => "\x02\x02\xFF\xFF",
    65536       => "\x02\x03\x01\x00\x00",
    16_777_215  => "\x02\x03\xFF\xFF\xFF",
    0x01000000  => "\x02\x04\x01\x00\x00\x00",
    0x3FFFFFFF  => "\x02\x04\x3F\xFF\xFF\xFF",
    0x4FFFFFFF  => "\x02\x04\x4F\xFF\xFF\xFF",

    # Some odd samples...
    5           => "\002\001\005",
    500         => "\002\002\001\364",
    50_000      => "\x02\x02\xC3P",
    5_000_000_000  => "\002\005\001*\005\362\000"
  }.each do |number, expected_encoding|
    define_method "test_encode_#{number}" do
      assert_equal expected_encoding.b, number.to_ber
    end
  end

  # Round-trip encoding: This is mostly to be sure to cover Bignums well.
  def test_powers_of_two
    100.times do |p|
      n = 2 << p

      assert_equal n, n.to_ber.read_ber
    end
  end

  def test_powers_of_ten<commit_msg>Fix the expected encoded value for 255<commit_after>require_relative '../test_helper'

class TestBEREncoding < Test::Unit::TestCase
  def test_empty_array
    assert_equal [], [].to_ber.read_ber
  end

  def test_array
    ary = [1,2,3]
    encoded_ary = ary.map { |el| el.to_ber }.to_ber

    assert_equal ary, encoded_ary.read_ber
  end

  # http://tools.ietf.org/html/rfc4511#section-5.1
  def test_true
    assert_equal "\x01\x01\xFF".b, true.to_ber
  end

  def test_false
    assert_equal "\x01\x01\x00", false.to_ber
  end

  # Sample based
  {
    0           => "\x02\x01\x00",
    1           => "\x02\x01\x01",
    127         => "\x02\x01\x7F",
    128         => "\x02\x02\x00\x80",
    255         => "\x02\x02\x00\xFF",
    256         => "\x02\x02\x01\x00",
    65535       => "\x02\x02\xFF\xFF",
    65536       => "\x02\x03\x01\x00\x00",
    16_777_215  => "\x02\x03\xFF\xFF\xFF",
    0x01000000  => "\x02\x04\x01\x00\x00\x00",
    0x3FFFFFFF  => "\x02\x04\x3F\xFF\xFF\xFF",
    0x4FFFFFFF  => "\x02\x04\x4F\xFF\xFF\xFF",

    # Some odd samples...
    5           => "\002\001\005",
    500         => "\002\002\001\364",
    50_000      => "\x02\x02\xC3P",
    5_000_000_000  => "\002\005\001*\005\362\000"
  }.each do |number, expected_encoding|
    define_method "test_encode_#{number}" do
      assert_equal expected_encoding.b, number.to_ber
    end
  end

  # Round-trip encoding: This is mostly to be sure to cover Bignums well.
  def test_powers_of_two
    100.times do |p|
      n = 2 << p

      assert_equal n, n.to_ber.read_ber
    end
  end

  def test_powers_of_ten
{'fraction_non_alphanumeric': 0.15251026207767604, 'fraction_numerical': 0.13293337543416484, 'mean_word_length': 2.1058823529411765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '5590816', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1295, 'n_words': 229}