<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe OOPM::Instructions::ByteSequence do
  describe '.make_bytecode' do
    before :all do
      @code = Instructions::ByteSequence::CODE
      
      @cases = [
        [1,2,3],
        [75, 144, 51, 190, 0xFF, 0xFE],
        (1..25).to_a,
        (0..0xFF).step(4).to_a
      ]
      
      @bytecodes = {}
      @cases.each do |bytes|
        @bytecodes[bytes] = Instructions::ByteSequence.make_bytecode bytes
      end
    end
    
    it "should populate first byte of bytecode with the instruction code for a byte sequence" do
      @bytecodes.each do |bytes, bytecode|
        bytecode.first.should eq @code
      end
    end

    it "should add byte for the byte sequence size after the instruction code byte" do
      @bytecodes.each do |bytes, bytecode|
        size_bytecode = Instructions::Natural.make_bytecode(bytes.size)
        bytecode[1, size_bytecode.count].should eq size_bytecode
      end
    end

    it "should add the byte sequence bytes after the sequence size bytecode" do
      @bytecodes.each do |bytes, bytecode|
        size_bytecode = Instructions::Natural.make_bytecode(bytes.size)
        bytecode[(1 + size_bytecode.count)..-1].should eq bytes
      end<commit_msg>Simplify tests for ByteSequence.make_bytecode and ByteSequence.read_bytecode.<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe OOPM::Instructions::ByteSequence do
  describe '.make_bytecode' do
    before :all do
      @code = Instructions::ByteSequence::CODE
      
      @cases = [
        [1,2,3],
        [75, 144, 51, 190, 0xFF, 0xFE],
        (1..25).to_a,
        (0..0xFF).step(4).to_a
      ]
    end
    
    it "should produce bytecode that can be read to get back the original value" do
      @cases.each do |byte_seq|
        bytecode = Instructions::ByteSequence.make_bytecode byte_seq
        byte_seq2 = Instructions::ByteSequence::read_bytecode(bytecode, 0)[0]
        byte_seq2.should eq byte_seq
      end
{'fraction_non_alphanumeric': 0.10408560311284047, 'fraction_numerical': 0.023832684824902722, 'mean_word_length': 2.7197106690777577, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4028022', 'n_tokens_mistral': 669, 'n_tokens_neox': 633, 'n_words': 166}