<commit_before>package picasso_test

import (
	"image"
	_ "image/jpeg"
	"image/png"
	"os"

	. "github.com/deiwin/picasso"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

type TestImage string

const (
	GirlBeforeAMirror TestImage = "./test_images/picasso-girl_before_a_mirror.jpg"
	OldGuitarist      TestImage = "./test_images/picasso-the_old_guitarist.jpg"
	WomenOfAlgiers    TestImage = "./test_images/picasso-the_women_of_algiers.jpg"
	Bullfight         TestImage = "./test_images/picasso-bullfight.jpg"
	Composed          TestImage = "./test_images/composed.png"
	TopHeavy1         TestImage = "./test_images/top_heavy-1.png"
	TopHeavy2         TestImage = "./test_images/top_heavy-2.png"
	TopHeavy3         TestImage = "./test_images/top_heavy-3.png"
	TopHeavy4         TestImage = "./test_images/top_heavy-4.png"
)

func (i TestImage) read() image.Image {
	file, err := os.Open(string(i))
	Expect(err).NotTo(HaveOccurred())
	defer file.Close()

	image, _, err := image.Decode(file)
	Expect(err).NotTo(HaveOccurred())
	return image
}

func (i TestImage) write(data image.Image) {
	outfile, err := os.Create(string(i))
	Expect(err).NotTo(HaveOccurred())
	defer outfile.Close()

	png.Encode(outfile, data)
}

var _ = Describe("Picasso", func() {
	ExpectToEqualTestImage := func(i image.Image, testImage TestImage) {
		composed := testImage.read()
		Expect(i.Bounds().Dx()).To(Equal(composed.Bounds().Dx()))
		Expect(i.Bounds().Dy()).To(Equal(composed.Bounds().Dy()))
		for x := 0; x < i.Bounds().Dx(); x++ {
			for y := 0; y < i.Bounds().Dy(); y++ {
				Expect(i.At(x, y)).To(Equal(composed.At(x, y)))
			}
		}
	}

	Describe("Node", func() {
		It("draws the composed image", func() {<commit_msg>Add similarity threshold for tests<commit_after>package picasso_test

import (
	"image"
	_ "image/jpeg"
	"image/png"
	"os"

	. "github.com/deiwin/picasso"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

type TestImage string

const (
	GirlBeforeAMirror TestImage = "./test_images/picasso-girl_before_a_mirror.jpg"
	OldGuitarist      TestImage = "./test_images/picasso-the_old_guitarist.jpg"
	WomenOfAlgiers    TestImage = "./test_images/picasso-the_women_of_algiers.jpg"
	Bullfight         TestImage = "./test_images/picasso-bullfight.jpg"
	Composed          TestImage = "./test_images/composed.png"
	TopHeavy1         TestImage = "./test_images/top_heavy-1.png"
	TopHeavy2         TestImage = "./test_images/top_heavy-2.png"
	TopHeavy3         TestImage = "./test_images/top_heavy-3.png"
	TopHeavy4         TestImage = "./test_images/top_heavy-4.png"
)

func (i TestImage) read() image.Image {
	file, err := os.Open(string(i))
	Expect(err).NotTo(HaveOccurred())
	defer file.Close()

	image, _, err := image.Decode(file)
	Expect(err).NotTo(HaveOccurred())
	return image
}

func (i TestImage) write(data image.Image) {
	outfile, err := os.Create(string(i))
	Expect(err).NotTo(HaveOccurred())
	defer outfile.Close()

	png.Encode(outfile, data)
}

var _ = Describe("Picasso", func() {
	ExpectToEqualTestImage := func(i image.Image, testImage TestImage) {
		expected := testImage.read()
		Expect(i.Bounds().Dx()).To(Equal(expected.Bounds().Dx()))
		Expect(i.Bounds().Dy()).To(Equal(expected.Bounds().Dy()))
		for x := 0; x < i.Bounds().Dx(); x++ {
			for y := 0; y < i.Bounds().Dy(); y++ {
				expectedColor := expected.At(x, y)
				er, eg, eb, ea := expectedColor.RGBA()
				r, g, b, a := i.At(x, y).RGBA()
				// There might be some differences while creating the image on different machines.
				// To account for that, expect the images to be similat, but not exactly the same.
				Expect(r).To(BeNumerically("~", er, 2))
				Expect(g).To(BeNumerically("~", eg, 2))
				Expect(b).To(BeNumerically("~", eb, 2))
				Expect(a).To(BeNumerically("~", ea, 2))
			}
		}
	}

	Describe("Node", func() {
		It("draws the composed image", func() {
{'fraction_non_alphanumeric': 0.16878402903811252, 'fraction_numerical': 0.00622245268343272, 'mean_word_length': 3.76885043263288, 'pattern_counts': {'":': 0, '<': 7, '<?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': '179380', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1439, 'n_words': 264}