<commit_before>package coord

import (
	"github.com/ghthor/engine/time"
	"github.com/ghthor/gospec"
	. "github.com/ghthor/gospec"
)

func DescribeDirection(c gospec.Context) {
	c.Specify("North is parallel to South", func() {
		c.Expect(North.IsParallelTo(North), IsTrue)
		c.Expect(North.IsParallelTo(South), IsTrue)
		c.Expect(North.IsParallelTo(East), IsFalse)
		c.Expect(North.IsParallelTo(West), IsFalse)

		c.Expect(South.IsParallelTo(North), IsTrue)
		c.Expect(South.IsParallelTo(South), IsTrue)
		c.Expect(South.IsParallelTo(East), IsFalse)
		c.Expect(South.IsParallelTo(West), IsFalse)
	})

	c.Specify("East is parallel to West", func() {
		c.Expect(East.IsParallelTo(North), IsFalse)
		c.Expect(East.IsParallelTo(South), IsFalse)
		c.Expect(East.IsParallelTo(East), IsTrue)
		c.Expect(East.IsParallelTo(West), IsTrue)

		c.Expect(West.IsParallelTo(North), IsFalse)
		c.Expect(West.IsParallelTo(South), IsFalse)
		c.Expect(West.IsParallelTo(East), IsTrue)
		c.Expect(West.IsParallelTo(West), IsTrue)
	})

	c.Specify("converts to a string", func() {
		c.Expect(North.String(), Equals, "north")
		c.Expect(East.String(), Equals, "east")
		c.Expect(South.String(), Equals, "south")
		c.Expect(West.String(), Equals, "west")
	})
}

func DescribeCell(c gospec.Context) {
	cell := Cell{0, 0}

	c.Specify("neighbors", func() {
		c.Expect(cell.Neighbor(North), Equals, Cell{0, 1})
		c.Expect(cell.Neighbor(East), Equals, Cell{1, 0})
		c.Expect(cell.Neighbor(South), Equals, Cell{0, -1})
		c.Expect(cell.Neighbor(West), Equals, Cell{-1, 0})
	})

	c.Specify("determining directions between points", func() {
		c.Expect(cell.DirectionTo(Cell{0, 1}), Equals, North)
		c.Expect(cell.DirectionTo(Cell{1, 0}), Equals, East)
		c.Expect(cell.DirectionTo(Cell{0, -1}), Equals, South)
		c.Expect(cell.DirectionTo(Cell{-1, 0}), Equals, West)

		defer func() {
			x := recover()
			c.Expect(x, Not(IsNil))
			c.Expect(x, Equals, "unable to calculate Direction")
		}()

		cell.DirectionTo(Cell{1, 1})
	})
}

func DescribePathAction(c gospec.Context) {

	// TODO This test might not cover really short durations
	c.Specify("should calculate partial cell percentages", func() {

		pa := PathAction{
			time.NewSpan(10, 20),
			Cell{0, 0},
			Cell{0, 1},
		}

		c.Specify("where the sum of the origin% and destination% equals 1.0", func() {
			for t := pa.Span.Start; t <= pa.Span.End; t++ {
				p := [...]PartialCell{
					pa.OrigPartial(t),
					pa.DestPartial(t),
				}

				sum := p[0].Percentage + p[1].Percentage
				/// I think the ϵ can be smaller, but it doesn't really matter at this point
				c.Expect(sum, IsWithin(0.000000000000000000000000000000000000000000000000000000000001), 1.0)
			}
		})

		c.Specify("where the origin% and destination%", func() {
			c.Specify("equal 1.0 and 0.0 if the time", func() {
				c.Specify("before the start of the action", func() {
					orig := pa.OrigPartial(pa.Span.Start - 1)
					dest := pa.DestPartial(pa.Span.Start - 1)

					c.Expect(orig.Percentage, Equals, 1.0)
					c.Expect(dest.Percentage, Equals, 0.0)
				})

				c.Specify("is the start of the action", func() {
					orig := pa.OrigPartial(pa.Span.Start)
					dest := pa.DestPartial(pa.Span.Start)

					c.Expect(orig.Percentage, Equals, 1.0)
					c.Expect(dest.Percentage, Equals, 0.0)
				})
			})

			c.Specify("equal 0.0 and 1.0 if the time", func() {
				c.Specify("is the end of the action", func() {
					orig := pa.OrigPartial(pa.Span.End)
					dest := pa.DestPartial(pa.Span.End)

					c.Expect(orig.Percentage, Equals, 0.0)
					c.Expect(dest.Percentage, Equals, 1.0)
				})

				c.Specify("after the end of the action", func() {
					orig := pa.OrigPartial(pa.Span.End + 1)
					dest := pa.DestPartial(pa.Span.End + 1)

					c.Expect(orig.Percentage, Equals, 0.0)
					c.Expect(dest.Percentage, Equals, 1.0)
				})
			})
		})
	})

	c.Specify("must know which cell's that it traverses through", func() {
		pa := PathAction{
			Dest: Cell{0, 0},
			Orig: Cell{0, 1},
		}

		c.Expect(pa.Traverses(Cell{0, 0}), IsTrue)
		c.Expect(pa.Traverses(Cell{0, 1}), IsTrue)
	})

	c.Specify("must know if it is traversing a cell at an instant in time", func() {
		clk, duration := time.Clock(0), int64(25)<commit_msg>Add an exception that a path isn't traversing a cell<commit_after>package coord

import (
	"github.com/ghthor/engine/time"
	"github.com/ghthor/gospec"
	. "github.com/ghthor/gospec"
)

func DescribeDirection(c gospec.Context) {
	c.Specify("North is parallel to South", func() {
		c.Expect(North.IsParallelTo(North), IsTrue)
		c.Expect(North.IsParallelTo(South), IsTrue)
		c.Expect(North.IsParallelTo(East), IsFalse)
		c.Expect(North.IsParallelTo(West), IsFalse)

		c.Expect(South.IsParallelTo(North), IsTrue)
		c.Expect(South.IsParallelTo(South), IsTrue)
		c.Expect(South.IsParallelTo(East), IsFalse)
		c.Expect(South.IsParallelTo(West), IsFalse)
	})

	c.Specify("East is parallel to West", func() {
		c.Expect(East.IsParallelTo(North), IsFalse)
		c.Expect(East.IsParallelTo(South), IsFalse)
		c.Expect(East.IsParallelTo(East), IsTrue)
		c.Expect(East.IsParallelTo(West), IsTrue)

		c.Expect(West.IsParallelTo(North), IsFalse)
		c.Expect(West.IsParallelTo(South), IsFalse)
		c.Expect(West.IsParallelTo(East), IsTrue)
		c.Expect(West.IsParallelTo(West), IsTrue)
	})

	c.Specify("converts to a string", func() {
		c.Expect(North.String(), Equals, "north")
		c.Expect(East.String(), Equals, "east")
		c.Expect(South.String(), Equals, "south")
		c.Expect(West.String(), Equals, "west")
	})
}

func DescribeCell(c gospec.Context) {
	cell := Cell{0, 0}

	c.Specify("neighbors", func() {
		c.Expect(cell.Neighbor(North), Equals, Cell{0, 1})
		c.Expect(cell.Neighbor(East), Equals, Cell{1, 0})
		c.Expect(cell.Neighbor(South), Equals, Cell{0, -1})
		c.Expect(cell.Neighbor(West), Equals, Cell{-1, 0})
	})

	c.Specify("determining directions between points", func() {
		c.Expect(cell.DirectionTo(Cell{0, 1}), Equals, North)
		c.Expect(cell.DirectionTo(Cell{1, 0}), Equals, East)
		c.Expect(cell.DirectionTo(Cell{0, -1}), Equals, South)
		c.Expect(cell.DirectionTo(Cell{-1, 0}), Equals, West)

		defer func() {
			x := recover()
			c.Expect(x, Not(IsNil))
			c.Expect(x, Equals, "unable to calculate Direction")
		}()

		cell.DirectionTo(Cell{1, 1})
	})
}

func DescribePathAction(c gospec.Context) {

	// TODO This test might not cover really short durations
	c.Specify("should calculate partial cell percentages", func() {

		pa := PathAction{
			time.NewSpan(10, 20),
			Cell{0, 0},
			Cell{0, 1},
		}

		c.Specify("where the sum of the origin% and destination% equals 1.0", func() {
			for t := pa.Span.Start; t <= pa.Span.End; t++ {
				p := [...]PartialCell{
					pa.OrigPartial(t),
					pa.DestPartial(t),
				}

				sum := p[0].Percentage + p[1].Percentage
				/// I think the ϵ can be smaller, but it doesn't really matter at this point
				c.Expect(sum, IsWithin(0.000000000000000000000000000000000000000000000000000000000001), 1.0)
			}
		})

		c.Specify("where the origin% and destination%", func() {
			c.Specify("equal 1.0 and 0.0 if the time", func() {
				c.Specify("before the start of the action", func() {
					orig := pa.OrigPartial(pa.Span.Start - 1)
					dest := pa.DestPartial(pa.Span.Start - 1)

					c.Expect(orig.Percentage, Equals, 1.0)
					c.Expect(dest.Percentage, Equals, 0.0)
				})

				c.Specify("is the start of the action", func() {
					orig := pa.OrigPartial(pa.Span.Start)
					dest := pa.DestPartial(pa.Span.Start)

					c.Expect(orig.Percentage, Equals, 1.0)
					c.Expect(dest.Percentage, Equals, 0.0)
				})
			})

			c.Specify("equal 0.0 and 1.0 if the time", func() {
				c.Specify("is the end of the action", func() {
					orig := pa.OrigPartial(pa.Span.End)
					dest := pa.DestPartial(pa.Span.End)

					c.Expect(orig.Percentage, Equals, 0.0)
					c.Expect(dest.Percentage, Equals, 1.0)
				})

				c.Specify("after the end of the action", func() {
					orig := pa.OrigPartial(pa.Span.End + 1)
					dest := pa.DestPartial(pa.Span.End + 1)

					c.Expect(orig.Percentage, Equals, 0.0)
					c.Expect(dest.Percentage, Equals, 1.0)
				})
			})
		})
	})

	c.Specify("must know which cell's that it traverses through", func() {
		pa := PathAction{
			Dest: Cell{0, 0},
			Orig: Cell{0, 1},
		}

		c.Expect(pa.Traverses(Cell{0, 0}), IsTrue)
		c.Expect(pa.Traverses(Cell{0, 1}), IsTrue)
		c.Expect(pa.Traverses(Cell{0, 2}), IsFalse)
	})

	c.Specify("must know if it is traversing a cell at an instant in time", func() {
		clk, duration := time.Clock(0), int64(25)
{'fraction_non_alphanumeric': 0.16927420303493707, 'fraction_numerical': 0.032231502176214566, 'mean_word_length': 3.7364902506963786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1166496', 'n_tokens_mistral': 3818, 'n_tokens_neox': 3195, 'n_words': 675}