<commit_before>package thumbnailer

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"testing"
)

func testThumbnailerMessage() ThumbnailerMessage {
	pwd, err := os.Getwd()
	if err != nil {
		log.Fatal("Failed to get the current directory: %s", err)
	}
	fmt.Println("Current dir:", pwd)
	opt := ThumbnailOpt{Width: 100, Height: 100}
	opts := make([]ThumbnailOpt, 0)
	opts = append(opts, opt)
	return ThumbnailerMessage{
		SrcImage:  filepath.Join("file://", pwd, "testdata", "pic.jpg"),
		DstFolder: "file:///tmp",
		Opts:      opts}

}

func Test_thumbURL(t *testing.T) {
	expected := "/tmp/pic_s100x100.jpg"
	tm := testThumbnailerMessage()
	url, err := tm.thumbURL(tm.Opts[0])
	if err != nil {
		t.Fatal("Failed to generate the thumbURL :", err)
	}
	if url.Path != expected {
		t.Fatalf("got: %s, expected: %s", url.Path, expected)
	}
}

func Test_generateThumbnail(t *testing.T) {
	tm := testThumbnailerMessage()
	src, err := tm.Open()
	if err != nil {
		t.Fatalf("Failed to open tm.SrcImage: %v", err)
	}
	result := tm.generateThumbnail(src, tm.Opts[0])
	// Clean up the generated thumb
	if err := os.Remove(result.Thumbnail.Path); err != nil {
		t.Fatal("Failed to delete the generated thumb:", err)
	}
}

func Test_GenerateThumbnails(t *testing.T) {
	tm := testThumbnailerMessage()
	results := tm.GenerateThumbnails()
	for result := range results {
		if result.Err != nil {
			t.Fatal("An error occured while generating a thumb :", result.Err)
		}
		// Clean up the generated thumb
		if err := os.Remove(result.Thumbnail.Path); err != nil {
			t.Fatal("Failed to delete the generated thumb:", err)
		}
	}
}<commit_msg>Add a benchmark to measure tm.generateThumbnail<commit_after>package thumbnailer

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"testing"
)

func testThumbnailerMessage() ThumbnailerMessage {
	pwd, err := os.Getwd()
	if err != nil {
		log.Fatal("Failed to get the current directory: %s", err)
	}
	fmt.Println("Current dir:", pwd)
	opt := ThumbnailOpt{Width: 100, Height: 100}
	opts := make([]ThumbnailOpt, 0)
	opts = append(opts, opt)
	return ThumbnailerMessage{
		SrcImage:  filepath.Join("file://", pwd, "testdata", "pic.jpg"),
		DstFolder: "file:///tmp",
		Opts:      opts}

}

func Test_thumbURL(t *testing.T) {
	expected := "/tmp/pic_s100x100.jpg"
	tm := testThumbnailerMessage()
	url, err := tm.thumbURL(tm.Opts[0])
	if err != nil {
		t.Fatal("Failed to generate the thumbURL :", err)
	}
	if url.Path != expected {
		t.Fatalf("got: %s, expected: %s", url.Path, expected)
	}
}

func Test_generateThumbnail(t *testing.T) {
	tm := testThumbnailerMessage()
	src, err := tm.Open()
	if err != nil {
		t.Fatalf("Failed to open tm.SrcImage: %v", err)
	}
	result := tm.generateThumbnail(src, tm.Opts[0])
	// Clean up the generated thumb
	if err := os.Remove(result.Thumbnail.Path); err != nil {
		t.Fatal("Failed to delete the generated thumb:", err)
	}
}

func Benchmark_generateThumbnail(b *testing.B) {
	tm := testThumbnailerMessage()
	src, err := tm.Open()
	if err != nil {
		b.Fatalf("Failed to open tm.SrcImage: %v", err)
	}
	var result ThumbnailResult
	for n := 0; n < b.N; n++ {
		result = tm.generateThumbnail(src, tm.Opts[0])
	}
	// Clean up the generated thumb
	if err := os.Remove(result.Thumbnail.Path); err != nil {
		b.Fatal("Failed to delete the generated thumb:", err)
	}

}

func Test_GenerateThumbnails(t *testing.T) {
	tm := testThumbnailerMessage()
	results := tm.GenerateThumbnails()
	for result := range results {
		if result.Err != nil {
			t.Fatal("An error occured while generating a thumb :", result.Err)
		}
		// Clean up the generated thumb
		if err := os.Remove(result.Thumbnail.Path); err != nil {
			t.Fatal("Failed to delete the generated thumb:", err)
		}
	}
}
{'fraction_non_alphanumeric': 0.15805061927840602, 'fraction_numerical': 0.008616047388260635, 'mean_word_length': 3.9467376830892142, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6676702', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1404, 'n_words': 359}