|
| 1 | +using Semgus.Model.Smt; |
| 2 | +using Semgus.Model.Smt.Theories; |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | + |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace Semgus.Parser.Tests |
| 13 | +{ |
| 14 | + public class SortResolutionTests |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// Test that a template sort will be recursively matched against a concrete sort, |
| 18 | + /// and that all the sub-pieces of the template will be resolved. |
| 19 | + /// </summary> |
| 20 | + [Fact] |
| 21 | + public void TemplatesRecursivelyResolved() |
| 22 | + { |
| 23 | + IDictionary<SmtSort, SmtSort> resolved = new Dictionary<SmtSort, SmtSort>(); |
| 24 | + |
| 25 | + var usf = new SmtSort.UniqueSortFactory(); |
| 26 | + var tix1 = usf.Next(); |
| 27 | + var val1 = usf.Next(); |
| 28 | + var tix2 = usf.Next(); |
| 29 | + |
| 30 | + var t2 = new SmtArraysExTheory.ArraySort(tix1, val1); |
| 31 | + var t1 = new SmtArraysExTheory.ArraySort(tix2, t2); |
| 32 | + |
| 33 | + |
| 34 | + var pix1 = new SmtSort.GenericSort(new("Proc1")); |
| 35 | + var pvl1 = new SmtSort.GenericSort(new("PVal1")); |
| 36 | + var pix2 = new SmtSort.GenericSort(new("Proc2")); |
| 37 | + var p2 = new SmtArraysExTheory.ArraySort(pix1, pvl1); |
| 38 | + var p1 = new SmtArraysExTheory.ArraySort(pix2, p2); |
| 39 | + |
| 40 | + Assert.True(SmtFunction.TraverseAndMatchTemplate(t1, p1, resolved)); |
| 41 | + |
| 42 | + Assert.Equal(5, resolved.Count); |
| 43 | + Assert.Equal(pix1, resolved[tix1]); |
| 44 | + Assert.Equal(pix2, resolved[tix2]); |
| 45 | + Assert.Equal(pvl1, resolved[val1]); |
| 46 | + Assert.Equal(p2, resolved[t2]); |
| 47 | + Assert.Equal(p1, resolved[t1]); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Tests that single parametric sorts will be matched against sorts with higher arity. |
| 52 | + /// E.g., a template X1 can match against (Array Int Int) fine |
| 53 | + /// </summary> |
| 54 | + [Fact] |
| 55 | + public void SingleTemplatesMatchedAgainstParametric() |
| 56 | + { |
| 57 | + IDictionary<SmtSort, SmtSort> resolved = new Dictionary<SmtSort, SmtSort>(); |
| 58 | + |
| 59 | + var usf = new SmtSort.UniqueSortFactory(); |
| 60 | + |
| 61 | + var top1 = usf.Next(); |
| 62 | + var subIx = usf.Next(); |
| 63 | + var subVal = usf.Next(); |
| 64 | + var top2 = new SmtArraysExTheory.ArraySort(subIx, subVal); |
| 65 | + |
| 66 | + var pix1 = new SmtSort.GenericSort(new("Proc1")); |
| 67 | + var pvl1 = new SmtSort.GenericSort(new("PVal1")); |
| 68 | + var pix2 = new SmtSort.GenericSort(new("Proc2")); |
| 69 | + var p2 = new SmtArraysExTheory.ArraySort(pix1, pvl1); |
| 70 | + var p1 = new SmtArraysExTheory.ArraySort(pix2, p2); |
| 71 | + |
| 72 | + Assert.True(SmtFunction.TraverseAndMatchTemplate(top1, p1, resolved)); |
| 73 | + Assert.True(SmtFunction.TraverseAndMatchTemplate(top2, p1, resolved)); |
| 74 | + |
| 75 | + Assert.Equal(4, resolved.Count); |
| 76 | + Assert.Equal(p1, resolved[top1]); |
| 77 | + Assert.Equal(p1, resolved[top2]); |
| 78 | + Assert.Equal(pix2, resolved[subIx]); |
| 79 | + Assert.Equal(p2, resolved[subVal]); |
| 80 | + |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments