Skip to content

Commit

Permalink
test: Add test for vertices and edge count in pgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
jhu960213 committed Nov 13, 2021
1 parent 0652273 commit 725da49
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pgraph/pgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

//go:build !root
// +build !root

package pgraph

import (
"reflect"
"strconv"
"testing"
)

Expand Down Expand Up @@ -49,6 +51,49 @@ func TestCount1(t *testing.T) {
}
}

func TestCountNodesAndEdges(t *testing.T) {

G := &Graph{Name: "MyG"}

if i := G.NumVertices(); i != 0 {
t.Errorf("should have 0 vertices instead of: %d", i)
}

if i := G.NumEdges(); i != 0 {
t.Errorf("should have 0 edges instead of: %d", i)
}

// add vertices
var vertices [6]Vertex
for i := 0; i < len(vertices); i++ {
var name string = "v" + strconv.Itoa(i+1)
vertices[i] = NV(name)
}

// add edges
var edges [5]Edge
for x := 0; x < len(edges); x++ {
var name string = "e" + strconv.Itoa(x+1)
edges[x] = NE(name)
}

// add edges and vertices to graph
for a := 0; a < len(vertices); a++ {
var b int = a + 1
if a <= len(vertices)-1 {
G.AddVertex(vertices[a], vertices[b], edges[a])
}
}

if y := G.NumVertices(); y != 6 {
t.Errorf("should have 6 vertices instead of: %d", y)
}

if w := G.NumEdges(); w != 5 {
t.Errorf("should have 5 edges instead of: %d", w)
}
}

func TestAddVertex1(t *testing.T) {
G := &Graph{Name: "g2"}
v1 := NV("v1")
Expand Down

0 comments on commit 725da49

Please sign in to comment.