예제 #1
0
        public static void HaveEqualEquatorEdgePermutation(CubieCube expected, CubieCube actual)
        {
            CubingAssert.HasFourEquatorEdges(expected);
            CubingAssert.HasFourEquatorEdges(actual);

            IEnumerator <(Edge edge, int index)> enumerator1 = expected.EdgePermutation.Select((edge, index) => (edge, index)).GetEnumerator();
            IEnumerator <(Edge edge, int index)> enumerator2 = actual.EdgePermutation.Select((edge, index) => (edge, index)).GetEnumerator();

            for (int equatorEdge = 0; equatorEdge < Constants.NumEquatorEdges; equatorEdge++)
            {
                while (enumerator1.MoveNext() && enumerator1.Current.edge < Edge.FR)
                {
                    ;
                }
                while (enumerator2.MoveNext() && enumerator2.Current.edge < Edge.FR)
                {
                    ;
                }

                if (enumerator1.Current.edge != enumerator2.Current.edge)
                {
                    throw new AssertFailedException("The two cubes do not have the same equator edge permutation: " +
                                                    enumerator1.Current.edge + " at index " + enumerator1.Current.index + " of " + nameof(expected) + " is not equal to " +
                                                    enumerator2.Current.edge + " at index " + enumerator2.Current.index + " of " + nameof(actual) + ".");
                }
            }
        }
예제 #2
0
        public void EquatorPermutationCoordTest() //Tests GetEquatorPermutationCoord, SetEquatorPermutationCoord
        {
            Random random      = new Random(7777777);
            int    length      = 50;
            int    repetitions = 50;

            //if solved permutation corresponds to the coordinate 0
            //SetEquatorPermutationCoord()
            CubieCube expected = CubieCube.CreateSolved();
            CubieCube result   = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));

            Coordinates.SetEquatorOrder(result, 0);
            CubingAssert.HaveEqualEquatorEdgePermutation(expected, result);

            expected = CubieCube.FromAlg(Alg.FromString("R2 L2"));
            result   = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
            Coordinates.SetEquatorOrder(result, Coordinates.NumEquatorOrders - 1);

            //GetEquatorPermutationCoord()
            result = CubieCube.CreateSolved();
            Assert.AreEqual(0, Coordinates.GetEquatorOrder(result));

            result.ApplyAlg(Alg.FromString("F' R' B' D' L2"));
            Assert.AreEqual(0, Coordinates.GetEquatorOrder(result));

            //apply B1
            int       expectedCoord = 17;
            CubieCube cube          = CubieCube.CreateSolved();

            cube.ApplyMove(Move.B1);
            int resultCoord = Coordinates.GetEquatorOrder(cube);

            Assert.AreEqual(expectedCoord, resultCoord);

            //apply B2
            expectedCoord = 6;
            cube          = CubieCube.CreateSolved();
            cube.ApplyMove(Move.B2);
            resultCoord = Coordinates.GetEquatorOrder(cube);
            Assert.AreEqual(expectedCoord, resultCoord);

            //if applying GetEquatorPermutationCoord() and SetEquatorPermutationCoord() results in the same array as at the beginning
            for (int repetition = 0; repetition < repetitions; repetition++)
            {
                expected = CubieCube.FromAlg(Alg.FromRandomMoves(length, random));
                result   = CubieCube.CreateSolved();

                int coord = Coordinates.GetEquatorOrder(expected);
                Coordinates.SetEquatorOrder(result, coord);

                CubingAssert.HaveEqualEquatorEdgePermutation(expected, result);
            }

            //exceptions
            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.GetEquatorOrder(null));

            Assert.ThrowsException <ArgumentNullException>(() => Coordinates.SetEquatorOrder(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorOrder(CubieCube.CreateSolved(), -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Coordinates.SetEquatorOrder(CubieCube.CreateSolved(), Coordinates.NumEquatorOrders));
        }