Skip to content

Commit

Permalink
new test + vertexes>vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauddri committed Jan 14, 2015
1 parent 0d48696 commit d91ae86
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func bfs(g *Graph, start VertexId) {
next = []VertexId{}
for _, vertex := range queue {
visited[vertex] = true
neighbours := g.GetNeighbours(vertex).VertexesIter()
neighbours := g.GetNeighbours(vertex).VerticesIter()

for neighbour := range neighbours {

Expand Down
2 changes: 1 addition & 1 deletion bfs_shortest_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func bfsShortestPath(g *Graph, start VertexId) {
next = []VertexId{}
for _, vertex := range queue {
visited[vertex] = true
neighbours := g.GetNeighbours(vertex).VertexesIter()
neighbours := g.GetNeighbours(vertex).VerticesIter()

for neighbour := range neighbours {

Expand Down
22 changes: 11 additions & 11 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type VertexId uint

type Vertexes []VertexId
type Vertices []VertexId

type Edge struct {
Tail VertexId
Expand All @@ -17,8 +17,8 @@ type EdgesIterable interface {
EdgesIter() <-chan Edge
}

type VertexesIterable interface {
VertexesIter() <-chan VertexId
type VerticesIterable interface {
VerticesIter() <-chan VertexId
}

type Graph struct {
Expand All @@ -37,8 +37,8 @@ func NewGraph() *Graph {
func (g *Graph) EdgesIter() <-chan Edge {
ch := make(chan Edge)
go func() {
for from, connectedVertexes := range g.edges {
for to, _ := range connectedVertexes {
for from, connectedVertices := range g.edges {
for to, _ := range connectedVertices {
if from < to {
ch <- Edge{from, to}
}
Expand All @@ -49,7 +49,7 @@ func (g *Graph) EdgesIter() <-chan Edge {
return ch
}

func (g *Graph) VertexesIter() <-chan VertexId {
func (g *Graph) VerticesIter() <-chan VertexId {
ch := make(chan VertexId)
go func() {
for vertex, _ := range g.edges {
Expand Down Expand Up @@ -90,8 +90,8 @@ func (g *Graph) RemoveVertex(vertex VertexId) error {

delete(g.edges, vertex)

for _, connectedVertexes := range g.edges {
delete(connectedVertexes, vertex)
for _, connectedVertices := range g.edges {
delete(connectedVertices, vertex)
}

return nil
Expand Down Expand Up @@ -144,7 +144,7 @@ func (g *Graph) EdgesCount() int {
return g.edgesCount
}

func (g *Graph) GetNeighbours(vertex VertexId) VertexesIterable {
func (g *Graph) GetNeighbours(vertex VertexId) VerticesIterable {
iterator := func() <-chan VertexId {
ch := make(chan VertexId)
go func() {
Expand All @@ -158,7 +158,7 @@ func (g *Graph) GetNeighbours(vertex VertexId) VertexesIterable {
return ch
}

return VertexesIterable(&_vertexIterableHelper{iterFunc: iterator})
return VerticesIterable(&_vertexIterableHelper{iterFunc: iterator})
}

func (g *Graph) isVertex(vertex VertexId) (exist bool) {
Expand All @@ -182,6 +182,6 @@ type _vertexIterableHelper struct {
iterFunc func() <-chan VertexId
}

func (helper *_vertexIterableHelper) VertexesIter() <-chan VertexId {
func (helper *_vertexIterableHelper) VerticesIter() <-chan VertexId {
return helper.iterFunc()
}
8 changes: 4 additions & 4 deletions graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ func TestGraph(t *testing.T) {
}

c := g.EdgesIter()
opened := true

countEdge := 0
for _ = range c {
countEdge++
}

if g.EdgesCount() != countEdge && !opened {
if g.EdgesCount() != countEdge {
fmt.Println(countEdge, g.edges)
t.Error()
}

d := g.VertexesIter()
d := g.VerticesIter()
verticesCount := g.Order()
countVertices := 0

for _ = range d {
countVertices++
}

if countVertices != len(g.edges) {
if countVertices != verticesCount {
fmt.Println(countVertices, g.edges)
t.Error()
}
Expand Down

0 comments on commit d91ae86

Please sign in to comment.