<commit_before>package cargo

import (
	"container/list"
	"testing"
	"time"

	"github.com/marcusolsson/goddd/location"

	. "gopkg.in/check.v1"
)

// Hook gocheck up to the "go test" runner
func Test(t *testing.T) { TestingT(t) }

type S struct{}

var _ = Suite(&S{})

func (s *S) TestConstruction(c *C) {
	trackingId := TrackingId("XYZ")
	specification := RouteSpecification{
		Origin:          location.Stockholm,
		Destination:     location.Melbourne,
		ArrivalDeadline: time.Date(2009, time.March, 13, 0, 0, 0, 0, time.UTC),
	}

	cargo := NewCargo(trackingId, specification)

	c.Check(cargo.Delivery.RoutingStatus, Equals, NotRouted)
	c.Check(cargo.Delivery.TransportStatus, Equals, NotReceived)
	c.Check(cargo.Delivery.LastKnownLocation, Equals, location.UnknownLocation)
}

func (s *S) TestEquality(c *C) {
	spec1 := RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	}
	spec2 := RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Melbourne,
	}

	c1 := NewCargo("ABC", spec1)
	c2 := NewCargo("CBA", spec1)
	c3 := NewCargo("ABC", spec2)
	c4 := NewCargo("ABC", spec1)

	c.Check(true, Equals, c1.Equal(c4))
	c.Check(true, Equals, c1.Equal(c3))
	c.Check(true, Equals, c3.Equal(c4))
	c.Check(false, Equals, c1.Equal(c2))
}

func (s *S) TestRepositoryFind(c *C) {
	c1 := NewCargo("ABC", RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	})

	r := NewCargoRepository()
	r.Store(*c1)

	c2, err := r.Find(TrackingId("ABC"))

	c.Assert(err, IsNil)
	c.Check(true, Equals, c1.Equal(&c2))
}

func (s *S) TestRepositoryFindAll(c *C) {
	c1 := NewCargo("ABC", RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	})

	c2 := NewCargo("CBA", RouteSpecification{
		Origin:      location.Hongkong,
		Destination: location.Stockholm,<commit_msg>Fix expected/obtained order in cargo tests.<commit_after>package cargo

import (
	"container/list"
	"testing"
	"time"

	"github.com/marcusolsson/goddd/location"

	. "gopkg.in/check.v1"
)

// Hook gocheck up to the "go test" runner
func Test(t *testing.T) { TestingT(t) }

type S struct{}

var _ = Suite(&S{})

func (s *S) TestConstruction(c *C) {
	trackingId := TrackingId("XYZ")
	specification := RouteSpecification{
		Origin:          location.Stockholm,
		Destination:     location.Melbourne,
		ArrivalDeadline: time.Date(2009, time.March, 13, 0, 0, 0, 0, time.UTC),
	}

	cargo := NewCargo(trackingId, specification)

	c.Check(cargo.Delivery.RoutingStatus, Equals, NotRouted)
	c.Check(cargo.Delivery.TransportStatus, Equals, NotReceived)
	c.Check(cargo.Delivery.LastKnownLocation, Equals, location.UnknownLocation)
}

func (s *S) TestEquality(c *C) {
	spec1 := RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	}
	spec2 := RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Melbourne,
	}

	c1 := NewCargo("ABC", spec1)
	c2 := NewCargo("CBA", spec1)
	c3 := NewCargo("ABC", spec2)
	c4 := NewCargo("ABC", spec1)

	c.Check(c1.Equal(c4), Equals, true)
	c.Check(c1.Equal(c3), Equals, true)
	c.Check(c3.Equal(c4), Equals, true)
	c.Check(c1.Equal(c2), Equals, false)
}

func (s *S) TestRepositoryFind(c *C) {
	c1 := NewCargo("ABC", RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	})

	r := NewCargoRepository()
	r.Store(*c1)

	c2, err := r.Find(TrackingId("ABC"))

	c.Assert(err, IsNil)
	c.Check(c1.Equal(&c2), Equals, true)
}

func (s *S) TestRepositoryFindAll(c *C) {
	c1 := NewCargo("ABC", RouteSpecification{
		Origin:      location.Stockholm,
		Destination: location.Hongkong,
	})

	c2 := NewCargo("CBA", RouteSpecification{
		Origin:      location.Hongkong,
		Destination: location.Stockholm,
{'fraction_non_alphanumeric': 0.1520127118644068, 'fraction_numerical': 0.019067796610169493, 'mean_word_length': 4.473913043478261, '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': '189941', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1462, 'n_words': 288}