Skip to content

Some more tests #7500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions tests/neg/empty-given.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
given {
def foo = 1 // error
}
8 changes: 8 additions & 0 deletions tests/pending/neg/i7445.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Main {
type O1[A] = {
type OutInner[X] = Unit
type Out = OutInner[A]
}

def f1: O1[Int]#Out = ???
}
24 changes: 24 additions & 0 deletions tests/pending/pos/overload-generic.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Test {
def rawr(string: String): String = string
}

implicit final class RawrExt(val t: Test) {
def rawr(int: Int): Int = int
}

val t = new Test

val r0 = t.rawr(5)


class TestP {
def rawr[A](list: List[A]): List[A] = list
}

implicit final class RawrExtP(val t: TestP) {
def rawr(int: Int): Int = int
}

val tt = new TestP

val r1 = tt.rawr(5) // This doesn't compile
30 changes: 30 additions & 0 deletions tests/pos/infer1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
trait TestInferrence[T] {

def getInt(t: T): Int

}

object TestIntInferrence extends TestInferrence[Int] {
override def getInt(i: Int) = i
}

object InferrenceTest {

def createNumberHandler[T](
testInfer: TestInferrence[T] = TestIntInferrence,
handlers: Map[String, T => Unit] = Map.empty,
): T => Unit = {

(t: T) => {
testInfer.getInt(t)
()
}

}
}

class InferrenceTest {

val handler = InferrenceTest.createNumberHandler()

}
2 changes: 2 additions & 0 deletions tests/run/Pouring.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Vector(Empty(0), Empty(1), Fill(0), Fill(1), Pour(0,1), Pour(1,0))
Fill(1) Pour(1,0) Empty(0) Pour(1,0) Fill(1) Pour(1,0) --> Vector(4, 6)
56 changes: 56 additions & 0 deletions tests/run/Pouring.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Pouring(capacity: Vector[Int]) with
type Glass = Int
type Content = Vector[Int]

enum Move with
def apply(content: Content): Content = this match
case Empty(g) => content.updated(g, 0)
case Fill(g) => content.updated(g, capacity(g))
case Pour(from, to) =>
val amount = content(from) min (capacity(to) - content(to))
def (s: Content) adjust (g: Glass, delta: Int) = s.updated(g, s(g) + delta)
content.adjust(from, -amount).adjust(to, amount)

case Empty(glass: Glass)
case Fill(glass: Glass)
case Pour(from: Glass, to: Glass)
end Move

val moves =
val glasses = 0 until capacity.length
(for g <- glasses yield Move.Empty(g))
++ (for g <- glasses yield Move.Fill(g))
++ (for g1 <- glasses; g2 <- glasses if g1 != g2 yield Move.Pour(g1, g2))

class Path(history: List[Move], val endContent: Content) with
def extend(move: Move) = Path(move :: history, move(endContent))
override def toString = s"${history.reverse.mkString(" ")} --> $endContent"
end Path

val initialContent: Content = capacity.map(x => 0)
val initialPath = Path(Nil, initialContent)

def from(paths: Set[Path], explored: Set[Content]): LazyList[Set[Path]] =
if paths.isEmpty then LazyList.empty
else
val extensions =
for
path <- paths
move <- moves
next = path.extend(move)
if !explored.contains(next.endContent)
yield next
paths #:: from(extensions, explored ++ extensions.map(_.endContent))

def solutions(target: Int): LazyList[Path] =
for
paths <- from(Set(initialPath), Set(initialContent))
path <- paths
if path.endContent.contains(target)
yield path
end Pouring

@main def Test =
val problem = Pouring(Vector(4, 7))
println(problem.moves)
println(problem.solutions(6).head)