Skip to content

Commit 036683d

Browse files
author
Antoine Brunner
committed
Add some tests to all current tuple operations
1 parent 20f7f39 commit 036683d

File tree

7 files changed

+93
-11
lines changed

7 files changed

+93
-11
lines changed

tests/run/tuple-tests.check

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@
77
(1,2,3,4,5,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35)
88
(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,1,2,3,4,5)
99
(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60)
10+
(head)
11+
(head,1,2,3,4,5)
12+
(head,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35)
13+
(head,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57)
14+
()
15+
(2,3,4,5)
16+
(12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35)
17+
(37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58)
18+
()
19+
(2,3,4,5,6)
20+
(21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45)
21+
()
22+
()
23+
()
24+
()
25+
()
26+
((1,6),(2,7),(3,8),(4,9),(5,10))
27+
((1,11),(2,12),(3,13),(4,14),(5,15))
28+
((11,1),(12,2),(13,3),(14,4),(15,5))
29+
((11,36),(12,37),(13,38),(14,39),(15,40),(16,41),(17,42),(18,43),(19,44),(20,45),(21,46),(22,47),(23,48),(24,49),(25,50),(26,51),(27,52),(28,53),(29,54),(30,55),(31,56),(32,57),(33,58),(34,59),(35,60))

tests/run/tuple-tests/tuple-concat.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11

2-
object Test extends App {
2+
def concat(): Unit = {
33
val emptyTuple: Tuple = ()
44
val tuple1: Tuple = ("1", "2", "3", "4", "5")
55
val tuple2: Tuple = ("6", "7", "8", "9", "10")
66
val tupleXXL1: Tuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")
77
val tupleXXL2: Tuple = ("36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60")
88

9-
// Try all possible kinds of concatenations (small === <=22):
10-
// empty + empty
11-
// small + empty
12-
// empty + small
13-
// xxl + empty
14-
// empty + xxl
15-
// small + small
16-
// small + xxl
17-
// xxl + small
18-
// xxl + xxl
9+
// All possible combinations of concatenating two tuples
1910
println(emptyTuple ++ emptyTuple)
2011
println(emptyTuple ++ tuple1)
2112
println(tuple1 ++ emptyTuple)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
def cons(): Unit = {
3+
val emptyTuple: Tuple = ()
4+
val tuple: Tuple = ("1", "2", "3", "4", "5")
5+
val tupleXXL: Tuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")
6+
val tuple22: Tuple = ("36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57")
7+
8+
// Test all possible combinations of making
9+
println("head" *: emptyTuple)
10+
println("head" *: tuple)
11+
println("head" *: tupleXXL)
12+
println("head" *: tuple22)
13+
}

tests/run/tuple-tests/tuple-map.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def map(): Unit = {
3+
val emptyTuple: Tuple = ()
4+
val tuple: Tuple = ("1", "2", "3", "4", "5")
5+
val tupleXXL: Tuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")
6+
7+
type Id[X] = X
8+
val f: [t] => t => Id[t] = [t] => (x: t) => {
9+
val str = x.asInstanceOf[String]
10+
str.updated(0, (str(0) + 1).toChar).asInstanceOf[t]
11+
}
12+
13+
// Test all possible combinations of making
14+
println(emptyTuple.map(f))
15+
println(tuple.map(f))
16+
println(tupleXXL.map(f))
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
def tail(): Unit = {
3+
val singletonTuple: NonEmptyTuple = Tuple1("59")
4+
val tuple: NonEmptyTuple = ("1", "2", "3", "4", "5")
5+
val tupleXXL: NonEmptyTuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")
6+
val tuple23: NonEmptyTuple = ("36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58")
7+
8+
// Test all possible combinations of making
9+
println(singletonTuple.tail)
10+
println(tuple.tail)
11+
println(tupleXXL.tail)
12+
println(tuple23.tail)
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
object Test extends App {
3+
concat()
4+
cons()
5+
tail()
6+
map()
7+
zip()
8+
}

tests/run/tuple-tests/tuple-zip.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
def zip(): Unit = {
3+
val emptyTuple: Tuple = ()
4+
val tuple1: Tuple = ("1", "2", "3", "4", "5")
5+
val tuple2: Tuple = ("6", "7", "8", "9", "10")
6+
val tupleXXL1: Tuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")
7+
val tupleXXL2: Tuple = ("36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60")
8+
9+
// All possible combinations of zipping two tuples
10+
println(emptyTuple zip emptyTuple)
11+
println(emptyTuple zip tuple1)
12+
println(tuple1 zip emptyTuple)
13+
println(tupleXXL1 zip emptyTuple)
14+
println(emptyTuple zip tupleXXL1)
15+
println(tuple1 zip tuple2)
16+
println(tuple1 zip tupleXXL1)
17+
println(tupleXXL1 zip tuple1)
18+
println(tupleXXL1 zip tupleXXL2)
19+
}
20+

0 commit comments

Comments
 (0)