|
1 | 1 | /** immutable hashmaps (as of 2.13 collections) only store up to 4 entries in insertion order */
|
2 | 2 | enum LatinAlphabet { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }
|
3 | 3 |
|
| 4 | +enum LatinAlphabet2 extends java.lang.Enum[LatinAlphabet2] { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } |
| 5 | + |
| 6 | +enum LatinAlphabet3[+T] extends java.lang.Enum[LatinAlphabet3[_]] { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } |
| 7 | + |
4 | 8 | @main def Test =
|
5 |
| - import LatinAlphabet._ |
6 |
| - val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) |
7 | 9 |
|
8 |
| - assert(ordered sameElements LatinAlphabet.values) |
| 10 | + val ordinals = Seq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) |
| 11 | + val labels = Seq("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z") |
| 12 | + |
| 13 | + def testLatin1() = |
| 14 | + import LatinAlphabet._ |
| 15 | + val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) |
| 16 | + |
| 17 | + assert(ordered sameElements LatinAlphabet.values) |
| 18 | + assert(ordinals == ordered.map(_.ordinal)) |
| 19 | + assert(labels == ordered.map(_.productPrefix)) |
| 20 | + |
| 21 | + def testLatin2() = |
| 22 | + import LatinAlphabet2._ |
| 23 | + val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) |
| 24 | + |
| 25 | + assert(ordered sameElements LatinAlphabet2.values) |
| 26 | + assert(ordinals == ordered.map(_.ordinal)) |
| 27 | + assert(labels == ordered.map(_.name)) |
| 28 | + |
| 29 | + def testLatin3() = |
| 30 | + import LatinAlphabet3._ |
| 31 | + val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) |
| 32 | + |
| 33 | + // assert(ordered sameElements LatinAlphabet3.values) // TODO: enable when .values exists on parameterized enums |
| 34 | + assert(ordinals == ordered.map(_.ordinal)) |
| 35 | + assert(labels == ordered.map(_.name)) |
| 36 | + |
| 37 | + testLatin1() |
0 commit comments