tile38/internal/controller/token_test.go
tidwall 6257ddba78 Faster point in polygon / GeoJSON updates
The big change is that the GeoJSON package has been completely
rewritten to fix a few of geometry calculation bugs, increase
performance, and to better follow the GeoJSON spec RFC 7946.

GeoJSON updates

- A LineString now requires at least two points.
- All json members, even foreign, now persist with the object.
- The bbox member persists too but is no longer used for geometry
  calculations. This is change in behavior. Previously Tile38 would
  treat the bbox as the object's physical rectangle.
- Corrections to geometry intersects and within calculations.

Faster spatial queries

- The performance of Point-in-polygon and object intersect operations
  are greatly improved for complex polygons and line strings. It went
  from O(n) to roughly O(log n).
- The same for all collection types with many children, including
  FeatureCollection, GeometryCollection, MultiPoint, MultiLineString,
  and MultiPolygon.

Codebase changes

- The pkg directory has been renamed to internal
- The GeoJSON internal package has been moved to a seperate repo at
  https://github.com/tidwall/geojson. It's now vendored.

Please look out for higher memory usage for datasets using complex
shapes. A complex shape is one that has 64 or more points. For these
shapes it's expected that there will be increase of least 54 bytes per
point.
2018-10-13 04:30:48 -07:00

112 lines
2.4 KiB
Go

package controller
import (
"strings"
"testing"
)
func TestLowerCompare(t *testing.T) {
if !lc("hello", "hello") {
t.Fatal("failed")
}
if !lc("Hello", "hello") {
t.Fatal("failed")
}
if !lc("HeLLo World", "hello world") {
t.Fatal("failed")
}
if !lc("", "") {
t.Fatal("failed")
}
if lc("hello", "") {
t.Fatal("failed")
}
if lc("", "hello") {
t.Fatal("failed")
}
if lc("HeLLo World", "Hello world") {
t.Fatal("failed")
}
}
// func testParseFloat(t testing.TB, s string, f float64, invalid bool) {
// n, err := parseFloat(s)
// if err != nil {
// if invalid {
// return
// }
// t.Fatal(err)
// }
// if invalid {
// t.Fatalf("expecting an error for %s", s)
// }
// if n != f {
// t.Fatalf("for '%s', expect %f, got %f", s, f, n)
// }
// }
// func TestParseFloat(t *testing.T) {
// testParseFloat(t, "100", 100, false)
// testParseFloat(t, "0", 0, false)
// testParseFloat(t, "-1", -1, false)
// testParseFloat(t, "-0", -0, false)
// testParseFloat(t, "-100", -100, false)
// testParseFloat(t, "-0", -0, false)
// testParseFloat(t, "+1", 1, false)
// testParseFloat(t, "+0", 0, false)
// testParseFloat(t, "33.102938", 33.102938, false)
// testParseFloat(t, "-115.123123", -115.123123, false)
// testParseFloat(t, ".1", 0.1, false)
// testParseFloat(t, "0.1", 0.1, false)
// testParseFloat(t, "00.1", 0.1, false)
// testParseFloat(t, "01.1", 1.1, false)
// testParseFloat(t, "01", 1, false)
// testParseFloat(t, "-00.1", -0.1, false)
// testParseFloat(t, "+00.1", 0.1, false)
// testParseFloat(t, "", 0.1, true)
// testParseFloat(t, " 0", 0.1, true)
// testParseFloat(t, "0 ", 0.1, true)
// }
func BenchmarkLowerCompare(t *testing.B) {
for i := 0; i < t.N; i++ {
if !lc("HeLLo World", "hello world") {
t.Fatal("failed")
}
}
}
func BenchmarkStringsLowerCompare(t *testing.B) {
for i := 0; i < t.N; i++ {
if strings.ToLower("HeLLo World") != "hello world" {
t.Fatal("failed")
}
}
}
// func BenchmarkParseFloat(t *testing.B) {
// s := []string{"33.10293", "-115.1203102"}
// for i := 0; i < t.N; i++ {
// _, err := parseFloat(s[i%2])
// if err != nil {
// t.Fatal("failed")
// }
// }
// }
// func BenchmarkStrconvParseFloat(t *testing.B) {
// s := []string{"33.10293", "-115.1203102"}
// for i := 0; i < t.N; i++ {
// _, err := strconv.ParseFloat(s[i%2], 64)
// if err != nil {
// t.Fatal("failed")
// }
// }
// }