-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evolog Modules: Unit test for ModuleAtomImpl
- Loading branch information
1 parent
49233d9
commit 90d3faf
Showing
3 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ommons/src/test/java/at/ac/tuwien/kr/alpha/commons/programs/atoms/ModuleAtomImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package at.ac.tuwien.kr.alpha.commons.programs.atoms; | ||
|
||
import java.util.List; | ||
|
||
import at.ac.tuwien.kr.alpha.api.programs.atoms.ModuleAtom; | ||
import at.ac.tuwien.kr.alpha.commons.programs.terms.Terms; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ModuleAtomImplTest { | ||
|
||
@Test | ||
public void withTerms() { | ||
ModuleAtom moduleAtom = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.ALL); | ||
ModuleAtom newModuleAtom = moduleAtom.withTerms(List.of(Terms.newConstant(1), Terms.newConstant(2), Terms.newConstant(3))); | ||
// Check correct construction of original atom (also check that withTerms didn't modify the original atom) | ||
assertEquals(moduleAtom.getInput().size(), 2); | ||
assertEquals(moduleAtom.getOutput().size(), 1); | ||
assertEquals(moduleAtom.getModuleName(), "someModule"); | ||
assertEquals(moduleAtom.getInstantiationMode(), ModuleAtom.ModuleInstantiationMode.ALL); | ||
// Check terms of new atom | ||
assertEquals(newModuleAtom.getInput().size(), 2); | ||
assertEquals(newModuleAtom.getOutput().size(), 1); | ||
assertEquals(newModuleAtom.getModuleName(), "someModule"); | ||
assertEquals(newModuleAtom.getInstantiationMode(), ModuleAtom.ModuleInstantiationMode.ALL); | ||
assertEquals(List.of(Terms.newConstant(1), Terms.newConstant(2)), newModuleAtom.getInput()); | ||
assertEquals(List.of(Terms.newConstant(3)), newModuleAtom.getOutput()); | ||
} | ||
|
||
@Test | ||
public void withTermsNewTermsTooLong() { | ||
ModuleAtom moduleAtom = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.ALL); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> moduleAtom.withTerms( | ||
List.of(Terms.newConstant(1), Terms.newConstant(2), | ||
Terms.newConstant(3), Terms.newConstant(4)))); | ||
} | ||
|
||
@Test | ||
public void withTermsNewTermsTooShort() { | ||
ModuleAtom moduleAtom = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.ALL); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> moduleAtom.withTerms(List.of(Terms.newConstant(1)))); | ||
} | ||
|
||
@Test | ||
public void moduleAtomsEqual() { | ||
ModuleAtom m1 = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.ALL); | ||
ModuleAtom m2 = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.ALL); | ||
assertEquals(m1, m2); | ||
assertEquals(m1.hashCode(), m2.hashCode()); | ||
|
||
ModuleAtom m3 = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.forNumAnswerSets(3)); | ||
ModuleAtom m4 = new ModuleAtomImpl("someModule", | ||
List.of(Terms.newVariable("X"), Terms.newVariable("Y")), | ||
List.of(Terms.newVariable("Z")), ModuleAtom.ModuleInstantiationMode.forNumAnswerSets(3)); | ||
assertNotEquals(m1, m3); | ||
assertEquals(m3, m4); | ||
} | ||
|
||
} |