示例#1
0
 public void BoggleGraphTest_Contains_Edge_WhenEdgePresent_ReturnsTrue()
 {
     BoggleEdge edge = new BoggleEdge(new BoggleNode(0, 0), new BoggleNode(1, 0));
     BoggleGraph graph = new BoggleGraph();
     graph.Add(edge);
     Assert.IsTrue(graph.Contains(edge));
 }
示例#2
0
 public void BoggleEdge_Equals_WhenAllVerticesAreNull_ReturnsTrue()
 {
     BoggleEdge one = new BoggleEdge(null, null);
     BoggleEdge two = new BoggleEdge(null, null);
     Assert.IsTrue(one.Equals(two));
     Assert.IsTrue(two.Equals(one));
 }
示例#3
0
        public void BoggleEdge_Equals_WhenEitherVertexIsNull_ReturnsFalse()
        {
            BoggleNode vOne = new BoggleNode(0, 0);
            BoggleNode vTwo = new BoggleNode(1, 0);

            BoggleEdge one = new BoggleEdge(vOne, vTwo);
            BoggleEdge two = new BoggleEdge(vOne, null);
            Assert.IsFalse(one.Equals(two));
            Assert.IsFalse(two.Equals(one));
            
            two.VertexOne = null;
            two.VertexTwo = vTwo;
            Assert.IsFalse(one.Equals(two));
            Assert.IsFalse(two.Equals(one));

            one.VertexOne = null;
            one.VertexTwo = vTwo;
            two.VertexOne = vOne;
            two.VertexTwo = vTwo;
            Assert.IsFalse(one.Equals(two));
            Assert.IsFalse(two.Equals(one));

            one.VertexOne = vOne;
            one.VertexTwo = null;
            two.VertexOne = vOne;
            two.VertexTwo = vTwo;
            Assert.IsFalse(one.Equals(two));
            Assert.IsFalse(two.Equals(one));
        }
示例#4
0
        public BoggleGraph Add(BoggleEdge edge)
        {
            if (_edges == null)
                _edges = new List<BoggleEdge>();

            if (edge != null && !this.Contains(edge))
                _edges.Add(edge);

            this.Add(edge.VertexOne);
            this.Add(edge.VertexTwo);

            return this;
        }
示例#5
0
        public void BoggleEdge_Equals_ReturnsTrueWhenBothAreEqual()
        {
            BoggleNode vOne = new BoggleNode(0, 0);
            BoggleNode vTwo = new BoggleNode(1, 0);

            BoggleEdge one = new BoggleEdge(vOne, vTwo);
            BoggleEdge two = new BoggleEdge(vOne, vTwo);

            Assert.IsTrue(one.Equals(two));
            Assert.IsTrue(two.Equals(one));

            // now swap the vertex orders - the edges should still be equal
            one.VertexOne = vOne;
            one.VertexTwo = vTwo;
            two.VertexOne = vTwo;
            two.VertexTwo = vOne;
            Assert.IsTrue(one.Equals(two));
            Assert.IsTrue(two.Equals(one));
        }
示例#6
0
        public bool Contains(BoggleEdge edge)
        {
            if (_edges == null || edge == null) return false;

            return _edges.Contains(edge);
        }
示例#7
0
        public void BoggleGraphTest_Add_Edge_DoesntAddDupes()
        {
            BoggleEdge edge = new BoggleEdge(new BoggleNode(0, 0), new BoggleNode(1, 0));
            BoggleGraph graph = new BoggleGraph();

            graph.Add(edge);
            Assert.IsTrue(graph.EdgeCount == 1);
            graph.Add(edge);
            Assert.IsTrue(graph.EdgeCount == 1);
            graph.Add(edge);
            Assert.IsTrue(graph.EdgeCount == 1);
        }
示例#8
0
        public void BoggleGraphTest_Equals_ReturnsTrueWhenEquals_RegardlesOfEdgeOrdering()
        {
            BoggleGraph g1 = new BoggleGraph();
            BoggleGraph g2 = new BoggleGraph();

            BoggleEdge e1 = new BoggleEdge(new BoggleNode(0, 0), new BoggleNode(1, 0));
            BoggleEdge e2 = new BoggleEdge(new BoggleNode(0, 0), new BoggleNode(0, 1));
            BoggleEdge e3 = new BoggleEdge(new BoggleNode(1, 0), new BoggleNode(1, 1));

            // insert edges out of order to verify that ordering doesn't effect graph equality
            g1.Add(e1);
            g1.Add(e2);
            g1.Add(e3);
            g2.Add(e3);
            g2.Add(e1);
            g2.Add(e2);

            Assert.AreEqual(g1, g2);
        }
示例#9
0
 public void BoggleEdge_Equals_WhenOneEdgeIsNull_ReturnsFalse()
 {
     BoggleEdge one = new BoggleEdge();
     BoggleEdge two = null;
     Assert.IsFalse(one.Equals(two));
 }