<commit_before>#include "gtest/gtest.h"

#include "GContext.h"
#include "GBitmap.h"
#include "GColor.h"

TEST(GContext, CreateFromBitmap) {
  GBitmap bm;
  bm.fWidth = 64;
  bm.fHeight = 128;
  const int nPixels = bm.fWidth * bm.fHeight;
  bm.fPixels = new GPixel[nPixels];
  bm.fRowBytes = bm.fWidth * sizeof(GPixel);

  memset(bm.fPixels, 0, sizeof(GPixel) * nPixels);

  GContext *newContext = GContext::Create(bm);

  GBitmap nbm;
  newContext->getBitmap(&nbm);

  EXPECT_EQ(memcmp(&bm, &nbm, sizeof(GBitmap)), 0);

  delete newContext;
}

TEST(GContext, CreateFromWidthAndHeight) {
  GContext *newContext = GContext::Create(64, 128);

  GBitmap nbm;
  nbm.fPixels = NULL;

  newContext->getBitmap(&nbm);

  EXPECT_EQ(nbm.fWidth, 64);
  EXPECT_EQ(nbm.fHeight, 128);
  EXPECT_NE(nbm.fPixels, static_cast<GPixel *>(NULL));

  delete newContext;
}

TEST(GContext, ClearOwnBitmap) {
  GContext *ctx = GContext::Create(32, 32);

  GColor clr;
  clr.fA = clr.fR = clr.fG = clr.fB = 1.0f;
  ctx->clear(clr);

  GBitmap bm;
  ctx->getBitmap(&bm);

  EXPECT_EQ(bm.fWidth, 32);
  EXPECT_EQ(bm.fHeight, 32);

  for(int i = 0; i < 32; i++) {
    for(int j = 0; j < 32; j++) {
      EXPECT_EQ(bm.fPixels[j*32 + i], 0xFFFFFFFF);
    }
  }

  delete ctx;
}

TEST(GContext, ClearForeignBitmap) {
  GBitmap bm;
  bm.fWidth = 64;
  bm.fHeight = 128;
  const int nPixels = bm.fWidth * bm.fHeight;
  bm.fPixels = new GPixel[nPixels];
  bm.fRowBytes = bm.fWidth * sizeof(GPixel);

  memset(bm.fPixels, 0, sizeof(GPixel) * nPixels);

  GContext *ctx = GContext::Create(bm);

  GColor clr;
  clr.fA = clr.fR = clr.fG = clr.fB = 1.0f;
  ctx->clear(clr);

  for(int j = 0; j < 128; j++) {
    for(int i = 0; i < 64; i++) {
      const int pIdx = j * bm.fWidth + i;
      EXPECT_EQ(bm.fPixels[pIdx], 0xFFFFFFFF);
    }
  }

  delete ctx;
}

TEST(GContext, ClearBitmapWithSlop) {
  GBitmap bm;
  bm.fWidth = 640;
  bm.fHeight = 12;
  bm.fRowBytes = bm.fWidth * sizeof(GPixel) + 14;
  const int fPixelsSz = bm.fRowBytes * bm.fHeight;
  bm.fPixels = (GPixel *)malloc(fPixelsSz);

  memset(bm.fPixels, 0, fPixelsSz);
<commit_msg>Change our slop to be divisible by 4<commit_after>#include "gtest/gtest.h"

#include "GContext.h"
#include "GBitmap.h"
#include "GColor.h"

TEST(GContext, CreateFromBitmap) {
  GBitmap bm;
  bm.fWidth = 64;
  bm.fHeight = 128;
  const int nPixels = bm.fWidth * bm.fHeight;
  bm.fPixels = new GPixel[nPixels];
  bm.fRowBytes = bm.fWidth * sizeof(GPixel);

  memset(bm.fPixels, 0, sizeof(GPixel) * nPixels);

  GContext *newContext = GContext::Create(bm);

  GBitmap nbm;
  newContext->getBitmap(&nbm);

  EXPECT_EQ(memcmp(&bm, &nbm, sizeof(GBitmap)), 0);

  delete newContext;
}

TEST(GContext, CreateFromWidthAndHeight) {
  GContext *newContext = GContext::Create(64, 128);

  GBitmap nbm;
  nbm.fPixels = NULL;

  newContext->getBitmap(&nbm);

  EXPECT_EQ(nbm.fWidth, 64);
  EXPECT_EQ(nbm.fHeight, 128);
  EXPECT_NE(nbm.fPixels, static_cast<GPixel *>(NULL));

  delete newContext;
}

TEST(GContext, ClearOwnBitmap) {
  GContext *ctx = GContext::Create(32, 32);

  GColor clr;
  clr.fA = clr.fR = clr.fG = clr.fB = 1.0f;
  ctx->clear(clr);

  GBitmap bm;
  ctx->getBitmap(&bm);

  EXPECT_EQ(bm.fWidth, 32);
  EXPECT_EQ(bm.fHeight, 32);

  for(int i = 0; i < 32; i++) {
    for(int j = 0; j < 32; j++) {
      EXPECT_EQ(bm.fPixels[j*32 + i], 0xFFFFFFFF);
    }
  }

  delete ctx;
}

TEST(GContext, ClearForeignBitmap) {
  GBitmap bm;
  bm.fWidth = 64;
  bm.fHeight = 128;
  const int nPixels = bm.fWidth * bm.fHeight;
  bm.fPixels = new GPixel[nPixels];
  bm.fRowBytes = bm.fWidth * sizeof(GPixel);

  memset(bm.fPixels, 0, sizeof(GPixel) * nPixels);

  GContext *ctx = GContext::Create(bm);

  GColor clr;
  clr.fA = clr.fR = clr.fG = clr.fB = 1.0f;
  ctx->clear(clr);

  for(int j = 0; j < 128; j++) {
    for(int i = 0; i < 64; i++) {
      const int pIdx = j * bm.fWidth + i;
      EXPECT_EQ(bm.fPixels[pIdx], 0xFFFFFFFF);
    }
  }

  delete ctx;
}

TEST(GContext, ClearBitmapWithSlop) {
  GBitmap bm;
  bm.fWidth = 640;
  bm.fHeight = 12;
  bm.fRowBytes = bm.fWidth * sizeof(GPixel) + 16;
  const int fPixelsSz = bm.fRowBytes * bm.fHeight;
  bm.fPixels = (GPixel *)malloc(fPixelsSz);

  memset(bm.fPixels, 0, fPixelsSz);

{'fraction_non_alphanumeric': 0.15937573894537715, 'fraction_numerical': 0.028611965003546937, 'mean_word_length': 3.5289079229122056, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '1596928', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1849, 'n_words': 367}