Ejemplo n.º 1
0
        public void TestUnion()
        {
            var n1 = new UnionFindNode();
            var n2 = new UnionFindNode();
            var n3 = new UnionFindNode();
            var n4 = new UnionFindNode();
            var n5 = new UnionFindNode();


            Assert.True(n1.Union(n2));
            Assert.True(n2.Union(n3));
            Assert.False(n3.Union(n1));

            Assert.True(n4.Union(n5));
            Assert.False(n5.Union(n4));

            Assert.True(n1.IsUnionedWith(n1));
            Assert.True(n2.IsUnionedWith(n2));
            Assert.True(n1.IsUnionedWith(n2));
            Assert.True(n1.IsUnionedWith(n3));

            Assert.False(n4.IsUnionedWith(n1));
            Assert.False(n5.IsUnionedWith(n2));

            Assert.True(n4.IsUnionedWith(n5));
        }
 private static void Combine(UnionFindNode <char> current, UnionFindNode <char> n, char shapeChar)
 {
     if (n.Value == shapeChar)
     {
         n.Union(current);
     }
 }
Ejemplo n.º 3
0
        public void Trivial_Test()
        {
            var n1 = new UnionFindNode();
            var n2 = new UnionFindNode();

            Assert.True(n1.IsUnionedWith(n1));
            Assert.False(n1.IsUnionedWith(n2));

            Assert.Throws <ArgumentNullException>(() => n1.Union(null));
            Assert.Throws <ArgumentNullException>(() => n1.IsUnionedWith(null));
        }
Ejemplo n.º 4
0
    public void TestTrivial2()
    {
        var r1 = new UnionFindNode();
        var r2 = new UnionFindNode();
        var r3 = new UnionFindNode();

        Assert.IsTrue(!r1.IsUnionedWith(r2));
        Assert.IsTrue(!r1.IsUnionedWith(r3));
        Assert.IsTrue(!r2.IsUnionedWith(r3));

        Assert.IsTrue(r1.Union(r3));
        Assert.IsTrue(!r1.IsUnionedWith(r2));
        Assert.IsTrue(r1.IsUnionedWith(r3));
        Assert.IsTrue(!r2.IsUnionedWith(r3));

        Assert.IsTrue(r1.Union(r2));
        Assert.IsTrue(r1.IsUnionedWith(r2));
        Assert.IsTrue(r1.IsUnionedWith(r3));
        Assert.IsTrue(r2.IsUnionedWith(r3));

        Assert.IsTrue(!r1.Union(r3));
    }