Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
fc3ff0d
gradle: Introduce submodules
lorenzleutgeb Oct 27, 2020
ab5d5bf
core: Move ANTLR sources
lorenzleutgeb Oct 27, 2020
f93ab16
cli: Move resources
lorenzleutgeb Oct 27, 2020
89dcda4
git: Ignore */build
lorenzleutgeb Oct 27, 2020
1dfa72a
WIP: Extract interfaces
lorenzleutgeb Oct 27, 2020
2ae8d14
intermediate commit
madmike200590 Dec 4, 2020
725f45e
WIP: separate inheritance hierarchies for core- and api-types
madmike200590 Dec 14, 2020
af4d78c
WIP: let core components only depend on core API (not dependent on pu…
madmike200590 Dec 18, 2020
2a45628
adapt module names, add module alpha-solver
madmike200590 Dec 19, 2020
60c1bcf
adapt package names in alpha-core
madmike200590 Dec 19, 2020
fdf165f
WIP: decouple core/public API
madmike200590 Dec 19, 2020
0fbd63e
WIP: design published API
madmike200590 Jan 4, 2021
5e38c33
WIP: make parser conform to public API
madmike200590 Jan 22, 2021
a91b282
WIP: ParseTreeVisitor and Alpha conforming to new public API
madmike200590 Jan 23, 2021
e75f694
globally use interface types for API constructs
madmike200590 Jan 29, 2021
848ad7c
extract all interfaces, make it compile
madmike200590 Jan 29, 2021
131a5c8
fix build errors
madmike200590 Jan 29, 2021
84f537c
WIP: fix tests
madmike200590 Jan 29, 2021
61b1bb3
WIP: fix tests
madmike200590 Jan 29, 2021
ba43d48
WIP: adapt unit tests to modularized setup
madmike200590 Feb 5, 2021
f250c24
modularize and fix compilation errors in unit tests
madmike200590 Feb 8, 2021
f5e165a
tests for core module fixed
madmike200590 Feb 12, 2021
4c333fb
fix unit tests in all modules
madmike200590 Feb 12, 2021
6c60b89
WIP: deploy jar files to local maven cache
madmike200590 Feb 16, 2021
6ef295e
ignore junit log
madmike200590 Feb 16, 2021
3000fde
new module alpha-commons
madmike200590 Feb 17, 2021
9c57339
WIP: move terms to commons module
madmike200590 Feb 23, 2021
1b4f116
hide implementation details for VariableTerm, change implementation t…
madmike200590 Feb 23, 2021
7ac24aa
hide implementation details for FunctionTerm, change implementation t…
madmike200590 Feb 23, 2021
e3ca893
hide implementation details for ArithmeticTerm, change implementation…
madmike200590 Feb 23, 2021
82ad457
separate package for terms in alpha-commons
madmike200590 Feb 23, 2021
fe97209
fix checkstyle errors
madmike200590 Feb 23, 2021
171f6b3
WIP: move AggregateAtom to alpha-commons
madmike200590 Apr 1, 2021
95ddd72
hide implementation for AggregateAtom
madmike200590 Apr 3, 2021
833ffed
fix ChoiceAtom and RuleAtom
madmike200590 Apr 3, 2021
bf992f6
hide implementation for ComparisonAtom, fix EnumerationAtom
madmike200590 Apr 3, 2021
7632b97
Hide implementation for ExternalAtom
madmike200590 Apr 3, 2021
400732f
fix IntervalAtom
madmike200590 Apr 3, 2021
120bfca
moved literal implementations to commons module
madmike200590 Apr 3, 2021
347be4a
fix unit tests
madmike200590 Apr 3, 2021
f1c23d7
introduce interfaces NormalProgram and NormalRule
madmike200590 Apr 7, 2021
24e4a77
WIP: remove direct compile dependencies from alpha-cli-app to alpha-core
madmike200590 Apr 10, 2021
d7d3495
remove direct compile-time dependencies from alpha-cli-app to alpha-core
madmike200590 Apr 16, 2021
08419ba
WIP: refactor debug output workflow for CLI app
madmike200590 Apr 16, 2021
1ce5f0b
implement InternalProgram#toNormalProgram, add missing override annot…
madmike200590 Apr 23, 2021
ef14b0f
adapt CLI app to use single debug flag for preprocessing debug options
madmike200590 Apr 24, 2021
57dcad0
remove interfaces specific to internal grounder workings from public API
madmike200590 Apr 24, 2021
6f0605f
include runtime dependencies for application jar
madmike200590 Apr 24, 2021
82fbc6d
merge master into branch modules
madmike200590 Apr 24, 2021
c7b9b64
update appveyor config
madmike200590 Apr 24, 2021
6c41d24
clean up public API
madmike200590 Aug 26, 2021
788c0dc
clean up public API package structure
madmike200590 Aug 26, 2021
e7401ae
fix cehckstyle warnings
madmike200590 Aug 26, 2021
dd390a8
merge changes from master
madmike200590 Sep 8, 2021
432a04c
adapt antlr folder structure to new reflect module name
madmike200590 Sep 9, 2021
8b042c4
correct antlr path in build file
madmike200590 Sep 9, 2021
7211edb
fix packages to conform to antlr-generated folder structure
madmike200590 Sep 9, 2021
1ab79e4
create separate package for heads in api module
madmike200590 Sep 9, 2021
034621d
hide implementation details for rule heads
madmike200590 Sep 14, 2021
f6876f0
merge upstream changes from master
madmike200590 Sep 20, 2021
c746f2b
merge upstream changes from master
madmike200590 Sep 20, 2021
d918830
clean up test package structure
madmike200590 Sep 20, 2021
d8ff66d
delete obsolete files
madmike200590 Oct 6, 2021
467171c
WIP: refactor test structure
madmike200590 Oct 7, 2021
3447d10
merge changes from master into 'modules'
madmike200590 Oct 12, 2021
d633474
Merge branch 'modules' into modules-refactor-tests
madmike200590 Oct 12, 2021
9f303d6
WIP: reduce dependencies of unit tests
madmike200590 Oct 13, 2021
1fd8b43
remove parser dependency from ProgramTest
madmike200590 Oct 14, 2021
3db5e1d
remove obsolete junit4 dependency
madmike200590 Oct 14, 2021
2f7e06f
remove unneeded dependencies
madmike200590 Oct 14, 2021
b13060c
remove unneeded dependencies
madmike200590 Oct 14, 2021
e161e84
add global junit5 dependency, get rid of junit4 leftovers
madmike200590 Oct 14, 2021
1644b03
Merge branch 'modules' into modules-refactor-tests
madmike200590 Oct 14, 2021
b508f01
WIP: factories for rules
madmike200590 Oct 14, 2021
d69a9eb
reduce dependecies of unit tests
madmike200590 Oct 15, 2021
619adcd
repo: Ignore junit.log
lorenzleutgeb Oct 18, 2021
6c24d02
api: Remove TODO that mentions class from core
lorenzleutgeb Oct 18, 2021
a7c800e
repo: Move publishing configuration to convention
lorenzleutgeb Oct 18, 2021
c27f435
repo: Remove source JARs
lorenzleutgeb Oct 18, 2021
ab956a6
gradle: 7.0 -> 7.2
lorenzleutgeb Oct 18, 2021
4975f63
gradle: Migrate to KotlinScript
lorenzleutgeb Oct 18, 2021
8b5dde2
gradle: Fix compileClasspath to contain ANTLR
lorenzleutgeb Oct 18, 2021
b5e92dd
reduce unit test dependencies
madmike200590 Oct 20, 2021
8f82812
core: Remove Rete
lorenzleutgeb Oct 20, 2021
1f0359f
gradle: Use stringtemplateVersion
lorenzleutgeb Oct 20, 2021
a0e6fb1
gradle: Remove unnecessary `it`
lorenzleutgeb Oct 20, 2021
e45cbec
gradle: Fix use of mainClassName
lorenzleutgeb Oct 20, 2021
0b99898
WIP: reduce unit test dependencies
madmike200590 Oct 20, 2021
2ab14ec
gradle: Rename LICENSE/NOTICE in Kotlin
lorenzleutgeb Oct 21, 2021
14a7417
commons: Suppres warning about varargs
lorenzleutgeb Oct 21, 2021
9b7bef7
decouple NaiveGrounderTest from parser and system config
madmike200590 Oct 21, 2021
7b8e8cf
decouple NaiveGrounderTest from parser and system config
madmike200590 Oct 21, 2021
4e43015
api: Convert TODOs to issues
lorenzleutgeb Oct 21, 2021
7f09f38
reduce unit test dependencies
madmike200590 Oct 21, 2021
513e485
api: remove obsolete TODOs
madmike200590 Oct 21, 2021
b63eeb1
AbstractTerm: remove obsolete TODO
madmike200590 Oct 21, 2021
50a854b
commons: address TODOs, added to refactoring suggestions in #300
madmike200590 Oct 21, 2021
2ab3038
core: remove obsolete TODO
madmike200590 Oct 21, 2021
8702ecb
WIP: address TODOs
madmike200590 Oct 21, 2021
38cde69
RuleGroundingInfoTest: decouple from parser and program rewritings
madmike200590 Oct 21, 2021
54922dd
gradle: Clean up dependency declarations
lorenzleutgeb Oct 26, 2021
797a871
doc: Remove reference to Externals from Predicate annotation
lorenzleutgeb Oct 26, 2021
e4bb60c
WIP: decouple unit tests from parser
madmike200590 Nov 3, 2021
7fa9414
reduce unit test dependencies
madmike200590 Nov 5, 2021
122effc
update TODOs and clean up test util methods
madmike200590 Nov 5, 2021
4b3f61d
address TODOs on test cosmetics
madmike200590 Nov 5, 2021
5df9908
fix copy-paste error in TODO
madmike200590 Nov 5, 2021
0a7d5aa
Merge remote-tracking branch 'refs/remotes/origin/modules' into modules
madmike200590 Nov 5, 2021
8be4abc
WIP: api: javadoc
madmike200590 Nov 5, 2021
1a61d0b
api: javadoc for Alpha and related types
madmike200590 Nov 8, 2021
3c807ed
api: javadoc for configs
madmike200590 Nov 8, 2021
b3d0fe5
api: javadoc for public interfaces
madmike200590 Nov 8, 2021
e246463
api: javadocs for programs and graphs
madmike200590 Nov 9, 2021
f218181
api: javadoc for program building blocks
madmike200590 Nov 9, 2021
b1c51d7
remove deprecated method Alpha#getConfig
madmike200590 Nov 9, 2021
31e6cab
AnswerSetQuery: remove superfluous public modifiers
madmike200590 Nov 9, 2021
f10652f
merge branch modules
madmike200590 Nov 9, 2021
0808587
merge changes from 'master' into 'modules-refactor-tests'
madmike200590 Dec 11, 2021
1e4f136
Update alpha-solver/src/test/java/at/ac/tuwien/kr/alpha/api/impl/Rule…
madmike200590 Dec 16, 2021
3cea9cc
Update alpha-solver/src/test/java/at/ac/tuwien/kr/alpha/api/impl/Rule…
madmike200590 Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import at.ac.tuwien.kr.alpha.app.mappers.AnswerSetToWorkbookMapperTest;
import at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder;

// TODO this is an integration test
public class AnswerSetToXlsxWriterTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

// TODO this is an end-to-end test
public class MainTest {

private static final String INPUT = "p(a). " + System.lineSeparator() + " b :- p(X)." + System.lineSeparator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import at.ac.tuwien.kr.alpha.api.impl.AlphaImpl;
import at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph;

// TODO This is a functional test and should not be run with standard unit tests
public class ComponentGraphWriterTest {
private static final String LS = System.lineSeparator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import at.ac.tuwien.kr.alpha.api.impl.AlphaImpl;
import at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph;

// TODO This is a functional test and should not be run with standard unit tests
public class DependencyGraphWriterTest {
private static final String LS = System.lineSeparator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import at.ac.tuwien.kr.alpha.api.terms.Term;
import at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder;

// TODO This is a functional test and should not be run with standard unit tests
public class AnswerSetToWorkbookMapperTest {

private AnswerSetToWorkbookMapper mapper = new AnswerSetToWorkbookMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.externals;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.externals;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -44,13 +44,6 @@
import at.ac.tuwien.kr.alpha.commons.Predicates;
import at.ac.tuwien.kr.alpha.commons.atoms.Atoms;
import at.ac.tuwien.kr.alpha.commons.terms.Terms;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.BinaryPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.BindingMethodPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.IntPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.LongPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.SuppliedPredicateInterpretation;
import at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.UnaryPredicateInterpretation;

public final class Externals {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import org.apache.commons.lang3.ClassUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.terms.ConstantTerm;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package at.ac.tuwien.kr.alpha.commons.externals;

import java.util.List;
import java.util.Set;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.terms.ConstantTerm;
import at.ac.tuwien.kr.alpha.api.terms.Term;

// TODO this looks like a duplicate
public interface PredicateInterpretationImpl extends PredicateInterpretation {
@Override
Set<List<ConstantTerm<?>>> evaluate(List<Term> terms);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.BindingPredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.terms.ConstantTerm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.core.common.fixedinterpretations;
package at.ac.tuwien.kr.alpha.commons.externals;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package at.ac.tuwien.kr.alpha.commons.atoms;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import at.ac.tuwien.kr.alpha.api.programs.atoms.Atom;
import at.ac.tuwien.kr.alpha.commons.Predicates;
import at.ac.tuwien.kr.alpha.commons.terms.Terms;

/**
* Test for basic functionality of various implementations of {@link Atom}.
*
* Copyright (c) 2019-2021, the Alpha Team.
*/
public class BasicAtomImplTest {

@Test
public void testIsBasicAtomGround() {
BasicAtomImpl a = new BasicAtomImpl(Predicates.getPredicate("bla", 2), Terms.newSymbolicConstant("blubb"),
Terms.newFunctionTerm("foo", Terms.newSymbolicConstant("bar")));
assertTrue(a.isGround());
BasicAtomImpl a1 = new BasicAtomImpl(Predicates.getPredicate("foo", 4), Terms.newConstant(1), Terms.newConstant(2), Terms.newConstant(3),
Terms.newConstant("bar"));
assertTrue(a1.isGround());
BasicAtomImpl a2 = new BasicAtomImpl(Predicates.getPredicate("foo", 1), Terms.newVariable("BAR"));
assertFalse(a2.isGround());
BasicAtomImpl a3 = new BasicAtomImpl(Predicates.getPredicate("foo", 3), Terms.newSymbolicConstant("b"), Terms.newSymbolicConstant("a"),
Terms.newFunctionTerm("r", Terms.newConstant("bla"), Terms.newVariable("BLUBB")));
assertFalse(a3.isGround());
}

@Test
public void testAreBasicAtomsEqual() {
BasicAtomImpl a1 = new BasicAtomImpl(Predicates.getPredicate("bla", 2), Terms.newSymbolicConstant("blubb"),
Terms.newFunctionTerm("foo", Terms.newSymbolicConstant("bar")));
BasicAtomImpl a2 = new BasicAtomImpl(Predicates.getPredicate("bla", 2), Terms.newSymbolicConstant("blubb"),
Terms.newFunctionTerm("foo", Terms.newSymbolicConstant("bar")));
assertEquals(a1, a2);

BasicAtomImpl a3 = new BasicAtomImpl(Predicates.getPredicate("foo", 4), Terms.newConstant(1), Terms.newConstant(2), Terms.newConstant(3),
Terms.newConstant("bar"));
BasicAtomImpl a4 = new BasicAtomImpl(Predicates.getPredicate("foo", 4), Terms.newConstant(1), Terms.newConstant(2), Terms.newConstant(3),
Terms.newConstant("bar"));
assertEquals(a3, a4);

BasicAtomImpl a5 = new BasicAtomImpl(Predicates.getPredicate("foo", 1), Terms.newVariable("BAR"));
BasicAtomImpl a6 = new BasicAtomImpl(Predicates.getPredicate("foo", 1), Terms.newVariable("BAR"));
assertEquals(a5, a6);

BasicAtomImpl a7 = new BasicAtomImpl(Predicates.getPredicate("foo", 3), Terms.newSymbolicConstant("b"), Terms.newSymbolicConstant("a"),
Terms.newFunctionTerm("r", Terms.newConstant("bla"), Terms.newVariable("BLUBB")));
BasicAtomImpl a8 = new BasicAtomImpl(Predicates.getPredicate("foo", 3), Terms.newSymbolicConstant("b"), Terms.newSymbolicConstant("a"),
Terms.newFunctionTerm("r", Terms.newConstant("bla"), Terms.newVariable("BLUBB")));
assertEquals(a7, a8);

assertFalse(a1.equals(a3));
assertFalse(a3.equals(a1));
assertFalse(a1.equals(a5));
assertFalse(a5.equals(a1));
assertFalse(a1.equals(a7));
assertFalse(a7.equals(a1));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package at.ac.tuwien.kr.alpha.commons.atoms;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.Test;

import at.ac.tuwien.kr.alpha.api.common.fixedinterpretations.PredicateInterpretation;
import at.ac.tuwien.kr.alpha.api.externals.Predicate;
import at.ac.tuwien.kr.alpha.api.programs.atoms.ExternalAtom;
import at.ac.tuwien.kr.alpha.api.terms.ConstantTerm;
import at.ac.tuwien.kr.alpha.api.terms.Term;
import at.ac.tuwien.kr.alpha.commons.Predicates;
import at.ac.tuwien.kr.alpha.commons.externals.Externals;
import at.ac.tuwien.kr.alpha.commons.terms.Terms;

public class ExternalAtomImplTest {

private Map<String, PredicateInterpretation> externals;

public ExternalAtomImplTest() throws NoSuchMethodException, SecurityException {
externals = new HashMap<>();
externals.put("isFoo", Externals.processPredicateMethod(ExternalAtomImplTest.class.getMethod("isFoo", int.class)));
externals.put("extWithOutput", Externals.processPredicateMethod(ExternalAtomImplTest.class.getMethod("extWithOutput", int.class)));
}

@Predicate
public static final boolean isFoo(int bar) {
return 0xF00 == bar;
}

@Predicate
public static final Set<List<ConstantTerm<Integer>>> extWithOutput(int in) {
Set<List<ConstantTerm<Integer>>> retVal = new HashSet<>();
List<ConstantTerm<Integer>> lst = new ArrayList<>();
lst.add(Terms.newConstant(in));
retVal.add(lst);
return retVal;
}

@Test
public void testIsExternalAtomGround() {
List<Term> ext1Input = new ArrayList<>();
ext1Input.add(Terms.newConstant(1));
// ext1 := &isFoo[1]
ExternalAtom ext1 = Atoms.newExternalAtom(Predicates.getPredicate("isFoo", 1), externals.get("isFoo"), ext1Input, Collections.emptyList());
assertTrue(ext1.isGround());

// ext2 := &isFoo[bar(1)]
List<Term> ext2Input = new ArrayList<>();
ext2Input.add(Terms.newFunctionTerm("bar", Terms.newConstant(1)));
ExternalAtom ext2 = Atoms.newExternalAtom(Predicates.getPredicate("isFoo", 1), externals.get("isFoo"), ext2Input, Collections.emptyList());
assertTrue(ext2.isGround());

// ext3 := &isFoo[BLA]
List<Term> ext3Input = new ArrayList<>();
ext3Input.add(Terms.newVariable("BLA"));
ExternalAtom ext3 = Atoms.newExternalAtom(Predicates.getPredicate("isFoo", 1), externals.get("isFoo"), ext3Input, Collections.emptyList());
assertFalse(ext3.isGround());
}

@Test
@SuppressWarnings("unlikely-arg-type")
public void testAreExternalAtomsEqual() {
// ext1 := &isFoo[1]
List<Term> ext1Input = new ArrayList<>();
ext1Input.add(Terms.newConstant(1));
ExternalAtom ext1 = Atoms.newExternalAtom(Predicates.getPredicate("isFoo", 1), externals.get("isFoo"), ext1Input, Collections.emptyList());
// ext2 := &isFoo[1]
List<Term> ext2Input = new ArrayList<>();
ext2Input.add(Terms.newConstant(1));
ExternalAtom ext2 = Atoms.newExternalAtom(Predicates.getPredicate("isFoo", 1), externals.get("isFoo"), ext2Input, Collections.emptyList());

assertEquals(ext1, ext2);
assertEquals(ext2, ext1);

assertFalse(ext1.equals(null));
assertFalse(ext1.equals("bla"));
assertTrue(ext1.hashCode() == ext2.hashCode());
}

@Test
public void testExternalHasOutput() {
// ext := &extWithOutput[1](OUT)
List<Term> input = new ArrayList<>();
List<Term> output = new ArrayList<>();
input.add(Terms.newConstant(1));
output.add(Terms.newVariable("OUT"));
ExternalAtom ext = Atoms.newExternalAtom(Predicates.getPredicate("extWithOutput", 2), externals.get("extWithOutput"), input, output);

assertFalse(ext.isGround());
assertTrue(ext.hasOutput());
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.ac.tuwien.kr.alpha.core.externals;
package at.ac.tuwien.kr.alpha.commons.externals;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Loading