weather/cache_recent_test.go

21 lines
548 B
Go

package main
import "testing"
func TestAddRecentLocationLRU(t *testing.T) {
locA := Location{Lat: 1, Lon: 1, City: "A"}
locB := Location{Lat: 2, Lon: 2, City: "B"}
locC := Location{Lat: 3, Lon: 3, City: "C"}
recent := []Location{locA, locB}
recent = addRecentLocation(recent, locC, 3)
if len(recent) != 3 || !sameLocation(recent[0], locC) {
t.Fatalf("expected new location at front")
}
recent = addRecentLocation(recent, locB, 3)
if len(recent) != 3 || !sameLocation(recent[0], locB) {
t.Fatalf("expected B to move to front")
}
}