<commit_before>package m3

import (
    "os"
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestNewFileReader(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    n, err := fd.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // seek to beginning of file
    fd.Seek(0, 0)

    // create reader
    reader := NewFileReader(fd)

    // test read
    n, err = reader.Read(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // test close
    err = reader.Close()
    assert.Nil(t, err)
}

func TestNewFileWriter(t *testing.T) {
    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, NoSyncOnWrite)

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // get file stat
    stat, err := fd.Stat()
    assert.Nil(t, err)
    assert.Equal(t, stat.Size(), len(buffer))

    // test close
    err = writer.Close()
    assert.Nil(t, err)
}

func TestNewFileWriterSync(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, SyncOnWrite)

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // get file stat
    stat, err := fd.Stat()
    assert.Nil(t, err)
    assert.Equal(t, stat.Size(), len(buffer))

    // test close
    err = writer.Close()
    assert.Nil(t, err)
}

func TestNewFileWriterSyncFail(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, SyncOnWrite)
    writer.Close()

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, 0)
    assert.NotNil(t, err)
<commit_msg>Resolve test failures<commit_after>package m3

import (
    "os"
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestNewFileReader(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    n, err := fd.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // seek to beginning of file
    fd.Seek(0, 0)

    // create reader
    reader := NewFileReader(fd)

    // test read
    n, err = reader.Read(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // test close
    err = reader.Close()
    assert.Nil(t, err)
}

func TestNewFileWriter(t *testing.T) {
    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, NoSyncOnWrite)

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // get file stat
    stat, err := fd.Stat()
    assert.Nil(t, err)
    assert.Equal(t, stat.Size(), int64(len(buffer)))

    // test close
    err = writer.Close()
    assert.Nil(t, err)
}

func TestNewFileWriterSync(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, SyncOnWrite)

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, len(buffer))
    assert.Nil(t, err)

    // get file stat
    stat, err := fd.Stat()
    assert.Nil(t, err)
    assert.Equal(t, stat.Size(), int64(len(buffer)))

    // test close
    err = writer.Close()
    assert.Nil(t, err)
}

func TestNewFileWriterSyncFail(t *testing.T) {

    filename := "testfile.bin"
    fd, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
    assert.Nil(t, err)

    // delete test file
    defer os.Remove(filename)

    buffer := make([]byte, 1024)
    writer := NewFileWriter(fd, SyncOnWrite)
    writer.Close()

    // test write
    n, err := writer.Write(buffer)
    assert.Equal(t, n, 0)
    assert.NotNil(t, err)

{'fraction_non_alphanumeric': 0.15248525695029486, 'fraction_numerical': 0.016006739679865205, 'mean_word_length': 2.644666155026861, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1008549', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1701, 'n_words': 392}