* A valid pseudo Boolean expression is of the form {@code c_1 * l_1 + ... + c_n * l_n R k} where the {@code c_i} are coefficients, * {@code l_i} are literals, and {@code R} is one of {@code =, >, >=, <, <=}. - * @version 1.2 + * @version 2.4.1 * @since 1.0 */ public final class PseudoBooleanParser extends FormulaParser { diff --git a/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java b/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java index 5861444f..331f5f1b 100644 --- a/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java +++ b/src/test/java/org/logicng/io/parsers/PropositionalParserTest.java @@ -40,7 +40,7 @@ /** * Unit Tests for the class {@link PropositionalParser}. - * @version 2.0.0 + * @version 2.4.1 * @since 1.0 */ public class PropositionalParserTest extends TestWithExampleFormulas { @@ -72,6 +72,13 @@ public void testParseLiterals() throws ParserException { assertThat(parser.parse("~a1")).isEqualTo(this.f.literal("a1", false)); assertThat(parser.parse("~aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("aA_Bb_Cc_12_3", false)); assertThat(parser.parse("~@aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("@aA_Bb_Cc_12_3", false)); + assertThat(parser.parse("#")).isEqualTo(this.f.literal("#", true)); + assertThat(parser.parse("~#")).isEqualTo(this.f.literal("#", false)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("A#B")).isEqualTo(this.f.literal("A#B", true)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("#A#B_")).isEqualTo(this.f.literal("#A#B_", true)); + assertThat(parser.parse("~#A#B_")).isEqualTo(this.f.literal("#A#B_", false)); } @Test @@ -250,7 +257,7 @@ public void testIllegalFormula8() { @Test public void testIllegalFormula9() { - final String string = "#"; + final String string = "@A@B"; final InputStream stream = new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8)); assertThatThrownBy(() -> new PropositionalParser(this.f).parse(stream)).isInstanceOf(ParserException.class); } diff --git a/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java b/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java index 57748952..c98547e8 100644 --- a/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java +++ b/src/test/java/org/logicng/io/parsers/PseudoBooleanParserTest.java @@ -40,7 +40,7 @@ /** * Unit Tests for the class {@link PseudoBooleanParser}. - * @version 2.0.0 + * @version 4.4.1 * @since 1.0 */ public class PseudoBooleanParserTest extends TestWithExampleFormulas { @@ -69,6 +69,13 @@ public void testParseLiterals() throws ParserException { assertThat(parser.parse("~A")).isEqualTo(this.f.literal("A", false)); assertThat(parser.parse("~a")).isEqualTo(this.f.literal("a", false)); assertThat(parser.parse("~aA_Bb_Cc_12_3")).isEqualTo(this.f.literal("aA_Bb_Cc_12_3", false)); + assertThat(parser.parse("#")).isEqualTo(this.f.literal("#", true)); + assertThat(parser.parse("~#")).isEqualTo(this.f.literal("#", false)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("A#B")).isEqualTo(this.f.literal("A#B", true)); + assertThat(parser.parse("~A#B")).isEqualTo(this.f.literal("A#B", false)); + assertThat(parser.parse("#A#B_")).isEqualTo(this.f.literal("#A#B_", true)); + assertThat(parser.parse("~#A#B_")).isEqualTo(this.f.literal("#A#B_", false)); } @Test