Skip to content

Commit

Permalink
Issue 7 (#22)
Browse files Browse the repository at this point in the history
* improve code coverage of tests

* code coverage; small bugfix

* code coverage

* trivial coverage work

* improved test coverage
  • Loading branch information
mpgerlek authored Apr 20, 2018
1 parent 0e6d02e commit 146f4cd
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/proj/proj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCmd(t *testing.T) {
[]float64{0.0, 0.0},
nil,
}, {
"proj-epsg 9999 -inverse",
"proj -epsg 3395 -inverse",
[]float64{0.0, 0.0},
nil,
}, {
Expand All @@ -42,7 +42,7 @@ func TestCmd(t *testing.T) {
[]float64{12.0, 55.0},
[]float64{691875.63, 6098907.83},
}, {
"proj -inverse +proj=utm +zone=32 +ellps=GRS80",
"proj -verbose -inverse +proj=utm +zone=32 +ellps=GRS80",
[]float64{691875.63, 6098907.83},
[]float64{12.0, 55.0},
},
Expand Down
14 changes: 7 additions & 7 deletions core/Coordinate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ const (

// CoordAny just generically holds data, not assigned to a coordinate type.
// Because unions.
type CoordAny struct{ v [4]float64 }
type CoordAny struct{ V [4]float64 }

//---------------------------------------------------------------------

// ToLP returns a CoordLP
func (c *CoordAny) ToLP() *CoordLP {
return &CoordLP{Lam: c.v[0], Phi: c.v[1]}
return &CoordLP{Lam: c.V[0], Phi: c.V[1]}
}

// FromLP sets this CoordAny
func (c *CoordAny) FromLP(lp *CoordLP) {
c.v[0] = lp.Lam
c.v[1] = lp.Phi
c.V[0] = lp.Lam
c.V[1] = lp.Phi
}

// ToXY returns a CoordXY
func (c *CoordAny) ToXY() *CoordXY {
return &CoordXY{X: c.v[0], Y: c.v[1]}
return &CoordXY{X: c.V[0], Y: c.V[1]}
}

// FromXY sets this CoordAny
func (c *CoordAny) FromXY(xy *CoordXY) {
c.v[0] = xy.Y
c.v[1] = xy.Y
c.V[0] = xy.X
c.V[1] = xy.Y
}

//---------------------------------------------------------------------
Expand Down
39 changes: 39 additions & 0 deletions core/Coordinate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package core_test

import (
"testing"

"github.com/go-spatial/proj/core"
"github.com/stretchr/testify/assert"
)

func TestCoordinate(t *testing.T) {
assert := assert.New(t)

{
any := &core.CoordAny{V: [4]float64{1.0, 2.0, 3.0, 4.0}}
lp := any.ToLP()
assert.Equal(1.0, lp.Lam)
assert.Equal(2.0, lp.Phi)
lp.Lam = 10.0
lp.Phi = 20.0
any.FromLP(lp)
assert.Equal(10.0, any.V[0])
assert.Equal(20.0, any.V[1])
assert.Equal(3.0, any.V[2])
assert.Equal(4.0, any.V[3])
}
{
any := &core.CoordAny{V: [4]float64{1.0, 2.0, 3.0, 4.0}}
xy := any.ToXY()
assert.Equal(1.0, xy.X)
assert.Equal(2.0, xy.Y)
xy.X = 10.0
xy.Y = 20.0
any.FromXY(xy)
assert.Equal(10.0, any.V[0])
assert.Equal(20.0, any.V[1])
assert.Equal(3.0, any.V[2])
assert.Equal(4.0, any.V[3])
}
}
17 changes: 16 additions & 1 deletion core/Ellipsoid_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package core_test

import (
"fmt"
"testing"

"github.com/go-spatial/proj/core"
"github.com/go-spatial/proj/support"

"github.com/stretchr/testify/assert"
)

func TestEllipsoid(t *testing.T) {
assert := assert.New(t)
assert.True(true)

ps, err := support.NewProjString("+proj=utm +zone=32 +ellps=GRS80")
assert.NoError(err)
sys, _, err := core.NewSystem(ps)
assert.NoError(err)

e := sys.Ellipsoid

assert.Equal("GRS80", e.ID)

s := fmt.Sprintf("%s", e)
assert.True(len(s) > 1)
}
6 changes: 0 additions & 6 deletions core/Operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ func (op *Operation) GetSystem() *System {
func (op *Operation) GetDescription() *OperationDescription {
return op.Description
}

// GetSignature returns the operation type, the input type, and the output type
func (op *Operation) GetSignature() (OperationType, CoordType, CoordType) {
d := op.Description
return d.OperationType, d.InputType, d.OutputType
}
16 changes: 16 additions & 0 deletions core/OperationDescription_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package core_test

import (
"testing"

"github.com/go-spatial/proj/core"

"github.com/stretchr/testify/assert"
)

func TestOperationDescription(t *testing.T) {
assert := assert.New(t)

opDesc := core.OperationDescriptionTable["utm"]
assert.NotNil(opDesc)
}
26 changes: 26 additions & 0 deletions core/Operation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package core_test

import (
"fmt"
"testing"

"github.com/go-spatial/proj/core"
"github.com/go-spatial/proj/support"

"github.com/stretchr/testify/assert"
)

func TestOperation(t *testing.T) {
assert := assert.New(t)

ps, err := support.NewProjString("+proj=utm +zone=32 +ellps=GRS80")
assert.NoError(err)
_, opx, err := core.NewSystem(ps)
assert.NoError(err)

s := fmt.Sprintf("%s", opx)
assert.True(len(s) > 1)

id := opx.GetDescription().ID
assert.Equal("utm", id)
}
2 changes: 2 additions & 0 deletions core/System_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func TestSystem(t *testing.T) {
assert.NoError(err)
assert.NotNil(sys)
assert.NotNil(op)

assert.NotEqual("", sys.String())
}

func TestProjStringValidation(t *testing.T) {
Expand Down
17 changes: 17 additions & 0 deletions gie/Gie_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gie_test

import (
"testing"

"github.com/go-spatial/proj/gie"

"github.com/stretchr/testify/assert"
)

func TestGie(t *testing.T) {
assert := assert.New(t)

g, err := gie.NewGie(".")
assert.NoError(err)
assert.NotNil(g)
}
4 changes: 4 additions & 0 deletions merror/Error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ func TestError(t *testing.T) {
exp3 := "wrapped error (from merror_test.TestError at Error_test.go:28)"
exp3 += " // Inner: " + exp2
assert.Equal(exp3, err3.Error())

err4 := merror.Pass(err2)
assert.Error(err4)
assert.Equal(exp2, err4.Error())
}
14 changes: 10 additions & 4 deletions mlog/Log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"strings"
"syscall"
"testing"

Expand Down Expand Up @@ -66,6 +67,8 @@ func TestLogger(t *testing.T) {
mlog.Printf("print %s", "2")
e := fmt.Errorf("E")
mlog.Error(e)
x := "yow"
mlog.Printv(x)

mlog.DebugEnabled = false
mlog.InfoEnabled = false
Expand All @@ -87,9 +90,12 @@ func TestLogger(t *testing.T) {
assert.NoError(err)
buf = buf[0:n]

ex1 := "[DEBUG] Log_test.go:65: debug 1"
ex2 := "[LOG] Log_test.go:66: print 2"
ex3 := "[ERROR] E"
expected := ex1 + "\n" + ex2 + "\n" + ex3 + "\n"
ex := []string{
"[DEBUG] Log_test.go:66: debug 1",
"[LOG] Log_test.go:67: print 2",
"[ERROR] E",
"[LOG] Log_test.go:71: \"yow\"",
}
expected := strings.Join(ex, "\n") + "\n"
assert.Equal(expected, string(buf))
}
18 changes: 18 additions & 0 deletions support/Aasincos_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package support_test

import (
"math"
"testing"

"github.com/go-spatial/proj/support"
"github.com/stretchr/testify/assert"
)

func TestAasincos(t *testing.T) {
assert := assert.New(t)

assert.InDelta(math.Asin(0.5), support.Aasin(0.5), 1.0e-8)
assert.InDelta(math.Asin(0.5), support.Aasin(0.5), 1.0e-8)
assert.InDelta(math.Sqrt(0.5), support.Asqrt(0.5), 1.0e-8)
assert.InDelta(math.Atan2(0.5, 0.5), support.Aatan2(0.5, 0.5), 1.0e-8)
}
15 changes: 15 additions & 0 deletions support/Adjlon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package support_test

import (
"math"
"testing"

"github.com/go-spatial/proj/support"
"github.com/stretchr/testify/assert"
)

func TestAdjlon(t *testing.T) {
assert := assert.New(t)

assert.InDelta(math.Pi*0.5, support.Adjlon(math.Pi*2.5), 1.0e-8)
}
18 changes: 18 additions & 0 deletions support/ParseDate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package support_test

import (
"testing"

"github.com/go-spatial/proj/support"
"github.com/stretchr/testify/assert"
)

func TestParseDate(t *testing.T) {
assert := assert.New(t)

assert.InDelta(0.0, support.ParseDate("yow"), 1.0e-8)
assert.InDelta(1999.5, support.ParseDate("1999.50"), 1.0e-8)
assert.InDelta(2000.0, support.ParseDate("1999.99999999"), 1.0e-8)
assert.InDelta(1999.0+(12.0*31.0-1.0)/(12.0*31.0), support.ParseDate("1999-12-31"), 1.0e-8)
assert.InDelta(1999.0+(6.0*31.0)/(12.0*31.0), support.ParseDate("1999-07-01"), 1.0e-8)
}
2 changes: 2 additions & 0 deletions support/ProjString_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ func TestPairListParsing(t *testing.T) {
assert.False(pl.ContainsKey("+k1"))

assert.Equal("k5", pl.Get(3).Value)

assert.True(len(pl.String()) > 10)
}

0 comments on commit 146f4cd

Please sign in to comment.