Skip to content

Commit c164dc7

Browse files
committed
Some tests
1 parent 2def876 commit c164dc7

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-0
lines changed

tests/neg/empty-given.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
given {
2+
def foo = 1 // error
3+
}

tests/pending/neg/i7445.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Main {
2+
type O1[A] = {
3+
type OutInner[X] = Unit
4+
type Out = OutInner[A]
5+
}
6+
7+
def f1: O1[Int]#Out = ???
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Test {
2+
def rawr(string: String): String = string
3+
}
4+
5+
implicit final class RawrExt(val t: Test) {
6+
def rawr(int: Int): Int = int
7+
}
8+
9+
val t = new Test
10+
11+
val r0 = t.rawr(5)
12+
13+
14+
class TestP {
15+
def rawr[A](list: List[A]): List[A] = list
16+
}
17+
18+
implicit final class RawrExtP(val t: TestP) {
19+
def rawr(int: Int): Int = int
20+
}
21+
22+
val tt = new TestP
23+
24+
val r1 = tt.rawr(5) // This doesn't compile

tests/pos/infer1.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
trait TestInferrence[T] {
2+
3+
def getInt(t: T): Int
4+
5+
}
6+
7+
object TestIntInferrence extends TestInferrence[Int] {
8+
override def getInt(i: Int) = i
9+
}
10+
11+
object InferrenceTest {
12+
13+
def createNumberHandler[T](
14+
testInfer: TestInferrence[T] = TestIntInferrence,
15+
handlers: Map[String, T => Unit] = Map.empty,
16+
): T => Unit = {
17+
18+
(t: T) => {
19+
testInfer.getInt(t)
20+
()
21+
}
22+
23+
}
24+
}
25+
26+
class InferrenceTest {
27+
28+
val handler = InferrenceTest.createNumberHandler()
29+
30+
}

tests/run/Pouring.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Vector(Empty(0), Empty(1), Fill(0), Fill(1), Pour(0,1), Pour(1,0))
2+
Fill(1) Pour(1,0) Empty(0) Pour(1,0) Fill(1) Pour(1,0) --> Vector(4, 6)

tests/run/Pouring.scala

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class Pouring(capacity: Vector[Int]) with
2+
type Glass = Int
3+
type Content = Vector[Int]
4+
5+
enum Move with
6+
def apply(content: Content): Content = this match
7+
case Empty(g) => content.updated(g, 0)
8+
case Fill(g) => content.updated(g, capacity(g))
9+
case Pour(from, to) =>
10+
val amount = content(from) min (capacity(to) - content(to))
11+
def (s: Content) adjust (g: Glass, delta: Int) = s.updated(g, s(g) + delta)
12+
content.adjust(from, -amount).adjust(to, amount)
13+
14+
case Empty(glass: Glass)
15+
case Fill(glass: Glass)
16+
case Pour(from: Glass, to: Glass)
17+
end Move
18+
19+
val moves =
20+
val glasses = 0 until capacity.length
21+
(for g <- glasses yield Move.Empty(g))
22+
++ (for g <- glasses yield Move.Fill(g))
23+
++ (for g1 <- glasses; g2 <- glasses if g1 != g2 yield Move.Pour(g1, g2))
24+
25+
class Path(history: List[Move], val endContent: Content) with
26+
def extend(move: Move) = Path(move :: history, move(endContent))
27+
override def toString = s"${history.reverse.mkString(" ")} --> $endContent"
28+
end Path
29+
30+
val initialContent: Content = capacity.map(x => 0)
31+
val initialPath = Path(Nil, initialContent)
32+
33+
def from(paths: Set[Path], explored: Set[Content]): LazyList[Set[Path]] =
34+
if paths.isEmpty then LazyList.empty
35+
else
36+
val extensions =
37+
for
38+
path <- paths
39+
move <- moves
40+
next = path.extend(move)
41+
if !explored.contains(next.endContent)
42+
yield next
43+
paths #:: from(extensions, explored ++ extensions.map(_.endContent))
44+
45+
def solutions(target: Int): LazyList[Path] =
46+
for
47+
paths <- from(Set(initialPath), Set(initialContent))
48+
path <- paths
49+
if path.endContent.contains(target)
50+
yield path
51+
end Pouring
52+
53+
@main def Test =
54+
val problem = Pouring(Vector(4, 7))
55+
println(problem.moves)
56+
println(problem.solutions(6).head)

0 commit comments

Comments
 (0)