예제 #1
0
        public void PuzzleSet_Subset_Superset_Tests1()
        {
            var sut1       = new PuzzleSet(PuzzleSize.NineByNine);
            var allNumbers = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3, 4 });
            allNumbers.AddRange(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            TestContext.WriteLine("lowNumbers overlaps allNumbers: {0}",
                                  sut1.Overlaps(allNumbers));

            TestContext.WriteLine("allNumbers and lowNumbers are equal sets: {0}",
                                  allNumbers.SetEquals(sut1));

            // Show the results of sub/superset testing
            Assert.True(sut1.IsSubsetOf(allNumbers));
            Assert.True(allNumbers.IsSupersetOf(sut1));
            Assert.True(sut1.IsProperSubsetOf(allNumbers));
            Assert.True(allNumbers.IsProperSupersetOf(sut1));

            // Modify allNumbers to remove numbers that are not in sut1.
            allNumbers.IntersectWith(sut1);

            Assert.True(allNumbers.SetEquals(sut1));

            Assert.True(sut1.IsSubsetOf(allNumbers));
            Assert.True(allNumbers.IsSupersetOf(sut1));
            Assert.False(sut1.IsProperSubsetOf(allNumbers));
            Assert.False(allNumbers.IsProperSupersetOf(sut1));
        }
예제 #2
0
        public void PuzzleSet_AddRange_Test1()
        {
            foreach (var size in new[]
            {
                PuzzleSize.FourByFour,
                PuzzleSize.NineByNine,
                PuzzleSize.SixteenBySixteen
            })
            {
                var sut = new PuzzleSet(size);

                Assert.True(sut.AddRange(Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte)));
                Assert.Equal(sut.MaxValue, sut.Count);

                Assert.False(sut.AddRange(Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte)));
                Assert.Equal(sut.MaxValue, sut.Count);
            }
        }
예제 #3
0
        public void PuzzleSet_IntersectWith_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3, 4, 5 });
            sut2.AddRange(new byte[] { 3, 4, 5, 6, 7, 8, 9 });

            sut2.IntersectWith(sut1);

            Assert.Equal(new byte[] { 3, 4, 5 }, sut2);
        }
예제 #4
0
        public void PuzzleSet_SetEquals_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 1, 2, 3 });

            Assert.True(sut1.SetEquals(sut1));
            Assert.True(sut1.SetEquals(sut2));
            Assert.True(sut2.SetEquals(sut1));

            sut2.AddRange(new byte[] { 4, 5, 6 });

            sut2.AddRange(new byte[] { 7, 8, 9 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            Assert.False(sut1.SetEquals(sut2));
            Assert.False(sut2.SetEquals(sut3));
            Assert.False(sut1.SetEquals(sut3));
        }
예제 #5
0
        public void PuzzleSet_Overlaps_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            Assert.True(sut1.Overlaps(sut2));
            Assert.True(sut2.Overlaps(sut3));
            Assert.False(sut1.Overlaps(sut3));
        }
예제 #6
0
        public void PuzzleSet_UnionWith_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 4, 5, 6 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            sut1.UnionWith(sut3);
            Assert.Equal(new byte[] { 1, 2, 3, 7, 8, 9 }, sut1);

            sut1.UnionWith(sut2);
            Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, sut1);
        }
예제 #7
0
        public void PuzzleSet_CopyTo_Test1()
        {
            foreach (var size in new[]
            {
                PuzzleSize.FourByFour,
                PuzzleSize.NineByNine,
                PuzzleSize.SixteenBySixteen
            })
            {
                var sut = new PuzzleSet(size);
                Assert.True(sut.AddRange(Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte)));

                var actual = new byte[sut.MaxValue];
                sut.CopyTo(actual, 0);

                var expected = Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte).ToArray();
                Assert.Equal(expected, actual);
            }
        }