<commit_before>package perfTestUtils

import (
	"bytes"
	"encoding/json"
	"fmt"
	"github.com/stretchr/testify/assert"
	"io"
	"math/rand"
	"net/http"
	"os"
	"strings"
	"testing"
	"time"
)

var mockedFs FileSystem = mockFs{}

type mockFs struct{}

func (mockFs) Open(name string) (File, error) { return mockedFile{}, nil }
func (mockFs) Create(name string) (File, error) {
	if strings.Contains(name, "FAIL") {
		return nil, fmt.Errorf("requested mock FAIL!")
	}
	return mockedFile{}, nil
}

type mockedFile struct{}

func (mockedFile) Readdir(n int) (fi []os.FileInfo, err error) {
	if n == -1 {
		return make([]os.FileInfo, 10), nil
	} else {
		return nil, fmt.Errorf("Mock dir error!")
	}
}
func (mockedFile) Close() error { return nil }

func (mockedFile) Write(p []byte) (n int, err error) { return io.WriteString(os.Stdout, string(p)) }

func TestReadBasePerfFile(t *testing.T) {
	bs := &BasePerfStats{
		BasePeakMemory: 10e6 - 10e3,
	}
	bma := make([]uint64, 0)
	for i := 0; i < 100; i++ {
		bma = append(bma, bs.BasePeakMemory+uint64(10e5*rand.Int()))
	}
	bs.MemoryAudit = bma
	bsrt := make(map[string]int64)
	bsrt["service 1"] = 3e6
	bsrt["service 2"] = 2e6
	bsrt["service 3"] = 4e6<commit_msg>fix file mock<commit_after>package perfTestUtils

import (
	"bytes"
	"encoding/json"
	"fmt"
	"github.com/stretchr/testify/assert"
	"io"
	"math/rand"
	"net/http"
	"os"
	"strings"
	"testing"
	"time"
)

var mockedFs FileSystem = mockFs{}

type mockFs struct{}

func (mockFs) Open(name string) (File, error) { return &mockedFile{}, nil }
func (mockFs) Create(name string) (File, error) {
	if strings.Contains(name, "FAIL") {
		return nil, fmt.Errorf("requested mock FAIL!")
	}
	return &mockedFile{}, nil
}

type mockedFile struct {
	Content []byte
	r       *strings.Reader
}

func (mockedFile) Readdir(n int) (fi []os.FileInfo, err error) {
	if n == -1 {
		return make([]os.FileInfo, 10), nil
	} else {
		return nil, fmt.Errorf("Mock dir error!")
	}
}
func (mockedFile) Close() error { return nil }

func (mockedFile) Write(p []byte) (n int, err error) { return io.WriteString(os.Stdout, string(p)) }
func (m *mockedFile) Read(p []byte) (n int, err error) {
	if m.r == nil {
		m.r = strings.NewReader(string(m.Content))
	}
	n, err = m.r.Read(p)
	return
}

func TestReadBasePerfFile(t *testing.T) {
	bs := &BasePerfStats{
		BasePeakMemory: 10e6 - 10e3,
	}
	bma := make([]uint64, 0)
	for i := 0; i < 100; i++ {
		bma = append(bma, bs.BasePeakMemory+uint64(10e5*rand.Int()))
	}
	bs.MemoryAudit = bma
	bsrt := make(map[string]int64)
	bsrt["service 1"] = 3e6
	bsrt["service 2"] = 2e6
	bsrt["service 3"] = 4e6
{'fraction_non_alphanumeric': 0.16891111966140823, 'fraction_numerical': 0.024624855713736054, 'mean_word_length': 4.252525252525253, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4483186', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1060, 'n_words': 265}