コード例 #1
0
        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
        }
コード例 #2
0
        public void Constructor_Throws()
        {
            var parameters = new HighlightParameters();

            // ReSharper disable ObjectCreationAsStatement
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(
                () => new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(null, parameters));
            Assert.Throws <ArgumentNullException>(
                () => new SimpleHighlightAlgorithm <int, Edge <int>, BidirectionalGraph <int, Edge <int> > >(null, null));
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper restore ObjectCreationAsStatement
        }
コード例 #3
0
        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));
        }