<commit_before>package scene

import (
	"github.com/orfjackal/gospec"
	. "github.com/orfjackal/gospec"
)

type SomeProperty struct {
	tid PropertyType
}

func NewProperty(t PropertyType) Property {
	return &SomeProperty{t}
}

func (p *SomeProperty) Type() PropertyType {
	return p.tid
}

func CtorSpec(c gospec.Context) {
	c.Specify("New scene", func() {
		scene := NewScene()

		c.Specify("has zero actors", func() {
			c.Expect(len(scene.Actors), Equals, 0)
		})

		c.Specify("has zero cached by property", func() {
			c.Expect(len(scene.byProperty), Equals, 0)
		})
	})
}

func AddSpec(c gospec.Context) {
	scene := NewScene()

	c.Specify("New actor always has reference to creating scene", func() {
		a,_ := scene.Add(ActorId("a"))
		
		c.Expect(a.s, IsSame, scene)
	})

	c.Specify("Add one actor with one property", func() {
		p1 := NewProperty(1)
		a, _ := scene.Add(ActorId("a"))
		a.Add(p1)

		c.Specify("scene contains just that one actor", func() {
			c.Expect(len(scene.Actors), Equals, 1)
			c.Expect(scene.Actors["a"], IsSame, a)
			c.Expect(len(scene.byProperty), Equals, 1)
			c.Expect(scene.byProperty[1], Contains, a)
		})

		c.Specify("actor contains that property", func() {
			c.Expect(len(a.properties), Equals, 1)
			c.Expect(a.properties[1], IsSame, p1)
		})
	})

	c.Specify("Add two actors with same id", func() {
		scene.Add(ActorId("foo"))
		_,err := scene.Add(ActorId("foo"))
		
		c.Specify("returns error containing the duplicate actor id", func() {
			c.Expect(err, Not(IsNil))
			// TODO: test string ending with foo
			c.Expect(true, Equals, false)
		})
		
	})

	c.Specify("Add two properties of same type to one actor", func() {
		a,_ := scene.Add(ActorId("a"))
		p1, p2 := NewProperty(1), NewProperty(1)
		a.Add(p1)
		err := a.Add(p2)

		c.Specify("returns error contains the duplicate property type id", func() {
			c.Expect(err, Not(IsNil))
			// TODO: test string ending with type id
			c.Expect(true, Equals, false)
		})
	})

	c.Specify("Add two actors with different properties", func() {
		p1, p2 := NewProperty(1), NewProperty(2)
		a, _ := scene.Add(ActorId("a"))
		a.Add(p1)
		b, _ := scene.Add(ActorId("b"))
		b.Add(p2)

		c.Specify("both actors contain those properties", func() {<commit_msg>fixed tests<commit_after>package scene

import (
	"github.com/orfjackal/gospec"
	. "github.com/orfjackal/gospec"
	"strings"
)

type SomeProperty struct {
	tid PropertyType
}

func NewProperty(t PropertyType) Property {
	return &SomeProperty{t}
}

func (p *SomeProperty) Type() PropertyType {
	return p.tid
}

func CtorSpec(c gospec.Context) {
	c.Specify("New scene", func() {
		scene := NewScene()

		c.Specify("has zero actors", func() {
			c.Expect(len(scene.Actors), Equals, 0)
		})

		c.Specify("has zero cached by property", func() {
			c.Expect(len(scene.byProperty), Equals, 0)
		})
	})
}

func AddSpec(c gospec.Context) {
	scene := NewScene()

	c.Specify("New actor always has reference to creating scene", func() {
		a,_ := scene.Add(ActorId("a"))
		
		c.Expect(a.s, IsSame, scene)
	})

	c.Specify("Add one actor with one property", func() {
		p1 := NewProperty(1)
		a, _ := scene.Add(ActorId("a"))
		a.Add(p1)

		c.Specify("scene contains just that one actor", func() {
			c.Expect(len(scene.Actors), Equals, 1)
			c.Expect(scene.Actors["a"], IsSame, a)

			c.Expect(len(scene.byProperty), Equals, 1)
			c.Expect(scene.byProperty[1], Contains, a)
		})

		c.Specify("actor contains that property", func() {
			c.Expect(len(a.properties), Equals, 1)
			c.Expect(a.properties[1], IsSame, p1)
		})
	})

	c.Specify("Add two actors with same id", func() {
		scene.Add(ActorId("foo"))
		_,e := scene.Add(ActorId("foo"))
		
		c.Specify("returns error containing the duplicate actor id", func() {
			c.Expect(e, Not(IsNil))
			c.Expect(e, Satisfies, strings.Contains(e.Error(), "foo"))
		})
		
	})

	c.Specify("Add two properties of same type to one actor", func() {
		a,_ := scene.Add(ActorId("a"))
		p1, p2 := NewProperty(42), NewProperty(42)
		a.Add(p1)
		e := a.Add(p2)

		c.Specify("returns error contains the duplicate property type id", func() {
			c.Expect(e, Not(IsNil))
			c.Expect(e, Satisfies, strings.Contains(e.Error(), "42"))
		})
	})

	c.Specify("Add two actors with different properties", func() {
		p1, p2 := NewProperty(1), NewProperty(2)
		a, _ := scene.Add(ActorId("a"))
		a.Add(p1)
		b, _ := scene.Add(ActorId("b"))
		b.Add(p2)

		c.Specify("both actors contain those properties", func() {
{'fraction_non_alphanumeric': 0.17404992129525523, 'fraction_numerical': 0.011243534967393748, 'mean_word_length': 3.9312638580931263, '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': '1958311', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1651, 'n_words': 391}