Exemplo n.º 1
0
func CoordsInsertTestImpl(t *testing.T, simpleCoords geom.ReadWriteCoords, pointFactory func(...float64) geom.Point) {
	assert.True(t, simpleCoords.IsEmpty())

	assert.Panics(t, func() { simpleCoords.Insert(1, pointFactory(66, 32)) })
	assert.Equal(t, 0, int(simpleCoords.NumCoords()), "Number of coordinates should be the 0")

	assert.True(t, simpleCoords.IsEmpty())

	simpleCoords.Insert(0, pointFactory(1, 2))
	assert.Equal(t, int(simpleCoords.NumCoords()), 1, "Number of coordinates should be the 1")
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	assert.False(t, simpleCoords.IsEmpty())

	assert.Panics(t, func() { simpleCoords.Insert(2, pointFactory(66, 32)) })
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	simpleCoords.Insert(0, pointFactory(-1, 0))
	assert.Equal(t, 2, int(simpleCoords.NumCoords()), "Number of coordinates should be the 2")
	assert.Equal(t, []float64{-1, 0}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	simpleCoords.Insert(1, pointFactory(1, 1))
	assert.Equal(t, 3, int(simpleCoords.NumCoords()), "Number of coordinates should be the 3")
	assert.Equal(t, []float64{-1, 0}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{1, 1}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(2).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	assert.Panics(t, func() { simpleCoords.Insert(1, pointFactory(1, 1, 4)) })
	assert.Equal(t, 3, int(simpleCoords.NumCoords()), "Number of coordinates should be the 3")
	assert.Equal(t, []float64{-1, 0}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{1, 1}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(2).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
}
Exemplo n.º 2
0
func CoordsAddTestImpl(t *testing.T, simpleCoords geom.ReadWriteCoords, pointFactory func(...float64) geom.Point) {
	simpleCoords.Add(pointFactory(1, 2))
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	simpleCoords.Add(pointFactory(3, 4))
	assert.Equal(t, 2, int(simpleCoords.NumCoords()), "Number of coordinates should be the 2")
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{3, 4}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))

	assert.Panics(t, func() { simpleCoords.Add(pointFactory(3, 4, 5)) })
	assert.Equal(t, 2, int(simpleCoords.NumCoords()), "Number of coordinates should be the 2")
	assert.Equal(t, []float64{1, 2}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{3, 4}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
}
Exemplo n.º 3
0
func CoordsInsertRawTestImpl(t *testing.T, simpleCoords geom.ReadWriteCoords) {
	assert.True(t, simpleCoords.IsEmpty())

	simpleCoords.InsertRaw(0, []float64{2, 3})
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")

	assert.False(t, simpleCoords.IsEmpty())

	assert.Panics(t, func() { simpleCoords.InsertRaw(0, []float64{2, 3, 4}) })
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")

	assert.Panics(t, func() { simpleCoords.InsertRaw(0, []float64{2}) })
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")

	assert.Panics(t, func() { simpleCoords.InsertRaw(0, []float64{2}) })
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")

	assert.Panics(t, func() { simpleCoords.InsertRaw(2, []float64{2, 3}) })
	assert.Equal(t, 1, int(simpleCoords.NumCoords()), "Number of coordinates should be the 1")

	simpleCoords.InsertRaw(1, []float64{4, 5})
	assert.Equal(t, 2, int(simpleCoords.NumCoords()), "Number of coordinates should be the 2")
	assert.Equal(t, []float64{2, 3}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{4, 5}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect second coordinate in %v", simpleCoords))

	simpleCoords.InsertRaw(1, []float64{3, 4})
	assert.Equal(t, 3, int(simpleCoords.NumCoords()), "Number of coordinates should be the 3")
	assert.Equal(t, []float64{2, 3}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{3, 4}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect second coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{4, 5}, simpleCoords.Get(2).ToArray(), fmt.Sprintf("Incorrect second coordinate in %v", simpleCoords))

	simpleCoords.InsertRaw(0, []float64{-1, 0})
	assert.Equal(t, 4, int(simpleCoords.NumCoords()), "Number of coordinates should be the 4")
	assert.Equal(t, []float64{-1, 0}, simpleCoords.Get(0).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{2, 3}, simpleCoords.Get(1).ToArray(), fmt.Sprintf("Incorrect first coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{3, 4}, simpleCoords.Get(2).ToArray(), fmt.Sprintf("Incorrect second coordinate in %v", simpleCoords))
	assert.Equal(t, []float64{4, 5}, simpleCoords.Get(3).ToArray(), fmt.Sprintf("Incorrect second coordinate in %v", simpleCoords))
}