public void Constructor() { var graph = new BidirectionalGraph <int, Edge <int> >(); var controller = new TestHighlightController <int>(graph); var algorithm = new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(controller, null); AssertAlgorithmProperties(algorithm, controller); var parameters = new HighlightParameters(); algorithm = new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(controller, parameters); AssertAlgorithmProperties(algorithm, controller, parameters); #region Local function void AssertAlgorithmProperties( SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > > algo, IHighlightController <int, Edge <int>, BidirectionalGraph <int, Edge <int> > > c, HighlightParameters p = null) { Assert.AreSame(c, algo.Controller); if (p is null) { Assert.IsNull(((IHighlightAlgorithm <int, Edge <int> >)algo).Parameters); Assert.IsNull(algo.Parameters); } else { Assert.AreSame(p, ((IHighlightAlgorithm <int, Edge <int> >)algo).Parameters); Assert.AreSame(p, algo.Parameters); } } #endregion }
public void Highlight_Throws() { var graph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >(); var controller = new TestHighlightController <TestVertex>(graph); var algorithm = new SimpleHighlightAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(controller, null); // ReSharper disable AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => algorithm.OnVertexHighlighting(null)); Assert.Throws <ArgumentNullException>(() => algorithm.OnVertexHighlightRemoving(null)); Assert.Throws <ArgumentNullException>(() => algorithm.OnEdgeHighlighting(null)); Assert.Throws <ArgumentNullException>(() => algorithm.OnEdgeHighlightRemoving(null)); // ReSharper restore AssignNullToNotNullAttribute }
public void ResetHighlight() { var edge12 = new Edge <int>(1, 2); var edge13 = new Edge <int>(1, 3); var edge23 = new Edge <int>(2, 3); var edge24 = new Edge <int>(2, 4); var edge25 = new Edge <int>(2, 5); var edge33 = new Edge <int>(3, 3); var edge35 = new Edge <int>(3, 5); var graph = new BidirectionalGraph <int, Edge <int> >(); graph.AddVerticesAndEdgeRange(new[] { edge12, edge13, edge23, edge24, edge25, edge33, edge35 }); var controller = new TestHighlightController <int>(graph); var algorithm = new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(controller, null); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge35)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge35)); algorithm.ResetHighlight(); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge35)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge35)); algorithm.OnVertexHighlighting(3); algorithm.ResetHighlight(); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge35)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge35)); algorithm.OnEdgeHighlighting(edge35); algorithm.ResetHighlight(); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(1)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(2)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(3)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(4)); Assert.IsFalse(algorithm.Controller.IsHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedVertex(5)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge12)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge13)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge23)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge24)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge25)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge33)); Assert.IsFalse(algorithm.Controller.IsHighlightedEdge(edge35)); Assert.IsFalse(algorithm.Controller.IsSemiHighlightedEdge(edge35)); }
public void StandardFactory() { var graph = new BidirectionalGraph <int, Edge <int> >(); var context = new TestHighlightContext(graph); var controller = new TestHighlightController(graph); var factory = new StandardHighlightAlgorithmFactory <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(); CollectionAssert.AreEqual(new[] { "Simple" }, factory.HighlightModes); Assert.IsNull( factory.CreateAlgorithm( string.Empty, context, controller, new HighlightParameters())); Assert.IsInstanceOf <SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > > >( factory.CreateAlgorithm( "Simple", context, controller, new HighlightParameters())); Assert.IsInstanceOf <SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > > >( factory.CreateAlgorithm( "Simple", context, controller, null)); var parameters = new HighlightParameters(); IHighlightParameters createdParameters = factory.CreateParameters(string.Empty, parameters); Assert.IsInstanceOf <HighlightParameters>(createdParameters); Assert.AreNotSame(parameters, createdParameters); createdParameters = factory.CreateParameters("Simple", parameters); Assert.IsInstanceOf <HighlightParameters>(createdParameters); Assert.AreNotSame(parameters, createdParameters); createdParameters = factory.CreateParameters("Simple", null); Assert.IsInstanceOf <HighlightParameters>(createdParameters); Assert.AreNotSame(parameters, createdParameters); createdParameters = factory.CreateParameters("NotExist", null); Assert.IsNull(createdParameters); Assert.IsFalse(factory.IsValidMode(null)); Assert.IsTrue(factory.IsValidMode(string.Empty)); Assert.IsTrue(factory.IsValidMode("Simple")); Assert.IsFalse(factory.IsValidMode("simple")); var algorithm1 = new TestHighlightAlgorithm(controller, new HighlightParameters()); Assert.IsNull(factory.GetHighlightMode(algorithm1)); var algorithm2 = new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(controller, new HighlightParameters()); Assert.AreEqual("Simple", factory.GetHighlightMode(algorithm2)); }