Add some tests that make the compiler panick.
This commit is contained in:
parent
95986fed83
commit
04c05f8d63
|
@ -0,0 +1,2 @@
|
|||
name = "test_a"
|
||||
version = "0.0.0"
|
|
@ -0,0 +1,14 @@
|
|||
pub fn length(xs: List(a)) -> Int {
|
||||
when xs is {
|
||||
[] -> 0
|
||||
[_, ..rest] -> 1 + length(rest)
|
||||
}
|
||||
}
|
||||
|
||||
test length_1() {
|
||||
length([1, 2, 3]) == 3
|
||||
}
|
||||
|
||||
test length_2() {
|
||||
length([]) == 0
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
name = "test_b"
|
||||
version = "0.0.0"
|
|
@ -0,0 +1,11 @@
|
|||
pub fn repeat(x: a, n: Int) -> List(a) {
|
||||
if n <= 0 {
|
||||
[]
|
||||
} else {
|
||||
[x, ..repeat(x, n - 1)]
|
||||
}
|
||||
}
|
||||
|
||||
test repeat_1() {
|
||||
repeat("aiken", 0) == []
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
name = "test_c"
|
||||
version = "0.0.0"
|
|
@ -0,0 +1,14 @@
|
|||
pub fn foldr(xs: List(a), f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] -> zero
|
||||
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn concat(left: List(a), right: List(a)) -> List(a) {
|
||||
foldr(left, fn(x, xs) { [x, ..xs] }, right)
|
||||
}
|
||||
|
||||
test concat_1() {
|
||||
concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
}
|
Loading…
Reference in New Issue