@@ -5,35 +5,76 @@ enum LatinAlphabet2 extends java.lang.Enum[LatinAlphabet2] { case A, B, C, D, E,
55
66enum 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 }
77
8+ object Color :
9+ trait Pretty
10+ enum Color extends java.lang.Enum [Color ]:
11+ case Red , Green , Blue
12+ case Aqua extends Color with Color .Pretty
13+ case Grey , Black , White
14+ case Emerald extends Color with Color .Pretty
15+ case Brown
16+
817@ main def Test =
918
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" )
1219
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 )
20+ def testLatin () =
1621
17- assert(ordered sameElements LatinAlphabet .values)
18- assert(ordinals == ordered.map(_.ordinal))
19- assert(labels == ordered.map(_.productPrefix))
22+ 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 )
23+ 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" )
2024
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 )
25+ def testLatin1 () =
26+ import LatinAlphabet ._
27+ 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 )
2428
25- assert(ordered sameElements LatinAlphabet2 .values)
26- assert(ordinals == ordered.map(_.ordinal))
27- assert(labels == ordered.map(_.name))
29+ assert(ordered sameElements LatinAlphabet .values)
30+ assert(ordinals == ordered.map(_.ordinal))
31+ assert(labels == ordered.map(_.productPrefix))
32+
33+ def testLatin2 () =
34+ import LatinAlphabet2 ._
35+ 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 )
36+
37+ assert(ordered sameElements LatinAlphabet2 .values)
38+ assert(ordinals == ordered.map(_.ordinal))
39+ assert(labels == ordered.map(_.name))
40+
41+ def testLatin3 () =
42+ import LatinAlphabet3 ._
43+ 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 )
2844
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 )
45+ assert(ordered sameElements LatinAlphabet3 .values)
46+ assert(ordinals == ordered.map(_.ordinal))
47+ assert(labels == ordered.map(_.name) )
3248
33- assert(ordered sameElements LatinAlphabet3 .values)
49+ testLatin1()
50+ testLatin2()
51+ testLatin3()
52+
53+ end testLatin
54+
55+ def testColor () =
56+ import Color ._
57+ val ordered = Seq (Red , Green , Blue , Aqua , Grey , Black , White , Emerald , Brown )
58+ val ordinals = Seq (0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 )
59+ val labels = Seq (" Red" , " Green" , " Blue" , " Aqua" , " Grey" , " Black" , " White" , " Emerald" , " Brown" )
60+
61+ assert(ordered sameElements Color .values)
3462 assert(ordinals == ordered.map(_.ordinal))
3563 assert(labels == ordered.map(_.name))
3664
37- testLatin1()
38- testLatin2()
39- testLatin3()
65+ def isPretty (c : Color ): Boolean = c match
66+ case _ : Pretty => true
67+ case _ => false
68+
69+ assert(! isPretty(Brown ))
70+ assert(! isPretty(Grey ))
71+ assert(isPretty(Aqua ))
72+ assert(isPretty(Emerald ))
73+ assert(Emerald .getClass != Aqua .getClass)
74+ assert(Aqua .getClass != Grey .getClass)
75+ assert(Grey .getClass == Brown .getClass)
76+
77+ end testColor
78+
79+ testLatin()
80+ testColor()
0 commit comments