Exemplo n.º 1
0
        public void Height_is_the_difference_of_YOffset_and_BottomRightY(Claim[] claims)
        {
            var union = new UnionClaim(claims);

            union.Height
            .Should().Be(union.BottomRightY - union.YOffset);
        }
Exemplo n.º 2
0
        public void Width_is_the_difference_of_XOffset_and_BottomRightX(Claim[] claims)
        {
            var union = new UnionClaim(claims);

            union.Width
            .Should().Be(union.BottomRightX - union.XOffset);
        }
Exemplo n.º 3
0
        public void Is_idempotent(Claim claim)
        {
            var union = new UnionClaim(claim);

            union.Should().BeEquivalentTo(
                claim,
                o => o.Excluding(c => c.Id));
        }
Exemplo n.º 4
0
        public void Is_the_sum_of_composed_claims(IFixture fixture)
        {
            var xs = fixture.CreateMany <int>(6).OrderBy(i => i).ToArray();
            var ys = fixture.CreateMany <int>(6).OrderBy(i => i).ToArray();

            var a = (topLeft : (x : xs[1], y : ys[0]), bottomRight : (x : xs[4], y : ys[5]));
            var b = (topLeft : (x : xs[2], y : ys[1]), bottomRight : (x : xs[5], y : ys[3]));
            var c = (topLeft : (x : xs[0], y : ys[2]), bottomRight : (x : xs[3], y : ys[4]));

            var claimA = new Claim(fixture.Create <int>(), a.topLeft, a.bottomRight);
            var claimB = new Claim(fixture.Create <int>(), b.topLeft, b.bottomRight);
            var claimC = new Claim(fixture.Create <int>(), c.topLeft, c.bottomRight);

            var union = new UnionClaim(claimA, claimB, claimC);

            var X = (x : fixture.CreateRandomBetween(b.topLeft.x, c.bottomRight.x - 1),
                     y : fixture.CreateRandomBetween(c.topLeft.y, b.bottomRight.y - 1));
            var Y = (x : fixture.CreateRandomBetween(a.topLeft.x, b.topLeft.x - 1),
                     y : fixture.CreateRandomBetween(b.bottomRight.y, c.bottomRight.y - 1));
            var Z = (x : fixture.CreateRandomBetween(0, a.topLeft.x - 1),
                     y : fixture.CreateRandomBetween(0, c.topLeft.y - 1));

            using (new AssertionScope())
            {
                union[X.x, X.y].Should().Be(3,
                                            "because it is where 3 claims overlap" + FixtureToDebugString(X.x, X.y));
                union[Y.x, Y.y].Should().Be(2,
                                            "because it is where 2 claims overlap" + FixtureToDebugString(Y.x, Y.y));
                union[Z.x, Z.y].Should().Be(0,
                                            "because it is where no claims overlap" + FixtureToDebugString(Z.x, Z.y));
            }

            string FixtureToDebugString(int x, int y)
            {
                return
                    ($" (x: {x}, y: {y}," +
                     $" A: {claimA.XOffset}, {claimA.YOffset}, {claimA.Width}, {claimA.Height}," +
                     $" B: {claimB.XOffset}, {claimB.YOffset}, {claimB.Width}, {claimB.Height}," +
                     $" C: {claimC.XOffset}, {claimC.YOffset}, {claimC.Width}, {claimC.Height})" +
                     union.ToDebugString((x, y)));
            }
        }
Exemplo n.º 5
0
        public static int GetNumberOfSquareInchesWithinTwoOrMoreClaims(string[] input)
        {
            var union = new UnionClaim(
                input
                .Select(i => Claim.Parse(i))
                .ToArray());
            var n = 0;

            for (int i = 0; i < union.XOffset + union.Width; i++)
            {
                for (int j = 0; j < union.YOffset + union.Height; j++)
                {
                    if (union[i, j] >= 2)
                    {
                        n += 1;
                    }
                }
            }

            return(n);
        }
Exemplo n.º 6
0
 public static string ToDebugString(this UnionClaim @this, (int x, int y) p)
Exemplo n.º 7
0
 public Part2Solver(params Claim[] claims)
 {
     this.claims = claims;
     union       = new UnionClaim(claims);
 }