changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT)
-> intersectionTests funktionieren
This commit is contained in:
parent
4422270452
commit
f0207de511
8 changed files with 132 additions and 39 deletions
|
|
@ -206,15 +206,11 @@ public class NFAImpl implements NFA {
|
|||
if (!this.isFinalized || !other.isFinalized()) {
|
||||
throw new FinalizedStateException();
|
||||
}
|
||||
NFAImpl intersectionNFA = new NFAImpl(this.initialState);
|
||||
|
||||
intersectionNFA.states.addAll(this.states);
|
||||
intersectionNFA.states.retainAll(other.getStates());
|
||||
|
||||
intersectionNFA.transitions.addAll(this.transitions);
|
||||
intersectionNFA.transitions.retainAll(other.getTransitions());
|
||||
|
||||
return intersectionNFA;
|
||||
NFA newNFA_A = this.complement();
|
||||
NFA newNFA_B = other.complement();
|
||||
NFA unionNFA = newNFA_A.union(newNFA_B);
|
||||
NFA result = unionNFA.complement();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -345,7 +341,7 @@ public class NFAImpl implements NFA {
|
|||
nfa.addAllTransitions(this.transitions);
|
||||
nfa.addAllAcceptingStates(this.acceptingStates);
|
||||
|
||||
nfaAddTrap(nfa);
|
||||
nfaAddTrap(nfa); //error on last occasion
|
||||
|
||||
NFAImpl fakeNFA = convertNFAtoDFA(nfa);
|
||||
|
||||
|
|
@ -524,9 +520,11 @@ public class NFAImpl implements NFA {
|
|||
for(char letter : completeAlphabet){
|
||||
boolean hasTransition = false;
|
||||
for(Transition transition : input.getTransitions()){
|
||||
if(transition.fromState().equals(state)&&transition.readSymbol().equals(letter)){
|
||||
hasTransition = true;
|
||||
break;
|
||||
if(transition.fromState().equals(state)/*&&transition.readSymbol().equals(letter)*/){
|
||||
if(transition.readSymbol()!= null&&transition.readSymbol()==letter) {
|
||||
hasTransition = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!hasTransition){
|
||||
|
|
|
|||
63
src/test/java/ab1/tests/myTests.java
Normal file
63
src/test/java/ab1/tests/myTests.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package ab1.tests;
|
||||
|
||||
import ab1.NFA;
|
||||
import ab1.NFAFactory;
|
||||
import ab1.NFAProvider;
|
||||
import ab1.Transition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class myTests {
|
||||
private final NFAFactory factory = NFAProvider.provideFactory();
|
||||
|
||||
@Test
|
||||
public void intersection1Test() {
|
||||
var nfaA = buildCharLanguage('a');
|
||||
var nfaB = buildCharLanguage('b');
|
||||
|
||||
var testInstance = nfaA.intersection(nfaB);
|
||||
|
||||
assertFalse(testInstance.acceptsWord("a"));
|
||||
assertFalse(testInstance.acceptsWord("b"));
|
||||
assertFalse(testInstance.acceptsWord("ab"));
|
||||
assertFalse(testInstance.acceptsWord("ba"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private NFA buildCharStarLanguage(char c) {
|
||||
var instance = factory.buildNFA("START");
|
||||
instance.addTransition(
|
||||
Transition.builder()
|
||||
.fromState("START")
|
||||
.readSymbol(c)
|
||||
.toState("START")
|
||||
.build()
|
||||
);
|
||||
instance.addAcceptingState("START");
|
||||
instance.finalizeAutomaton();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private NFA buildCharLanguage(char c) {
|
||||
var instance = factory.buildNFA("START");
|
||||
instance.addTransition(
|
||||
Transition.builder()
|
||||
.fromState("START")
|
||||
.readSymbol(c)
|
||||
.toState("ACCEPT")
|
||||
.build()
|
||||
);
|
||||
instance.addAcceptingState("ACCEPT");
|
||||
instance.finalizeAutomaton();
|
||||
|
||||
assertTrue(instance.acceptsWord(String.valueOf(c)));
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
Reference in a new issue