|
| 1 | +package dotty.tools |
| 2 | +package dotc |
| 3 | +package transform |
| 4 | +package patmat |
| 5 | + |
| 6 | +import core.*, Annotations.*, Contexts.*, Decorators.*, Flags.*, Names.*, StdNames.*, Symbols.*, Types.* |
| 7 | +import ast.*, tpd.* |
| 8 | + |
| 9 | +import vulpix.TestConfiguration, TestConfiguration.basicClasspath |
| 10 | + |
| 11 | +import org.junit, junit.Test, junit.Assert.* |
| 12 | + |
| 13 | +class SpaceEngineTest: |
| 14 | + @Test def isSubspaceTest1: Unit = inCompilerContext(basicClasspath) { |
| 15 | + // Testing the property of `isSubspace` that: |
| 16 | + // isSubspace(a, b) <=> simplify(simplify(a) - simplify(a)) == Empty |
| 17 | + // Previously there were no simplify calls, |
| 18 | + // and this is a counter-example, |
| 19 | + // for which you need either to simplify(b) or simplify the minus result. |
| 20 | + val engine = patmat.SpaceEngine() |
| 21 | + import engine.* |
| 22 | + |
| 23 | + val tp = defn.ConsClass.typeRef.appliedTo(defn.AnyType) |
| 24 | + val unappTp = requiredMethod("scala.collection.immutable.::.unapply").termRef |
| 25 | + val params = List(Empty, Typ(tp)) |
| 26 | + |
| 27 | + val a = Prod(tp, unappTp, params) |
| 28 | + val b = Empty |
| 29 | + |
| 30 | + val res1 = isSubspace(a, b) |
| 31 | + |
| 32 | + val a2 = simplify(a) |
| 33 | + val b2 = simplify(b) |
| 34 | + val rem1 = minus(a2, b2) |
| 35 | + val rem2 = simplify(rem1) |
| 36 | + val res2 = rem2 == Empty |
| 37 | + |
| 38 | + assertEquals( |
| 39 | + i"""|isSubspace: |
| 40 | + | |
| 41 | + |isSubspace(a, b) = $res1 |
| 42 | + | |
| 43 | + |Should be equivalent to: |
| 44 | + |simplify(simplify(a) - simplify(b)) == Empty |
| 45 | + |simplify(a2 - b2) == Empty |
| 46 | + |simplify(rem1) == Empty |
| 47 | + |rem2 == Empty |
| 48 | + | |
| 49 | + |a = ${show(a)} |
| 50 | + |b = ${show(b)} |
| 51 | + |a2 = ${show(a2)} |
| 52 | + |b2 = ${show(b2)} |
| 53 | + |rem1 = ${show(rem1)} |
| 54 | + |rem2 = ${show(rem2)} |
| 55 | + | |
| 56 | + |a = ${a.toString} |
| 57 | + |b = ${b.toString} |
| 58 | + |a2 = ${a2.toString} |
| 59 | + |b2 = ${b2.toString} |
| 60 | + |rem1 = ${rem1.toString} |
| 61 | + |rem2 = ${rem2.toString} |
| 62 | + | |
| 63 | + |""".stripMargin, res1, res2) |
| 64 | + } |
0 commit comments