source: trunk/ab5.0/ablib/TestCase/SimpleTestCase/Generics.ab

Last change on this file was 656, checked in by イグトランス (egtra), 15 years ago

文字列比較のテストを3引数版UnitTestの呼出に変更

File size: 1.0 KB
Line 
1Namespace GenericsTest
2
3Class Foo<T>
4Public
5 Function GetTypeName( t As T ) As String
6 Return t.GetType().Name
7 End Function
8End Class
9Class Bar<T>
10 Inherits Foo<String>
11End Class
12
13Sub TestMain()
14 ' クラス型の型パラメータ
15 Dim a = New System.Collections.Generic.List<String>
16 a.Add( "test" )
17 a.Add( "123" )
18 UnitTest( "Generic ... type parameter is class", a[0] = "test" and a[1] = "123" )
19
20 ' 値型の型パラメータ
21 Dim b = New System.Collections.Generic.List<Byte>
22 b.Add( 123 )
23 b.Add( 234 )
24 UnitTest( "Generic ... type parameter is value(byte)", b[0] = 123 and b[1] = 234 )
25 Dim c = New System.Collections.Generic.List<Double>
26 c.Add( 123.456 )
27 c.Add( 456.789 )
28 UnitTest( "Generic ... type parameter is value(double)", c[0] = 123.456 and c[1] = 456.789 )
29
30 ' 型パラメータがクロスした場合
31 ' TODO: より多くのパターンで試す必要あり
32 Dim bar = New Bar<Long>
33 UnitTest( "Generic ... complex", bar.GetTypeName( New String() ), "String" )
34End Sub
35
36End Namespace
37
38GenericsTest.TestMain()
Note: See TracBrowser for help on using the repository browser.