From e447e1cd46f5332d6c001783290a27a38f61ef6b Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Sun, 15 Nov 2015 14:39:08 +0100 Subject: [PATCH] adapt + tests --- src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java | 5 ++++- test/unify/RuleSetTest.java | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java index 6b450672c..be456354b 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java @@ -319,6 +319,9 @@ public class RuleSet implements IRuleSet{ if(lhsType.getTypeParams().size() == 0 || rhsType.getTypeParams().size() == 0) return Optional.empty(); + if(lhsType.getName().equals(rhsType.getName())) + return Optional.empty(); + Type lhsFromFc = finiteClosure.getType(lhsType.getName()); if(lhsFromFc == null) @@ -337,7 +340,7 @@ public class RuleSet implements IRuleSet{ TypeParams lhsFromFcTypeParams = lhsFromFc.getTypeParams(); Unifier unif = new Unifier(lhsFromFcTypeParams.get(0), lhsTypeParams.get(0)); - for(int i = 0; i < lhsTypeParams.size(); i++) + for(int i = 1; i < lhsTypeParams.size(); i++) unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i))); return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOT)); diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index 729e2ea54..fd8dcba2e 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -538,8 +538,15 @@ public class RuleSetTest { MPair pair2 = new MPair(c1, c3, PairOperator.SMALLERDOT); System.out.println("------ Adapt ------"); System.out.println(rules.adapt(pair1)); - System.out.println(rules.adapt(pair2)); // Not working yet + System.out.println(rules.adapt(pair2)); + MPair noAdapt1 = new MPair(c2, c1, PairOperator.SMALLERDOT); + MPair noAdapt2 = new MPair(c1, c1, PairOperator.SMALLERDOT); + MPair noAdapt3 = new MPair(c1, c2, PairOperator.SMALLERDOTWC); + + Assert.assertFalse(rules.adapt(noAdapt1).isPresent()); + Assert.assertFalse(rules.adapt(noAdapt2).isPresent()); + Assert.assertFalse(rules.adapt(noAdapt3).isPresent()); } @Test