Compare commits

..

No commits in common. "3081d67e0fb83fc38025d98c02f96d7257580a62" and "0f808a371bd8a71baa3a84ad15b2e99ceefb83b7" have entirely different histories.

3 changed files with 0 additions and 93 deletions

View file

@ -1,30 +0,0 @@
package ch.nuth.zhaw.exbox;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
public class WellformedXmlServer implements CommandExecutor {
Pattern tagPattern = Pattern.compile("<(/?)(\\w+)( \\w+=\"[^\"]*\")*>");
@Override
public String execute(String command) throws Exception {
return Boolean.toString(checkWellformed(command)) + "\n";
}
public boolean checkWellformed(String code) {
ListStack openTags = new ListStack();
Iterable<MatchResult> results = () -> tagPattern.matcher(code).results().iterator();
for (MatchResult result : results) {
if (result.group(1).length() == 0) {
openTags.push(result.group(2));
} else if (result.group(2).equals(openTags.peek())) {
openTags.pop();
} else {
return false;
}
}
return openTags.isEmpty();
}
}

View file

@ -1,29 +0,0 @@
package ch.nuth.zhaw.exbox;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ADS1_3_test {
BracketServer bs;
@BeforeEach
public void setUp() {
bs = new BracketServer();
}
private void test(String content, boolean expected) {
assertEquals(expected, bs.checkBrackets(content), content);
}
@Test
public void testBracket() {
test("()", true);
test("(()]", false);
test("((([([])])))", true);
test("[(])", false);
test("[(3 +3)* 35 +3]* {3 +2}", true);
test("[({3 +3)* 35} +3]* {3 +2}", false);
}
}

View file

@ -1,34 +0,0 @@
package ch.nuth.zhaw.exbox;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ADS1_4_test {
WellformedXmlServer xml;
@BeforeEach
public void setUp() {
xml = new WellformedXmlServer();
}
private void test(String content, boolean expected) {
assertEquals(expected, xml.checkWellformed(content), content);
}
@Test
public void testXmlAttributes() {
test("<a href=\"sugus\"></a>", true);
}
@Test
public void testXml() {
test("<a></a>", true);
test("<a>", false);
test("</a>", false);
test("<a/>", true);
test("<a><b></b></a>", true);
test("<a><b></a></b>", false);
}
}