@@ -5,7 +5,7 @@ import SparseArrays
5
5
6
6
module Fruit
7
7
8
- struct Apple end
8
+ struct RedApple end
9
9
10
10
end
11
11
@@ -17,11 +17,19 @@ import .Fruit
17
17
@testset " typename" begin
18
18
@test StatisticalTraits. typename (Nothing) == :Nothing
19
19
@test StatisticalTraits. typename (UnionAll) == :UnionAll
20
- @test StatisticalTraits. typename (Union{Char,Int}) == Symbol (" Union{Char, Int64}" )
20
+ @test StatisticalTraits. typename (Union{Char,Int}) ==
21
+ Symbol (" Union{Char, Int64}" )
21
22
T = SparseArrays. sparse ([1 ,2 ], [1 ,3 ], [0.5 , 0.6 ]) |> typeof
22
23
@test StatisticalTraits. typename (T) == :SparseMatrixCSC
23
24
end
24
25
26
+ @testset " snakecase" begin
27
+ @test StatisticalTraits. snakecase (" AnthonyBlaomsPetElk" ) ==
28
+ " anthony_blaoms_pet_elk"
29
+ @test StatisticalTraits. snakecase (" TheLASERBeam" , delim= ' ' ) ==
30
+ " the laser beam"
31
+ end
32
+
25
33
26
34
# # TRAITS WITH NON-CONSTANT FALL-BACK
27
35
32
40
33
41
@testset " docstring" begin
34
42
@test docstring (Foo (1 ,' x' )) == " Foo"
35
- @test docstring (Fruit. Apple ()) == " Main.Fruit.Apple "
43
+ @test docstring (Fruit. RedApple ()) == " Main.Fruit.RedApple "
36
44
end
37
45
38
46
@testset " hyperparameter_ranges" begin
39
47
@test hyperparameter_ranges (Foo (1 , ' x' )) == (nothing , nothing )
40
- @test hyperparameter_ranges (Fruit. Apple ()) == ()
48
+ @test hyperparameter_ranges (Fruit. RedApple ()) == ()
41
49
end
42
50
43
51
@testset " name" begin
44
52
@test name (Float64) == " Float64"
45
- @test name (Fruit. Apple) == " Apple"
46
- @test name (Fruit. Apple ()) == " Apple"
53
+ @test name (Fruit. RedApple) == " RedApple"
54
+ @test name (Fruit. RedApple ()) == " RedApple"
55
+ end
56
+
57
+ @testset " human_name" begin
58
+ @test human_name (AbstractString) == " abstract string"
59
+ @test human_name (Fruit. RedApple) == " red apple"
60
+ @test human_name (Fruit. RedApple ()) == " red apple"
47
61
end
48
62
49
63
@testset " hyperparameters" begin
50
64
@test hyperparameters (Foo (1 , ' x' )) == (:x , :y )
51
- @test hyperparameters (Fruit. Apple ()) == ()
65
+ @test hyperparameters (Fruit. RedApple ()) == ()
52
66
end
53
67
54
68
@testset " hyperparameter_types" begin
55
69
@test hyperparameter_types (Foo (1 , ' x' )) == (" Int64" , " Char" )
56
- @test hyperparameter_types (Fruit. Apple ()) == ()
70
+ @test hyperparameter_types (Fruit. RedApple ()) == ()
57
71
end
58
72
59
73
62
76
const NONCONSTANT = [:docstring ,
63
77
:hyperparameter_ranges ,
64
78
:name ,
79
+ :human_name ,
65
80
:hyperparameters ,
66
81
:hyperparameter_types ]
67
82
68
83
@testset " traits with constant fall-back" begin
69
84
for trait in setdiff (StatisticalTraits. TRAITS, NONCONSTANT)
70
85
ex = quote
71
- @test $ trait (Fruit. Apple ()) == $ trait (Foo (1 , ' x' ))
86
+ @test $ trait (Fruit. RedApple ()) == $ trait (Foo (1 , ' x' ))
72
87
end
73
88
Main. eval (ex)
74
89
end
0 commit comments