mirror of https://github.com/perkeep/perkeep.git
search: add LocationConstraint tests, make Any work
Change-Id: I1a13f0cc7333bb209edcd7f28184a10efeee544d
This commit is contained in:
parent
a0caaa3bec
commit
abc247c34d
|
@ -589,3 +589,31 @@ func TestMatchPrefix(t *testing.T) {
|
|||
t.Error("Expected simple mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocationConstraint(t *testing.T) {
|
||||
var c LocationConstraint
|
||||
if c.matchesLatLong(1, 2) {
|
||||
t.Error("zero value shouldn't match")
|
||||
}
|
||||
c.Any = true
|
||||
if !c.matchesLatLong(1, 2) {
|
||||
t.Error("Any should match")
|
||||
}
|
||||
|
||||
c = LocationConstraint{North: 2, South: 1, West: 0, East: 2}
|
||||
tests := []struct {
|
||||
lat, long float64
|
||||
want bool
|
||||
}{
|
||||
{1, 1, true},
|
||||
{3, 1, false}, // too north
|
||||
{1, 3, false}, // too east
|
||||
{1, -1, false}, // too west
|
||||
{0, 1, false}, // too south
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := c.matchesLatLong(tt.lat, tt.long); got != tt.want {
|
||||
t.Errorf("matches(%v, %v) = %v; want %v", tt.lat, tt.long, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,7 +463,7 @@ type LocationConstraint struct {
|
|||
}
|
||||
|
||||
func (c *LocationConstraint) matchesLatLong(lat, long float64) bool {
|
||||
return c.West <= long && long <= c.East && c.South <= lat && lat <= c.North
|
||||
return c.Any || (c.West <= long && long <= c.East && c.South <= lat && lat <= c.North)
|
||||
}
|
||||
|
||||
// A StringConstraint specifies constraints on a string.
|
||||
|
|
Loading…
Reference in New Issue