X-Git-Url: https://git.hedgecode.org/?a=blobdiff_plain;f=chesshog-format%2Fsrc%2Ftest%2Fjava%2Forg%2Fhedgecode%2Fchess%2Ftcd%2FTCDParserTest.java;fp=chesshog-format%2Fsrc%2Ftest%2Fjava%2Forg%2Fhedgecode%2Fchess%2Ftcd%2FTCDParserTest.java;h=93ea7662558325d46bd8075c7acf75afdeea18bc;hb=3819e21945f32159d441ee441f2cd156fcd8389f;hp=0000000000000000000000000000000000000000;hpb=f1421939d7793592403888e95360eca9c6b4d77f;p=chesshog.git diff --git a/chesshog-format/src/test/java/org/hedgecode/chess/tcd/TCDParserTest.java b/chesshog-format/src/test/java/org/hedgecode/chess/tcd/TCDParserTest.java new file mode 100644 index 0000000..93ea766 --- /dev/null +++ b/chesshog-format/src/test/java/org/hedgecode/chess/tcd/TCDParserTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018-2019. Developed by Hedgecode. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hedgecode.chess.tcd; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.configuration.XMLConfiguration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import org.hedgecode.chess.AbstractPositionTest; +import org.hedgecode.chess.position.Parser; +import org.hedgecode.chess.position.Position; + +/** + * Tests for {@link TCDParser}. + * + * @author Dmitry Samoshin aka gotty + */ +@RunWith(JUnit4.class) +public class TCDParserTest extends AbstractPositionTest implements TCDPositionTest { + + @Test + public void testParse() throws Exception { + Parser tcdParser = TCDParser.getInstance(); + for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(AbstractXMLConfigTest.TESTS)) { + setPositionName( + String.format( + MSG_TCD_POSITION, testConfig.getString(AbstractPositionTest.NAME) + ) + ); + String tcd = testConfig.getString(TCD_TAG); + Position position = assignPosition( + testConfig.configurationAt(AbstractPositionTest.POSITION) + ); + assertPositionEquals( + position, + tcdParser.parse(tcd) + ); + } + } + + @Override + public List getXMLPositions() throws Exception { + List xmlPositions = new LinkedList<>(); + for (HierarchicalConfiguration testConfig : getXMLConfig().configurationsAt(AbstractXMLConfigTest.TESTS)) { + xmlPositions.add( + new XMLConfiguration( + testConfig.configurationAt(AbstractPositionTest.POSITION) + ) + ); + } + return xmlPositions; + } + +} \ No newline at end of file