forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: abstract edgeid2weight and related operation together
issue: #351
- Loading branch information
1 parent
d0f2f94
commit bd1b43a
Showing
3 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package stationgraph | ||
|
||
import "github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" | ||
|
||
type place2placeID struct { | ||
from common.PlaceID | ||
to common.PlaceID | ||
} | ||
type edgeID2EdgeData map[place2placeID]*common.Weight | ||
|
||
func newEdgeID2EdgeData() edgeID2EdgeData { | ||
return make(edgeID2EdgeData, 5000000) | ||
} | ||
|
||
func (edge2Weight edgeID2EdgeData) get(id place2placeID) *common.Weight { | ||
return edge2Weight[id] | ||
} | ||
|
||
func (edge2Weight edgeID2EdgeData) add(id place2placeID, weight *common.Weight) { | ||
edge2Weight[id] = weight | ||
} |
61 changes: 61 additions & 0 deletions
61
integration/service/oasis/stationgraph/edge_2_weight_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package stationgraph | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/Telenav/osrm-backend/integration/service/oasis/internal/common" | ||
"github.com/Telenav/osrm-backend/integration/service/oasis/stationfinder/stationfindertype" | ||
) | ||
|
||
func TestEdgeID2EdgeDataGetResultShouldEqualsToSetValue(t *testing.T) { | ||
cases := []struct { | ||
key place2placeID | ||
value *common.Weight | ||
}{ | ||
// case 1 | ||
{ | ||
place2placeID{ | ||
111, | ||
222, | ||
}, | ||
&common.Weight{ | ||
Duration: 111.0, | ||
Distance: 222.0, | ||
}, | ||
}, | ||
// case 2 | ||
{ | ||
place2placeID{ | ||
stationfindertype.OrigLocationID, | ||
stationfindertype.DestLocationID, | ||
}, | ||
&common.Weight{ | ||
Duration: 333.0, | ||
Distance: 444.0, | ||
}, | ||
}, | ||
} | ||
|
||
edgeID2Data := newEdgeID2EdgeData() | ||
for _, c := range cases { | ||
edgeID2Data.add(c.key, c.value) | ||
} | ||
|
||
for _, c := range cases { | ||
actualValue := edgeID2Data.get(c.key) | ||
if !reflect.DeepEqual(c.value, actualValue) { | ||
t.Errorf("Expect to get value %#v for key %#v but got %#v\n", c.value, c.key, actualValue) | ||
} | ||
} | ||
} | ||
|
||
func TestEdgeID2EdgeDataWhenGetUnsettedKeyShouldGetNil(t *testing.T) { | ||
edgeID2Data := newEdgeID2EdgeData() | ||
actualValue := edgeID2Data.get(place2placeID{ | ||
stationfindertype.OrigLocationID, | ||
stationfindertype.DestLocationID}) | ||
if actualValue != nil { | ||
t.Errorf("Expect to get nil for unsetted key but got %#v\n", actualValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters