<commit_before>#include "vm/test/test.hpp"

#include "vm/object_utils.hpp"
#include "builtin/byte_array.hpp"
#include "builtin/exception.hpp"
#include "builtin/string.hpp"
#include "primitives.hpp"

class TestByteArray : public CxxTest::TestSuite, public VMTest {
  public:

  void setUp() {
    create();
  }

  void tearDown() {
    destroy();
  }

  ByteArray* new_bytearray(const char* str, int size = 0) {
    if(size == 0) size = strlen(str);
    ByteArray* b = ByteArray::create(state, size);
    memcpy(b->raw_bytes(), str, size);
    return b;
  }

  void test_create() {
    size_t mag = sizeof(Object*);
    ByteArray* b;

    b = ByteArray::create(state, 0);
    TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)0);

    for(size_t i = 1; i <= mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)mag);
    }

    for(size_t i = mag + 1; i <= 2 * mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)(2 * mag));
    }

    for(size_t i = 5 * mag + 1; i <= 6 * mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)(6 * mag));
    }
  }

  void test_allocate() {
    ByteArray* b = ByteArray::allocate(state, Fixnum::from(5));
    TS_ASSERT_EQUALS(b->size(state)->to_native(), 8);
  }

  void test_size() {
    ByteArray* b = ByteArray::create(state, 1);
    TS_ASSERT_EQUALS(b->size(state), Fixnum::from(sizeof(Object*)));
  }

  void test_get_byte() {<commit_msg>Update test reflecting not creating 0 sizes ByteArray's<commit_after>#include "vm/test/test.hpp"

#include "vm/object_utils.hpp"
#include "builtin/byte_array.hpp"
#include "builtin/exception.hpp"
#include "builtin/string.hpp"
#include "primitives.hpp"

class TestByteArray : public CxxTest::TestSuite, public VMTest {
  public:

  void setUp() {
    create();
  }

  void tearDown() {
    destroy();
  }

  ByteArray* new_bytearray(const char* str, int size = 0) {
    if(size == 0) size = strlen(str);
    ByteArray* b = ByteArray::create(state, size);
    memcpy(b->raw_bytes(), str, size);
    return b;
  }

  void test_create() {
    size_t mag = sizeof(Object*);
    ByteArray* b;

    b = ByteArray::create(state, 0);
    TS_ASSERT(b->size(state)->to_native() > 0);

    for(size_t i = 1; i <= mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)mag);
    }

    for(size_t i = mag + 1; i <= 2 * mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)(2 * mag));
    }

    for(size_t i = 5 * mag + 1; i <= 6 * mag; i++) {
      b = ByteArray::create(state, i);
      TS_ASSERT_EQUALS(b->size(state)->to_native(), (native_int)(6 * mag));
    }
  }

  void test_allocate() {
    ByteArray* b = ByteArray::allocate(state, Fixnum::from(5));
    TS_ASSERT_EQUALS(b->size(state)->to_native(), 8);
  }

  void test_size() {
    ByteArray* b = ByteArray::create(state, 1);
    TS_ASSERT_EQUALS(b->size(state), Fixnum::from(sizeof(Object*)));
  }

  void test_get_byte() {
{'fraction_non_alphanumeric': 0.17920353982300885, 'fraction_numerical': 0.009797724399494312, 'mean_word_length': 3.5936139332365746, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, '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': '787626', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1169, 'n_words': 237}