Beispiel #1
0
        public void GetPossibleChildNodes_must_work()
        {
            // Node from where childNodes should be calculated
            TwoBuckets tb1 = new TwoBuckets(3, 5, 2, 3);

            // Get the list with possible child nodes.
            IEnumerable <TwoBuckets> neighborVertices = GraphGenerator.GetNeighborVertices(tb1);

            // Expected NeighborNodes
            TwoBuckets tb2 = new TwoBuckets(3, 5, 3, 2); // Fill1From2
            TwoBuckets tb3 = new TwoBuckets(3, 5, 0, 5); // Fill2From1
            TwoBuckets tb4 = new TwoBuckets(3, 5, 0, 3); // Empty1
            TwoBuckets tb5 = new TwoBuckets(3, 5, 2, 0); // Empty2
            TwoBuckets tb6 = new TwoBuckets(3, 5, 2, 5); // Fill1
            TwoBuckets tb7 = new TwoBuckets(3, 5, 3, 3); // Fill2

            // Check result
            Assert.AreEqual(6, neighborVertices.Count());
            Assert.IsTrue(neighborVertices.Contains(tb2));
            Assert.IsTrue(neighborVertices.Contains(tb3));
            Assert.IsTrue(neighborVertices.Contains(tb4));
            Assert.IsTrue(neighborVertices.Contains(tb5));
            Assert.IsTrue(neighborVertices.Contains(tb6));
            Assert.IsTrue(neighborVertices.Contains(tb7));

            // Test special case
            TwoBuckets tb8 = new TwoBuckets(3, 5);

            neighborVertices = GraphGenerator.GetNeighborVertices(tb8);

            // Check Result
            Assert.AreEqual(2, neighborVertices.Count());
            Assert.IsTrue(neighborVertices.Contains(new TwoBuckets(3, 5, 0, 5)));
            Assert.IsTrue(neighborVertices.Contains(new TwoBuckets(3, 5, 3, 0)));
        }
        public void TryGetValue_must_work()
        {
            TwoBuckets tb1 = new TwoBuckets(3, 5, 2, 4);
            TwoBuckets tb2 = new TwoBuckets(2, 7, 1, 5);
            TwoBuckets tb3 = new TwoBuckets(4, 9, 3, 7);

            List <TwoBuckets> list = new List <TwoBuckets>
            {
                tb1,
                tb2,
                tb3
            };

            Assert.IsTrue(list.TryGetValue(new TwoBuckets(3, 5, 2, 4), out TwoBuckets tb4));
            Assert.AreEqual(tb1, tb4);
            Assert.IsTrue(object.ReferenceEquals(tb1, tb4));

            Assert.IsTrue(list.TryGetValue(new TwoBuckets(2, 7, 1, 5), out TwoBuckets tb5));
            Assert.AreEqual(tb2, tb5);
            Assert.IsTrue(object.ReferenceEquals(tb2, tb5));

            Assert.IsTrue(list.TryGetValue(new TwoBuckets(4, 9, 3, 7), out TwoBuckets tb6));
            Assert.AreEqual(tb3, tb6);
            Assert.IsTrue(object.ReferenceEquals(tb3, tb6));
        }
Beispiel #3
0
    public void Fourth_example()
    {
        var bucketOneSize = 7;
        var bucketTwoSize = 11;
        var goal          = 2;
        var startBucket   = Bucket.Two;
        var twoBuckets    = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);

        var actual = twoBuckets.Solve(goal);

        Assert.That(actual.Moves, Is.EqualTo(18));
        Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.Two));
        Assert.That(actual.OtherBucketContents, Is.EqualTo(7));
    }
Beispiel #4
0
    public void First_example()
    {
        var bucketOneSize = 3;
        var bucketTwoSize = 5;
        var goal          = 1;
        var startBucket   = Bucket.One;
        var twoBuckets    = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);

        var actual = twoBuckets.Solve(goal);

        Assert.That(actual.Moves, Is.EqualTo(4));
        Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.One));
        Assert.That(actual.OtherBucketContents, Is.EqualTo(5));
    }
Beispiel #5
0
    public void Fourth_example()
    {
        var bucketOneSize = 7;
        var bucketTwoSize = 11;
        var goal          = 2;
        var startBucket   = Bucket.Two;
        var twoBuckets    = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);

        var actual = twoBuckets.Solve(goal);

        Assert.Equal(18, actual.Moves);
        Assert.Equal(Bucket.Two, actual.GoalBucket);
        Assert.Equal(7, actual.OtherBucketContents);
    }
Beispiel #6
0
    public void First_example()
    {
        var bucketOneSize = 3;
        var bucketTwoSize = 5;
        var goal          = 1;
        var startBucket   = Bucket.One;
        var twoBuckets    = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);

        var actual = twoBuckets.Solve(goal);

        Assert.Equal(4, actual.Moves);
        Assert.Equal(Bucket.One, actual.GoalBucket);
        Assert.Equal(5, actual.OtherBucketContents);
    }
Beispiel #7
0
    public void Third_example()
    {
        var bucketOneSize = 7;
        var bucketTwoSize = 11;
        var goal          = 2;
        var startBucket   = Bucket.One;
        var twoBuckets    = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);

        var actual = twoBuckets.Solve(goal);

        Assert.Equal(14, actual.Moves);
        Assert.Equal(Bucket.One, actual.GoalBucket);
        Assert.Equal(11, actual.OtherBucketContents);
    }
Beispiel #8
0
        public void Fill_must_work()
        {
            TwoBuckets tb1 = new TwoBuckets(3, 5);

            Assert.IsTrue(tb1.CanFillB1());
            Assert.IsTrue(tb1.CanFillB2());

            TwoBuckets tb2 = tb1.FillB1();
            TwoBuckets tb3 = tb1.FillB2();

            Assert.AreEqual(3, tb2.contentBucket1);
            Assert.AreEqual(5, tb3.contentBucket2);

            Assert.IsFalse(tb2.CanFillB1());
            Assert.IsFalse(tb3.CanFillB2());
        }
Beispiel #9
0
        public void FillFrom_must_work()
        {
            TwoBuckets tb1 = new TwoBuckets(3, 5, 3, 0);
            TwoBuckets tb2 = new TwoBuckets(3, 5, 0, 5);

            Assert.IsTrue(tb1.CanFillB2());
            Assert.IsTrue(tb2.CanFillB1());

            TwoBuckets tb3 = tb1.FillB2FromB1();
            TwoBuckets tb4 = tb2.FillB1FromB2();

            Assert.AreEqual(0, tb3.contentBucket1);
            Assert.AreEqual(3, tb3.contentBucket2);
            Assert.AreEqual(3, tb4.contentBucket1);
            Assert.AreEqual(2, tb4.contentBucket2);

            TwoBuckets tb5 = new TwoBuckets(0, 0);

            Assert.IsNull(tb5.FillB1FromB2());
            Assert.IsNull(tb5.FillB2FromB1());
        }
Beispiel #10
0
        public void Empty_must_work()
        {
            TwoBuckets tb1 = new TwoBuckets(3, 5);

            Assert.IsFalse(tb1.CanEmptyB1());
            Assert.IsFalse(tb1.CanEmptyB2());

            TwoBuckets tb2 = tb1.FillB1();
            TwoBuckets tb3 = tb1.FillB2();

            Assert.AreEqual(3, tb2.contentBucket1);
            Assert.AreEqual(5, tb3.contentBucket2);

            Assert.IsTrue(tb2.CanEmptyB1());
            Assert.IsTrue(tb3.CanEmptyB2());

            TwoBuckets tb4 = tb2.EmptyB1();
            TwoBuckets tb5 = tb3.EmptyB2();

            Assert.AreEqual(0, tb4.contentBucket1);
            Assert.AreEqual(0, tb5.contentBucket2);
        }