<commit_before>package mnist

import (
	. "github.com/smartystreets/goconvey/convey"
	"gopkg.in/sensorbee/sensorbee.v0/core"
	"gopkg.in/sensorbee/sensorbee.v0/data"
	"testing"
)

func TestCreateDataBucketState(t *testing.T) {
	cc := &core.ContextConfig{}
	ctx := core.NewContext(cc)
	Convey("Given a state creator", t, func() {

		Convey("When pass an empty parameter", func() {
			params := data.Map{}
			_, err := NewBucketState(ctx, params)
			Convey("Then the creator should not create a state", func() {
				So(err, ShouldNotBeNil)
			})
		})

		Convey("When pass a valid parameter", func() {
			params := data.Map{
				"bucket_size": data.Int(3),
			}
			s, err := NewBucketState(ctx, params)
			So(err, ShouldBeNil)
			Reset(func() {
				s.Terminate(ctx)
			})
			Convey("Then the creator should return a state", func() {
				db, ok := s.(*dataBucket)
				So(ok, ShouldBeTrue)
				So(db.bucketSize, ShouldEqual, 3)
			})
		})
	})
}

func TestBucketStoreUDSFProcess(t *testing.T) {
	cc := &core.ContextConfig{}
	ctx := core.NewContext(cc)
	Convey("Given a bucket which set up three tuples pool & bucket store UDSF", t, func() {
		params := data.Map{
			"bucket_size": data.Int(3),
		}
		ss, err := NewBucketState(ctx, params)
		So(err, ShouldBeNil)
		err = ctx.SharedStates.Add("bucket", "bucket", ss)
		So(err, ShouldBeNil)

		udsf := bucketStoreUDSF{
			bucketName: "bucket",
		}

		Convey("When three tuples are processed", func() {
			var written data.Array
			w := core.WriterFunc(func(ctx *core.Context, t *core.Tuple) error {
				bu, err := t.Data.Get(data.MustCompilePath("bucket"))
				So(err, ShouldBeNil)
				array, err := data.AsArray(bu)
				So(err, ShouldBeNil)
				So(len(array), ShouldEqual, 3)
				written = array

				return nil
			})

			m1 := data.Map{
				"data": data.String("1"),
			}
			t1 := &core.Tuple{
				Data: m1,
			}
			err := udsf.Process(ctx, t1, w)
			So(err, ShouldBeNil)

			m2 := data.Map{<commit_msg>fix failure test, change reserved state name<commit_after>package mnist

import (
	. "github.com/smartystreets/goconvey/convey"
	"gopkg.in/sensorbee/sensorbee.v0/core"
	"gopkg.in/sensorbee/sensorbee.v0/data"
	"testing"
)

func TestCreateDataBucketState(t *testing.T) {
	cc := &core.ContextConfig{}
	ctx := core.NewContext(cc)
	Convey("Given a state creator", t, func() {

		Convey("When pass an empty parameter", func() {
			params := data.Map{}
			_, err := NewBucketState(ctx, params)
			Convey("Then the creator should not create a state", func() {
				So(err, ShouldNotBeNil)
			})
		})

		Convey("When pass a valid parameter", func() {
			params := data.Map{
				"bucket_size": data.Int(3),
			}
			s, err := NewBucketState(ctx, params)
			So(err, ShouldBeNil)
			Reset(func() {
				s.Terminate(ctx)
			})
			Convey("Then the creator should return a state", func() {
				db, ok := s.(*dataBucket)
				So(ok, ShouldBeTrue)
				So(db.bucketSize, ShouldEqual, 3)
			})
		})
	})
}

func TestBucketStoreUDSFProcess(t *testing.T) {
	cc := &core.ContextConfig{}
	ctx := core.NewContext(cc)
	Convey("Given a bucket which set up three tuples pool & bucket store UDSF", t, func() {
		params := data.Map{
			"bucket_size": data.Int(3),
		}
		ss, err := NewBucketState(ctx, params)
		So(err, ShouldBeNil)
		err = ctx.SharedStates.Add("test_bucket", "bucket_state", ss)
		So(err, ShouldBeNil)

		udsf := bucketStoreUDSF{
			bucketName: "test_bucket",
		}

		Convey("When three tuples are processed", func() {
			var written data.Array
			w := core.WriterFunc(func(ctx *core.Context, t *core.Tuple) error {
				bu, err := t.Data.Get(data.MustCompilePath("bucket"))
				So(err, ShouldBeNil)
				array, err := data.AsArray(bu)
				So(err, ShouldBeNil)
				So(len(array), ShouldEqual, 3)
				written = array

				return nil
			})

			m1 := data.Map{
				"data": data.String("1"),
			}
			t1 := &core.Tuple{
				Data: m1,
			}
			err := udsf.Process(ctx, t1, w)
			So(err, ShouldBeNil)

			m2 := data.Map{
{'fraction_non_alphanumeric': 0.15621031242062483, 'fraction_numerical': 0.006096012192024384, 'mean_word_length': 3.4699205448354142, 'pattern_counts': {'":': 6, '<': 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': '6787277', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1443, 'n_words': 335}