Skip to content

Instantly share code, notes, and snippets.

@jirkapenzes
Created August 7, 2014 21:54
Show Gist options
  • Select an option

  • Save jirkapenzes/671a1e2c9e8038ea6241 to your computer and use it in GitHub Desktop.

Select an option

Save jirkapenzes/671a1e2c9e8038ea6241 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace GraphAnalyzer.Core.Graph.Tests
{
class GraphTests
{
[Test]
public void Graph_AddVertex_Added()
{
var graph = CreateEmptyGraph();
graph.AddVertex(new Vertex<string>("V1"));
graph.AddVertex(new Vertex<string>("V2"));
Assert.That(() => graph.Vertices, Has.Count.EqualTo(2));
}
[Test]
public void Graph_AddDuplicityVertex_ThrowException()
{
var graph = CreateEmptyGraph();
graph.AddVertex(new Vertex<string>("V1"));
Assert.That(() => graph.AddVertex(new Vertex<string>("V1")), Throws.TypeOf<Exception>());
}
private Graph<string, int> CreateEmptyGraph()
{
return new Graph<string, int>();
}
private Graph<string, int> CreateSampleGraph()
{
var graph = new Graph<string, int>();
var v1 = new Vertex<string>("V1");
var v2 = new Vertex<string>("V2");
var v3 = new Vertex<string>("V3");
var v4 = new Vertex<string>("V4");
graph.AddVertex(v1);
graph.AddVertex(v2);
graph.AddVertex(v3);
graph.AddVertex(v4);
graph.AddEdge(new Edge<string, int>(v1, v2, 10));
graph.AddEdge(new Edge<string, int>(v1, v3, 20));
graph.AddEdge(new Edge<string, int>(v2, v3, 30));
graph.AddEdge(new Edge<string, int>(v3, v4, 40));
return graph;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment